Skip to content

Commit

Permalink
x86/mm: Implement native set_memory_rox()
Browse files Browse the repository at this point in the history
Provide a native implementation of set_memory_rox(), avoiding the
double set_memory_ro();set_memory_x(); calls.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
  • Loading branch information
Peter Zijlstra authored and Dave Hansen committed Dec 15, 2022
1 parent d48567c commit 6046362
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arch/x86/include/asm/set_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <asm/page.h>
#include <asm-generic/set_memory.h>

#define set_memory_rox set_memory_rox
int set_memory_rox(unsigned long addr, int numpages);

/*
* The set_memory_* API can be used to change various attributes of a virtual
* address range. The attributes include:
Expand Down
10 changes: 10 additions & 0 deletions arch/x86/mm/pat/set_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,16 @@ int set_memory_ro(unsigned long addr, int numpages)
return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW), 0);
}

int set_memory_rox(unsigned long addr, int numpages)
{
pgprot_t clr = __pgprot(_PAGE_RW);

if (__supported_pte_mask & _PAGE_NX)
clr.pgprot |= _PAGE_NX;

return change_page_attr_clear(&addr, numpages, clr, 0);
}

int set_memory_rw(unsigned long addr, int numpages)
{
return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_RW), 0);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/set_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }
static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
#endif

#ifndef set_memory_rox
static inline int set_memory_rox(unsigned long addr, int numpages)
{
int ret = set_memory_ro(addr, numpages);
if (ret)
return ret;
return set_memory_x(addr, numpages);
}
#endif

#ifndef CONFIG_ARCH_HAS_SET_DIRECT_MAP
static inline int set_direct_map_invalid_noflush(struct page *page)
Expand Down

0 comments on commit 6046362

Please sign in to comment.