mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h
@ 2026-09-11 14:40 Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 1/6] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-09-11 14:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Peter Huewe,
	Jarkko Sakkinen, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
	Sami Tolvanen
  Cc: Xin Li, H. Peter Anvin, Andy Lutomirski, Christian Borntraeger,
	Sven Schnelle, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Jason Gunthorpe, Aaron Tomlin, linux-s390,
	kvm, linux-integrity, linux-modules, linux-kernel

linux/module.h appears in roughly 15k #include directives across the
kernel. This makes it a "hot" header, so it should avoid pulling in
unnecessary definitions.

The header currently includes linux/elf.h but this is largely unnecessary
because it requires only the base ELF structures, such as Elf_Ehdr and
Elf_Sym, which are declared in uapi/linux/elf.h.

Replace the linux/elf.h include with uapi/linux/elf.h. On x86_64_defconfig,
including linux/module.h alone results in 2.2 MB of preprocessed data. This
change reduces that to 1.5 MB.

The first five patches are cleanups to avoid relying on declarations being
indirectly provided through linux/module.h -> linux/elf.h. These patches
are mostly independent and can go through their respective trees if
preferred, except for the cpufeature patch, which depends on the preceding
s390 cleanup. The final module patch depends on all of these changes.

It is hard to identify all files that indirectly reference something only
through linux/module.h -> linux/elf.h. The changes were build-tested with
allmodconfig on arm, arm64, m68k, mips, powerpc64, riscv, s390, x86_64.

---
Changes in v2:
- Rebase on top of v7.3-rc2.
- Add the missing include of linux/slab.h in
  drivers/virt/coco/arm-cca-guest/arm-cca-guest.c.
- Remove the asm/mmu_context.h include from asm/elf.h on s390.
- Add the missing include of linux/elf.h in linux/cpufeature.h, reported by
  the kernel test robot.
- Clean up commit descriptions.
- Link to v1: https://patch.msgid.link/20260707153819.4172541-1-petr.pavlu@suse.com

---
Petr Pavlu (6):
      x86: Avoid indirect includes through linux/module.h -> linux/elf.h
      s390: Avoid indirect includes through linux/module.h -> linux/elf.h
      drivers: Include linux/slab.h for kmalloc() functions
      s390: Remove the asm/mmu_context.h include from asm/elf.h
      cpufeature: Include asm/elf.h for ELF_PLATFORM
      module: Limit ELF includes in linux/module.h to uapi/linux/elf.h

 arch/s390/include/asm/elf.h                     | 1 -
 arch/s390/kernel/nospec-branch.c                | 1 +
 arch/s390/kernel/processor.c                    | 1 +
 arch/s390/mm/mmap.c                             | 1 +
 arch/x86/entry/entry_fred.c                     | 1 +
 arch/x86/entry/syscall_32.c                     | 1 +
 arch/x86/kernel/cpu/intel.c                     | 1 +
 arch/x86/kernel/fpu/xstate.c                    | 2 +-
 arch/x86/kernel/process.c                       | 1 +
 arch/x86/kernel/signal.c                        | 1 +
 drivers/char/tpm/tpm_crb_ffa.c                  | 1 +
 drivers/s390/char/uvdevice.c                    | 2 ++
 drivers/virt/coco/arm-cca-guest/arm-cca-guest.c | 1 +
 include/linux/cpufeature.h                      | 1 +
 include/linux/module.h                          | 4 ++--
 15 files changed, 16 insertions(+), 4 deletions(-)
