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) <rppt@kernel.org> 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/20241023162711.2579610-6-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Tested-by: kdevops <kdevops@lists.linux.dev> Cc: Andreas Larsson <andreas@gaisler.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov (AMD) <bp@alien8.de> Cc: Brian Cain <bcain@quicinc.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dinh Nguyen <dinguyen@kernel.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Guo Ren <guoren@kernel.org> Cc: Helge Deller <deller@gmx.de> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Liam R. Howlett <Liam.Howlett@Oracle.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: Matt Turner <mattst88@gmail.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Richard Weinberger <richard@nod.at> Cc: Russell King <linux@armlinux.org.uk> Cc: Song Liu <song@kernel.org> Cc: Stafford Horne <shorne@gmail.com> Cc: Steven Rostedt (Google) <rostedt@goodmis.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 0c6378a) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
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)