* [PATCH 0/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h
@ 2026-07-07 15:37 Petr Pavlu
2026-07-07 15:37 ` [PATCH 1/4] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-07-07 15:37 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 linux/module.h header is included by every *.mod.c file to provide
`struct module` and other related definitions. 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 three patches are cleanups to avoid relying on declarations being
indirectly provided through linux/module.h -> linux/elf.h. These patches
are all independent and can go through their respective trees. The final
patch depends on 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.
Petr Pavlu (4):
x86: Avoid indirect includes through linux/module.h -> linux/elf.h
s390: Avoid indirect includes through linux/module.h -> linux/elf.h
tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
module: Limit ELF includes in linux/module.h to uapi/linux/elf.h
arch/s390/kernel/nospec-branch.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 ++
include/linux/module.h | 4 ++--
10 files changed, 12 insertions(+), 3 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] x86: Avoid indirect includes through linux/module.h -> linux/elf.h
2026-07-07 15:37 [PATCH 0/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
@ 2026-07-07 15:37 ` Petr Pavlu
2026-07-07 15:37 ` [PATCH 2/4] s390: " Petr Pavlu
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-07-07 15:37 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 31b9492fe851..12fceffc99ef 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 abb3984336eb..18cf40f08557 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 85435044e33c..e40f7f3d3489 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.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] s390: Avoid indirect includes through linux/module.h -> linux/elf.h
2026-07-07 15:37 [PATCH 0/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
2026-07-07 15:37 ` [PATCH 1/4] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
@ 2026-07-07 15:37 ` Petr Pavlu
2026-07-07 15:37 ` [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree() Petr Pavlu
2026-07-07 15:37 ` [PATCH 4/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
3 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-07-07 15:37 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 e6a264c996ce..4fe3ead4a091 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.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
2026-07-07 15:37 [PATCH 0/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
2026-07-07 15:37 ` [PATCH 1/4] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
2026-07-07 15:37 ` [PATCH 2/4] s390: " Petr Pavlu
@ 2026-07-07 15:37 ` Petr Pavlu
2026-07-07 15:43 ` sashiko-bot
2026-07-07 15:37 ` [PATCH 4/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
3 siblings, 1 reply; 7+ messages in thread
From: Petr Pavlu @ 2026-07-07 15:37 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 drivers/char/tpm/tpm_crb_ffa.c file uses kzalloc_obj() and kfree(),
which are declared in linux/slab.h. It currently relies on this header
being included indirectly through linux/module.h -> linux/elf.h. Add the
missing include 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 +
1 file changed, 1 insertion(+)
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;
--
2.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h
2026-07-07 15:37 [PATCH 0/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
` (2 preceding siblings ...)
2026-07-07 15:37 ` [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree() Petr Pavlu
@ 2026-07-07 15:37 ` Petr Pavlu
3 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-07-07 15:37 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 linux/module.h header is included by every *.mod.c file to provide
`struct module` and other related definitions. 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>
---
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 7566815fabbe..7661faadbedd 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.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
2026-07-07 15:37 ` [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree() Petr Pavlu
@ 2026-07-07 15:43 ` sashiko-bot
2026-07-08 10:10 ` Petr Pavlu
0 siblings, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-07-07 15:43 UTC (permalink / raw)
To: Petr Pavlu
Cc: kvm, Heiko Carstens, linux-modules, Alexander Gordeev, linux-s390,
Vasily Gorbik
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The commit message incorrectly claims that the file uses `kzalloc_obj()` instead of `kzalloc()`.
--
--- Patch [3]: [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree() ---
commit a56e4cf89267d12126bd70f7981a05c846959016
Author: Petr Pavlu <petr.pavlu@suse.com>
tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
This commit adds the missing linux/slab.h inclusion to tpm_crb_ffa.c.
It removes the reliance on indirect inclusion through linux/module.h.
This prepares for the eventual removal of linux/elf.h from linux/module.h.
> tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
[Severity: Low]
This isn't a bug, but there appears to be a typo in the commit subject.
Did you mean kzalloc() instead of kzalloc_obj()? Looking at
tpm_crb_ffa_probe() in the driver, it correctly calls kzalloc().
> The drivers/char/tpm/tpm_crb_ffa.c file uses kzalloc_obj() and kfree(),
[Severity: Low]
This isn't a bug, but the same typo is also present here in the commit
description.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260707153819.4172541-1-petr.pavlu@suse.com?part=3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
2026-07-07 15:43 ` sashiko-bot
@ 2026-07-08 10:10 ` Petr Pavlu
0 siblings, 0 replies; 7+ messages in thread
From: Petr Pavlu @ 2026-07-08 10:10 UTC (permalink / raw)
To: sashiko-reviews
Cc: kvm, Heiko Carstens, linux-modules, Alexander Gordeev, linux-s390,
Vasily Gorbik
On 7/7/26 5:43 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] The commit message incorrectly claims that the file uses `kzalloc_obj()` instead of `kzalloc()`.
> --
>
> --- Patch [3]: [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree() ---
> commit a56e4cf89267d12126bd70f7981a05c846959016
> Author: Petr Pavlu <petr.pavlu@suse.com>
>
> tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
>
> This commit adds the missing linux/slab.h inclusion to tpm_crb_ffa.c.
> It removes the reliance on indirect inclusion through linux/module.h.
> This prepares for the eventual removal of linux/elf.h from linux/module.h.
>
>> tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree()
>
> [Severity: Low]
> This isn't a bug, but there appears to be a typo in the commit subject.
> Did you mean kzalloc() instead of kzalloc_obj()? Looking at
> tpm_crb_ffa_probe() in the driver, it correctly calls kzalloc().
>
>> The drivers/char/tpm/tpm_crb_ffa.c file uses kzalloc_obj() and kfree(),
>
> [Severity: Low]
> This isn't a bug, but the same typo is also present here in the commit
> description.
>
I don't see a typo here. The code uses the kzalloc_obj() macro:
https://github.com/torvalds/linux/blob/v7.2-rc2/drivers/char/tpm/tpm_crb_ffa.c#L339
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-07-08 10:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 15:37 [PATCH 0/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h Petr Pavlu
2026-07-07 15:37 ` [PATCH 1/4] x86: Avoid indirect includes through linux/module.h -> linux/elf.h Petr Pavlu
2026-07-07 15:37 ` [PATCH 2/4] s390: " Petr Pavlu
2026-07-07 15:37 ` [PATCH 3/4] tpm_crb_ffa: Include linux/slab.h for kzalloc_obj() and kfree() Petr Pavlu
2026-07-07 15:43 ` sashiko-bot
2026-07-08 10:10 ` Petr Pavlu
2026-07-07 15:37 ` [PATCH 4/4] 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