Skip to content

Commit d253ca0

Browse files
rpedgecoIngo Molnar
authored and
Ingo Molnar
committed
x86/mm/cpa: Add set_direct_map_*() functions
Add two new functions set_direct_map_default_noflush() and set_direct_map_invalid_noflush() for setting the direct map alias for the page to its default valid permissions and to an invalid state that cannot be cached in a TLB, respectively. These functions do not flush the TLB. Note, __kernel_map_pages() does something similar but flushes the TLB and doesn't reset the permission bits to default on all architectures. Also add an ARCH config ARCH_HAS_SET_DIRECT_MAP for specifying whether these have an actual implementation or a default empty one. Signed-off-by: Rick Edgecombe <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Nadav Amit <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0a203df commit d253ca0

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

arch/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ config ARCH_HAS_FORTIFY_SOURCE
249249
config ARCH_HAS_SET_MEMORY
250250
bool
251251

252+
# Select if arch has all set_direct_map_invalid/default() functions
253+
config ARCH_HAS_SET_DIRECT_MAP
254+
bool
255+
252256
# Select if arch init_task must go in the __init_task_data section
253257
config ARCH_TASK_STRUCT_ON_STACK
254258
bool

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ config X86
6565
select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
6666
select ARCH_HAS_UACCESS_MCSAFE if X86_64 && X86_MCE
6767
select ARCH_HAS_SET_MEMORY
68+
select ARCH_HAS_SET_DIRECT_MAP
6869
select ARCH_HAS_STRICT_KERNEL_RWX
6970
select ARCH_HAS_STRICT_MODULE_RWX
7071
select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE

arch/x86/include/asm/set_memory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ int set_pages_nx(struct page *page, int numpages);
8585
int set_pages_ro(struct page *page, int numpages);
8686
int set_pages_rw(struct page *page, int numpages);
8787

88+
int set_direct_map_invalid_noflush(struct page *page);
89+
int set_direct_map_default_noflush(struct page *page);
90+
8891
extern int kernel_set_to_readonly;
8992
void set_kernel_text_rw(void);
9093
void set_kernel_text_ro(void);

arch/x86/mm/pageattr.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,8 +2209,6 @@ int set_pages_rw(struct page *page, int numpages)
22092209
return set_memory_rw(addr, numpages);
22102210
}
22112211

2212-
#ifdef CONFIG_DEBUG_PAGEALLOC
2213-
22142212
static int __set_pages_p(struct page *page, int numpages)
22152213
{
22162214
unsigned long tempaddr = (unsigned long) page_address(page);
@@ -2249,6 +2247,17 @@ static int __set_pages_np(struct page *page, int numpages)
22492247
return __change_page_attr_set_clr(&cpa, 0);
22502248
}
22512249

2250+
int set_direct_map_invalid_noflush(struct page *page)
2251+
{
2252+
return __set_pages_np(page, 1);
2253+
}
2254+
2255+
int set_direct_map_default_noflush(struct page *page)
2256+
{
2257+
return __set_pages_p(page, 1);
2258+
}
2259+
2260+
#ifdef CONFIG_DEBUG_PAGEALLOC
22522261
void __kernel_map_pages(struct page *page, int numpages, int enable)
22532262
{
22542263
if (PageHighMem(page))
@@ -2282,7 +2291,6 @@ void __kernel_map_pages(struct page *page, int numpages, int enable)
22822291
}
22832292

22842293
#ifdef CONFIG_HIBERNATION
2285-
22862294
bool kernel_page_present(struct page *page)
22872295
{
22882296
unsigned int level;

include/linux/set_memory.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; }
1717
static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; }
1818
#endif
1919

20+
#ifndef CONFIG_ARCH_HAS_SET_DIRECT_MAP
21+
static inline int set_direct_map_invalid_noflush(struct page *page)
22+
{
23+
return 0;
24+
}
25+
static inline int set_direct_map_default_noflush(struct page *page)
26+
{
27+
return 0;
28+
}
29+
#endif
30+
2031
#ifndef set_mce_nospec
2132
static inline int set_mce_nospec(unsigned long pfn)
2233
{

0 commit comments

Comments
 (0)