Skip to content

Commit 5a9e6da

Browse files
committed
arch: introduce set_direct_map_valid_noflush()
jira LE-4694 Rebuild_History Non-Buildable kernel-6.12.0-55.43.1.el10_0 commit-author Mike Rapoport (Microsoft) <[email protected]> commit 0c6378a Add an API that will allow updates of the direct/linear map for a set of physically contiguous pages. It will be used in the following patches. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Tested-by: kdevops <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Petkov (AMD) <[email protected]> Cc: Brian Cain <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Guo Ren <[email protected]> Cc: Helge Deller <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Johannes Berg <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu (Google) <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russell King <[email protected]> Cc: Song Liu <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Uladzislau Rezki (Sony) <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit 0c6378a) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 0f01fb3 commit 5a9e6da

File tree

11 files changed

+74
-0
lines changed

11 files changed

+74
-0
lines changed

arch/arm64/include/asm/set_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ int set_memory_valid(unsigned long addr, int numpages, int enable);
1313

1414
int set_direct_map_invalid_noflush(struct page *page);
1515
int set_direct_map_default_noflush(struct page *page);
16+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid);
1617
bool kernel_page_present(struct page *page);
1718

1819
#endif /* _ASM_ARM64_SET_MEMORY_H */

arch/arm64/mm/pageattr.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ int set_direct_map_default_noflush(struct page *page)
192192
PAGE_SIZE, change_page_range, &data);
193193
}
194194

195+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid)
196+
{
197+
unsigned long addr = (unsigned long)page_address(page);
198+
199+
if (!can_set_direct_map())
200+
return 0;
201+
202+
return set_memory_valid(addr, nr, valid);
203+
}
204+
195205
#ifdef CONFIG_DEBUG_PAGEALLOC
196206
void __kernel_map_pages(struct page *page, int numpages, int enable)
197207
{

arch/loongarch/include/asm/set_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ int set_memory_rw(unsigned long addr, int numpages);
1717
bool kernel_page_present(struct page *page);
1818
int set_direct_map_default_noflush(struct page *page);
1919
int set_direct_map_invalid_noflush(struct page *page);
20+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid);
2021

2122
#endif /* _ASM_LOONGARCH_SET_MEMORY_H */

arch/loongarch/mm/pageattr.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,22 @@ int set_direct_map_invalid_noflush(struct page *page)
216216

217217
return __set_memory(addr, 1, __pgprot(0), __pgprot(_PAGE_PRESENT | _PAGE_VALID));
218218
}
219+
220+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid)
221+
{
222+
unsigned long addr = (unsigned long)page_address(page);
223+
pgprot_t set, clear;
224+
225+
if (addr < vm_map_base)
226+
return 0;
227+
228+
if (valid) {
229+
set = PAGE_KERNEL;
230+
clear = __pgprot(0);
231+
} else {
232+
set = __pgprot(0);
233+
clear = __pgprot(_PAGE_PRESENT | _PAGE_VALID);
234+
}
235+
236+
return __set_memory(addr, 1, set, clear);
237+
}

arch/riscv/include/asm/set_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static inline int set_kernel_memory(char *startp, char *endp,
4242

4343
int set_direct_map_invalid_noflush(struct page *page);
4444
int set_direct_map_default_noflush(struct page *page);
45+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid);
4546
bool kernel_page_present(struct page *page);
4647

4748
#endif /* __ASSEMBLY__ */

arch/riscv/mm/pageattr.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,21 @@ int set_direct_map_default_noflush(struct page *page)
386386
PAGE_KERNEL, __pgprot(_PAGE_EXEC));
387387
}
388388

389+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid)
390+
{
391+
pgprot_t set, clear;
392+
393+
if (valid) {
394+
set = PAGE_KERNEL;
395+
clear = __pgprot(_PAGE_EXEC);
396+
} else {
397+
set = __pgprot(0);
398+
clear = __pgprot(_PAGE_PRESENT);
399+
}
400+
401+
return __set_memory((unsigned long)page_address(page), nr, set, clear);
402+
}
403+
389404
#ifdef CONFIG_DEBUG_PAGEALLOC
390405
static int debug_pagealloc_set_page(pte_t *pte, unsigned long addr, void *data)
391406
{

arch/s390/include/asm/set_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ __SET_MEMORY_FUNC(set_memory_4k, SET_MEMORY_4K)
6262

6363
int set_direct_map_invalid_noflush(struct page *page);
6464
int set_direct_map_default_noflush(struct page *page);
65+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid);
6566

6667
#endif

arch/s390/mm/pageattr.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ int set_direct_map_default_noflush(struct page *page)
406406
return __set_memory((unsigned long)page_to_virt(page), 1, SET_MEMORY_DEF);
407407
}
408408

409+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid)
410+
{
411+
unsigned long flags;
412+
413+
if (valid)
414+
flags = SET_MEMORY_DEF;
415+
else
416+
flags = SET_MEMORY_INV;
417+
418+
return __set_memory((unsigned long)page_to_virt(page), nr, flags);
419+
}
409420
#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE)
410421

411422
static void ipte_range(pte_t *pte, unsigned long address, int nr)

arch/x86/include/asm/set_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int set_pages_rw(struct page *page, int numpages);
8989

9090
int set_direct_map_invalid_noflush(struct page *page);
9191
int set_direct_map_default_noflush(struct page *page);
92+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid);
9293
bool kernel_page_present(struct page *page);
9394

9495
extern int kernel_set_to_readonly;

arch/x86/mm/pat/set_memory.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,14 @@ int set_direct_map_default_noflush(struct page *page)
24442444
return __set_pages_p(page, 1);
24452445
}
24462446

2447+
int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid)
2448+
{
2449+
if (valid)
2450+
return __set_pages_p(page, nr);
2451+
2452+
return __set_pages_np(page, nr);
2453+
}
2454+
24472455
#ifdef CONFIG_DEBUG_PAGEALLOC
24482456
void __kernel_map_pages(struct page *page, int numpages, int enable)
24492457
{

0 commit comments

Comments
 (0)