---
base-commit: df2908090cda368b01ff43709f51890076c56157
change-id: 20260816-module-include-elf-a9c10c041867

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/6] x86: Avoid indirect includes through linux/module.h -> linux/elf.h
  2026-09-11 14:40 [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
@ 2026-09-11 14:40 ` Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 2/6] s390: " Petr Pavlu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-09-11 14:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Peter Huewe,
	Jarkko Sakkinen, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
	Sami Tolvanen
  Cc: Xin Li, H. Peter Anvin, Andy Lutomirski, Christian Borntraeger,
	Sven Schnelle, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Jason Gunthorpe, Aaron Tomlin, linux-s390,
	kvm, linux-integrity, linux-modules, linux-kernel

Several x86 files use ELF-related declarations and currently rely on them
being provided indirectly through linux/module.h -> linux/elf.h:

* arch/x86/entry/entry_fred.c: ia32_enabled() -> asm/ia32.h,
* arch/x86/entry/syscall_32.c: vdso32_image -> asm/vdso.h,
* arch/x86/kernel/cpu/intel.c: ELF_HWCAP2 -> asm/elf.h,
* arch/x86/kernel/fpu/xstate.c: elf_coredump_extra_notes_write(),
  elf_coredump_extra_notes_size(), NT_X86_XSAVE_LAYOUT, elf_note ->
  linux/elf.h,
* arch/x86/kernel/process.c: mmap_is_ia32() -> asm/elf.h,
* arch/x86/kernel/signal.c: get_sigframe_size() -> asm/elf.h.

Add the missing includes to these files in preparation for removing the
linux/elf.h include from linux/module.h.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
---
 arch/x86/entry/entry_fred.c  | 1 +
 arch/x86/entry/syscall_32.c  | 1 +
 arch/x86/kernel/cpu/intel.c  | 1 +
 arch/x86/kernel/fpu/xstate.c | 2 +-
 arch/x86/kernel/process.c    | 1 +
 arch/x86/kernel/signal.c     | 1 +
 6 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c
index fb3594ddf731..ea3bb4298065 100644
--- a/arch/x86/entry/entry_fred.c
+++ b/arch/x86/entry/entry_fred.c
@@ -9,6 +9,7 @@
 
 #include <asm/desc.h>
 #include <asm/fred.h>
+#include <asm/ia32.h>
 #include <asm/idtentry.h>
 #include <asm/syscall.h>
 #include <asm/trapnr.h>
diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c
index 91123a90710c..4ace5b534f65 100644
--- a/arch/x86/entry/syscall_32.c
+++ b/arch/x86/entry/syscall_32.c
@@ -12,6 +12,7 @@
 #include <asm/traps.h>
 #include <asm/cpufeature.h>
 #include <asm/syscall.h>
+#include <asm/vdso.h>
 
 #ifdef CONFIG_IA32_EMULATION
 #define __SYSCALL_WITH_COMPAT(nr, native, compat)	__SYSCALL(nr, compat)
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 4297ceb2cb24..7dd5a039186e 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -17,6 +17,7 @@
 #include <asm/cpufeature.h>
 #include <asm/cpu.h>
 #include <asm/cpuid/api.h>
+#include <asm/elf.h>
 #include <asm/hwcap2.h>
 #include <asm/intel-family.h>
 #include <asm/microcode.h>
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index a7b6524a9dea..8b90bf86a742 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -7,6 +7,7 @@
 #include <linux/bitops.h>
 #include <linux/compat.h>
 #include <linux/cpu.h>
+#include <linux/elf.h>
 #include <linux/mman.h>
 #include <linux/kvm_types.h>
 #include <linux/nospec.h>
@@ -26,7 +27,6 @@
 #include <asm/msr.h>
 #include <asm/tlbflush.h>
 #include <asm/prctl.h>
-#include <asm/elf.h>
 
 #include <uapi/asm/elf.h>
 
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 346c438ac880..e7f736b53f41 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -54,6 +54,7 @@
 #include <asm/mmu_context.h>
 #include <asm/msr.h>
 #include <asm/shstk.h>
+#include <asm/elf.h>
 
 #include "process.h"
 
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 2404233336ab..0fe2d7a6b1af 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -29,6 +29,7 @@
 #include <linux/syscalls.h>
 #include <linux/rseq.h>
 
+#include <asm/elf.h>
 #include <asm/processor.h>
 #include <asm/ucontext.h>
 #include <asm/fpu/signal.h>

-- 
2.55.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/6] s390: Avoid indirect includes through linux/module.h -> linux/elf.h
  2026-09-11 14:40 [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 1/6] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
@ 2026-09-11 14:40 ` Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 3/6] drivers: Include linux/slab.h for kmalloc() functions Petr Pavlu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-09-11 14:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Peter Huewe,
	Jarkko Sakkinen, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
	Sami Tolvanen
  Cc: Xin Li, H. Peter Anvin, Andy Lutomirski, Christian Borntraeger,
	Sven Schnelle, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Jason Gunthorpe, Aaron Tomlin, linux-s390,
	kvm, linux-integrity, linux-modules, linux-kernel

