Skip to content

Commit 1e03304

Browse files
committed
mm: vmalloc: group declarations depending on CONFIG_MMU together
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 beeb922 Patch series "x86/module: use large ROX pages for text allocations", v7. These patches add support for using large ROX pages for allocations of executable memory on x86. They address Andy's comments [1] about having executable mappings for code that was not completely formed. The approach taken is to allocate ROX memory along with writable but not executable memory and use the writable copy to perform relocations and alternatives patching. After the module text gets into its final shape, the contents of the writable memory is copied into the actual ROX location using text poking. The allocations of the ROX memory use vmalloc(VMAP_ALLOW_HUGE_MAP) to allocate PMD aligned memory, fill that memory with invalid instructions and in the end remap it as ROX. Portions of these large pages are handed out to execmem_alloc() callers without any changes to the permissions. When the memory is freed with execmem_free() it is invalidated again so that it won't contain stale instructions. The module memory allocation, x86 code dealing with relocations and alternatives patching take into account the existence of the two copies, the writable memory and the ROX memory at the actual allocated virtual address. [1] https://lore.kernel.org/all/a17c65c6-863f-4026-9c6f-a04b659e9ab4@app.fastmail.com This patch (of 8): There are a couple of declarations that depend on CONFIG_MMU in include/linux/vmalloc.h spread all over the file. Group them all together to improve code readability. No functional changes. Link: https://lkml.kernel.org/r/20241023162711.2579610-1-rppt@kernel.org Link: https://lkml.kernel.org/r/20241023162711.2579610-2-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com> 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: Vineet Gupta <vgupta@kernel.org> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit beeb922) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 0cf7bd6 commit 1e03304

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

include/linux/vmalloc.h

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ extern void vm_unmap_ram(const void *mem, unsigned int count);
134134
extern void *vm_map_ram(struct page **pages, unsigned int count, int node);
135135
extern void vm_unmap_aliases(void);
136136

137-
#ifdef CONFIG_MMU
138-
extern unsigned long vmalloc_nr_pages(void);
139-
#else
140-
static inline unsigned long vmalloc_nr_pages(void) { return 0; }
141-
#endif
142-
143137
extern void *vmalloc_noprof(unsigned long size) __alloc_size(1);
144138
#define vmalloc(...) alloc_hooks(vmalloc_noprof(__VA_ARGS__))
145139

@@ -266,37 +260,44 @@ static inline bool is_vm_area_hugepages(const void *addr)
266260
#endif
267261
}
268262

263+
/* for /proc/kcore */
264+
long vread_iter(struct iov_iter *iter, const char *addr, size_t count);
265+
266+
/*
267+
* Internals. Don't use..
268+
*/
269+
__init void vm_area_add_early(struct vm_struct *vm);
270+
__init void vm_area_register_early(struct vm_struct *vm, size_t align);
271+
272+
int register_vmap_purge_notifier(struct notifier_block *nb);
273+
int unregister_vmap_purge_notifier(struct notifier_block *nb);
274+
269275
#ifdef CONFIG_MMU
276+
#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
277+
278+
unsigned long vmalloc_nr_pages(void);
279+
270280
int vm_area_map_pages(struct vm_struct *area, unsigned long start,
271281
unsigned long end, struct page **pages);
272282
void vm_area_unmap_pages(struct vm_struct *area, unsigned long start,
273283
unsigned long end);
274284
void vunmap_range(unsigned long addr, unsigned long end);
285+
275286
static inline void set_vm_flush_reset_perms(void *addr)
276287
{
277288
struct vm_struct *vm = find_vm_area(addr);
278289

279290
if (vm)
280291
vm->flags |= VM_FLUSH_RESET_PERMS;
281292
}
293+
#else /* !CONFIG_MMU */
294+
#define VMALLOC_TOTAL 0UL
282295

283-
#else
284-
static inline void set_vm_flush_reset_perms(void *addr)
285-
{
286-
}
287-
#endif
288-
289-
/* for /proc/kcore */
290-
extern long vread_iter(struct iov_iter *iter, const char *addr, size_t count);
291-
292-
/*
293-
* Internals. Don't use..
294-
*/
295-
extern __init void vm_area_add_early(struct vm_struct *vm);
296-
extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
296+
static inline unsigned long vmalloc_nr_pages(void) { return 0; }
297+
static inline void set_vm_flush_reset_perms(void *addr) {}
298+
#endif /* CONFIG_MMU */
297299

298-
#ifdef CONFIG_SMP
299-
# ifdef CONFIG_MMU
300+
#if defined(CONFIG_MMU) && defined(CONFIG_SMP)
300301
struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
301302
const size_t *sizes, int nr_vms,
302303
size_t align);
@@ -311,22 +312,9 @@ pcpu_get_vm_areas(const unsigned long *offsets,
311312
return NULL;
312313
}
313314

314-
static inline void
315-
pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
316-
{
317-
}
318-
# endif
319-
#endif
320-
321-
#ifdef CONFIG_MMU
322-
#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
323-
#else
324-
#define VMALLOC_TOTAL 0UL
315+
static inline void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) {}
325316
#endif
326317

327-
int register_vmap_purge_notifier(struct notifier_block *nb);
328-
int unregister_vmap_purge_notifier(struct notifier_block *nb);
329-
330318
#if defined(CONFIG_MMU) && defined(CONFIG_PRINTK)
331319
bool vmalloc_dump_obj(void *object);
332320
#else

0 commit comments

Comments
 (0)