Several s390 files use declarations that are provided indirectly through
linux/module.h -> linux/elf.h:

* arch/s390/kernel/nospec-branch.c: s390_kernel_write() -> linux/uaccess.h,
* drivers/s390/char/uvdevice.c: copy_to_user(), copy_from_user(),
  put_user(), get_user() -> linux/uaccess.h; file_operations -> linux/fs.h.

Add the missing includes to these files in preparation for removing the
linux/elf.h include from linux/module.h.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
---
 arch/s390/kernel/nospec-branch.c | 1 +
 drivers/s390/char/uvdevice.c     | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/arch/s390/kernel/nospec-branch.c b/arch/s390/kernel/nospec-branch.c
index e11ec15960a1..b62da9e81e79 100644
--- a/arch/s390/kernel/nospec-branch.c
+++ b/arch/s390/kernel/nospec-branch.c
@@ -2,6 +2,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/cpu.h>
+#include <linux/uaccess.h>
 #include <asm/nospec-branch.h>
 
 int nobp = IS_ENABLED(CONFIG_KERNEL_NOBP);
diff --git a/drivers/s390/char/uvdevice.c b/drivers/s390/char/uvdevice.c
index 4d274a2ee84d..402b8a225d6b 100644
--- a/drivers/s390/char/uvdevice.c
+++ b/drivers/s390/char/uvdevice.c
@@ -28,6 +28,8 @@
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
 #include <linux/cpufeature.h>
+#include <linux/fs.h>
+#include <linux/uaccess.h>
 
 #include <asm/uvdevice.h>
 #include <asm/uv.h>

-- 
2.55.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 3/6] drivers: Include linux/slab.h for kmalloc() functions
  2026-09-11 14:40 [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 1/6] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 2/6] s390: " Petr Pavlu
@ 2026-09-11 14:40 ` Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 4/6] s390: Remove the asm/mmu_context.h include from asm/elf.h Petr Pavlu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-09-11 14:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Peter Huewe,
	Jarkko Sakkinen, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
	Sami Tolvanen
  Cc: Xin Li, H. Peter Anvin, Andy Lutomirski, Christian Borntraeger,
	Sven Schnelle, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Jason Gunthorpe, Aaron Tomlin, linux-s390,
	kvm, linux-integrity, linux-modules, linux-kernel

drivers/char/tpm/tpm_crb_ffa.c and
drivers/virt/coco/arm-cca-guest/arm-cca-guest.c use kmalloc() functions,
which are declared in linux/slab.h. They currently rely on this header
being included indirectly through linux/module.h -> linux/elf.h.

Add the missing includes in preparation for removing the linux/elf.h
include from linux/module.h.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
---
 drivers/char/tpm/tpm_crb_ffa.c                  | 1 +
 drivers/virt/coco/arm-cca-guest/arm-cca-guest.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/char/tpm/tpm_crb_ffa.c b/drivers/char/tpm/tpm_crb_ffa.c
index 025c4d4b17ca..af4466cdc297 100644
--- a/drivers/char/tpm/tpm_crb_ffa.c
+++ b/drivers/char/tpm/tpm_crb_ffa.c
@@ -12,6 +12,7 @@
 #include <linux/arm_ffa.h>
 #include <linux/delay.h>
 #include <linux/moduleparam.h>
+#include <linux/slab.h>
 #include "tpm_crb_ffa.h"
 
 static unsigned int busy_timeout_ms = 2000;
diff --git a/drivers/virt/coco/arm-cca-guest/arm-cca-guest.c b/drivers/virt/coco/arm-cca-guest/arm-cca-guest.c
index 0eeddd1ff05b..54dcfc1681ab 100644
--- a/drivers/virt/coco/arm-cca-guest/arm-cca-guest.c
+++ b/drivers/virt/coco/arm-cca-guest/arm-cca-guest.c
@@ -8,6 +8,7 @@
 #include <linux/kernel.h>
 #include <linux/device-id/platform.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/smp.h>
 #include <linux/tsm.h>
 #include <linux/types.h>

-- 
2.55.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 4/6] s390: Remove the asm/mmu_context.h include from asm/elf.h
  2026-09-11 14:40 [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
                   ` (2 preceding siblings ...)
  2026-09-11 14:40 ` [PATCH v2 3/6] drivers: Include linux/slab.h for kmalloc() functions Petr Pavlu
@ 2026-09-11 14:40 ` Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 5/6] cpufeature: Include asm/elf.h for ELF_PLATFORM Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 6/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
  5 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-09-11 14:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Peter Huewe,
	Jarkko Sakkinen, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
	Sami Tolvanen
  Cc: Xin Li, H. Peter Anvin, Andy Lutomirski, Christian Borntraeger,
	Sven Schnelle, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Jason Gunthorpe, Aaron Tomlin, linux-s390,
	kvm, linux-integrity, linux-modules, linux-kernel

The asm/mmu_context.h include was added to asm/elf.h by commit 146e4b3c8b92
("[S390] 1K/2K page table pages.") in 2008, when the new macro
elf_read_implies_exec() used disable_noexec() /
current->mm->context.noexec. Commit 043d07084b53 ("[S390] Remove data
execution protection") removed that macro in 2011 and asm/elf.h no longer
needs asm/mmu_context.h.

Several s390 files currently depend on declarations provided indirectly
through asm/elf.h -> asm/mmu_context.h:

* arch/s390/mm/mmap.c: check_asce_limit() -> asm/pgalloc.h,
* arch/s390/kernel/processor.c: enter_lazy_tlb() -> asm/mmu_context.h.

Add the missing includes to these files and remove the asm/mmu_context.h
include from asm/elf.h.

This is a preparatory cleanup for adding the asm/elf.h include in
linux/cpufeature.h, which would otherwise create the following cycle:

linux/pgtable.h -> asm/pgtable.h -> linux/cpufeature.h -> asm/elf.h ->
asm/mmu_context.h -> asm/pgalloc.h -> linux/mm.h -> linux/pgtable.h

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
---
 arch/s390/include/asm/elf.h  | 1 -
 arch/s390/kernel/processor.c | 1 +
 arch/s390/mm/mmap.c          | 1 +
 3 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
index bb63fa4d20bb..e22e3ab25760 100644
--- a/arch/s390/include/asm/elf.h
+++ b/arch/s390/include/asm/elf.h
@@ -170,7 +170,6 @@ typedef s390_fp_regs elf_fpregset_t;
 typedef s390_regs elf_gregset_t;
 
 #include <linux/sched/mm.h>	/* for task_struct */
-#include <asm/mmu_context.h>
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
diff --git a/arch/s390/kernel/processor.c b/arch/s390/kernel/processor.c
index e33a3eccda56..76b2c7478c6e 100644
--- a/arch/s390/kernel/processor.c
+++ b/arch/s390/kernel/processor.c
@@ -27,6 +27,7 @@
 #include <asm/param.h>
 #include <asm/sclp.h>
 #include <asm/smp.h>
+#include <asm/mmu_context.h>
 
 unsigned long __read_mostly elf_hwcap;
 char elf_platform[ELF_PLATFORM_SIZE];
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index ef7bfc87758c..8206f347e00e 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -18,6 +18,7 @@
 #include <linux/security.h>
 #include <linux/hugetlb.h>
 #include <asm/elf.h>
+#include <asm/pgalloc.h>
 
 static unsigned long stack_maxrandom_size(void)
 {

-- 
2.55.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 5/6] cpufeature: Include asm/elf.h for ELF_PLATFORM
  2026-09-11 14:40 [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
                   ` (3 preceding siblings ...)
  2026-09-11 14:40 ` [PATCH v2 4/6] s390: Remove the asm/mmu_context.h include from asm/elf.h Petr Pavlu
@ 2026-09-11 14:40 ` Petr Pavlu
  2026-09-11 14:40 ` [PATCH v2 6/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
  5 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-09-11 14:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Peter Huewe,
	Jarkko Sakkinen, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
	Sami Tolvanen
  Cc: Xin Li, H. Peter Anvin, Andy Lutomirski, Christian Borntraeger,
	Sven Schnelle, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Jason Gunthorpe, Aaron Tomlin, linux-s390,
	kvm, linux-integrity, linux-modules, linux-kernel,
	kernel test robot

linux/cpufeature.h uses ELF_PLATFORM, which is defined in asm/elf.h. It
currently relies on that header being included indirectly through other
files, specifically, drivers/base/cpu.c gets it via linux/module.h ->
linux/elf.h.

Add the missing include in preparation for removing the linux/elf.h include
from linux/module.h.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202608151415.UAbFbpvE-lkp@intel.com/
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
---
 include/linux/cpufeature.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/cpufeature.h b/include/linux/cpufeature.h
index 6aff540ee9e5..66027987e9d6 100644
--- a/include/linux/cpufeature.h
+++ b/include/linux/cpufeature.h
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/mod_devicetable.h>
 #include <asm/cpufeature.h>
+#include <asm/elf.h>
 
 /*
  * Macros imported from <asm/cpufeature.h>:

-- 
2.55.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 6/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h
  2026-09-11 14:40 [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
                   ` (4 preceding siblings ...)
  2026-09-11 14:40 ` [PATCH v2 5/6] cpufeature: Include asm/elf.h for ELF_PLATFORM Petr Pavlu
@ 2026-09-11 14:40 ` Petr Pavlu
  5 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-09-11 14:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Peter Huewe,
	Jarkko Sakkinen, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
	Sami Tolvanen
  Cc: Xin Li, H. Peter Anvin, Andy Lutomirski, Christian Borntraeger,
	Sven Schnelle, Janosch Frank, Claudio Imbrenda,
	David Hildenbrand, Jason Gunthorpe, Aaron Tomlin, linux-s390,
	kvm, linux-integrity, linux-modules, linux-kernel

linux/module.h appears in roughly 15k #include directives across the
kernel. This makes it a "hot" header, so it should avoid pulling in
unnecessary definitions.

The header currently includes linux/elf.h but this is largely unnecessary
because it requires only the base ELF structures, such as Elf_Ehdr and
Elf_Sym, which are declared in uapi/linux/elf.h.

Replace the linux/elf.h include with uapi/linux/elf.h. On x86_64_defconfig,
including linux/module.h alone results in 2.2 MB of preprocessed data. This
change reduces that to 1.5 MB.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Reviewed-by: Aaron Tomlin <atomlin@atomlin.com>
---
 include/linux/module.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/module.h b/include/linux/module.h
index 96cc98568eea..1ec9e121a24b 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -17,7 +17,6 @@
 #include <linux/cleanup.h>
 #include <linux/kmod.h>
 #include <linux/init.h>
-#include <linux/elf.h>
 #include <linux/stringify.h>
 #include <linux/kobject.h>
 #include <linux/moduleparam.h>
@@ -29,8 +28,9 @@
 #include <linux/srcu.h>
 #include <linux/static_call_types.h>
 #include <linux/dynamic_debug.h>
-
 #include <linux/percpu.h>
+
+#include <uapi/linux/elf.h>
 #include <asm/module.h>
 
 #define MODULE_NAME_LEN __MODULE_NAME_LEN

-- 
2.55.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-11 14:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 14:40 [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
2026-09-11 14:40 ` [PATCH v2 1/6] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
2026-09-11 14:40 ` [PATCH v2 2/6] s390: " Petr Pavlu
2026-09-11 14:40 ` [PATCH v2 3/6] drivers: Include linux/slab.h for kmalloc() functions Petr Pavlu
2026-09-11 14:40 ` [PATCH v2 4/6] s390: Remove the asm/mmu_context.h include from asm/elf.h Petr Pavlu
2026-09-11 14:40 ` [PATCH v2 5/6] cpufeature: Include asm/elf.h for ELF_PLATFORM Petr Pavlu
2026-09-11 14:40 ` [PATCH v2 6/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®