Skip to content

module: Limit ELF includes in linux/module.h to uapi/linux/elf.h

Petr Pavlu kvm linux-integrity linux-modules linux-s390 lkml 2 versions – In review

Get series with b4
b4 am [email protected] change-id 20260816-module-include-elf-a9c10c041867

Versions newest first · linked by author and title

  1. v2 Latest6 patches 2 repliesIn review
  2. v14 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- 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/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6x86: Avoid indirect includes through linux/module.h -> linux/elf.harch/x86/entry/entry_fred.c arch/x86/entry/syscall_32.c arch/x86/kernel/cpu/intel.c +3 more+6 -11 reply
2/6s390: Avoid indirect includes through linux/module.h -> linux/elf.harch/s390/kernel/nospec-branch.c drivers/s390/char/uvdevice.c+3 -00 replies
3/6drivers: Include linux/slab.h for kmalloc() functionsdrivers/char/tpm/tpm_crb_ffa.c drivers/virt/coco/arm-cca-guest/arm-cca-guest.c+2 -00 replies
4/6s390: Remove the asm/mmu_context.h include from asm/elf.harch/s390/include/asm/elf.h arch/s390/kernel/processor.c arch/s390/mm/mmap.c+2 -10 replies
5/6cpufeature: Include asm/elf.h for ELF_PLATFORMinclude/linux/cpufeature.h+1 -00 replies
6/6module: Limit ELF includes in linux/module.h to uapi/linux/elf.hinclude/linux/module.h+2 -20 replies

Reviews trailers per patch

2 of 6 patches have a Reviewed-by or Acked-by.

PatchAaron TomlinBorislav Petkov (AMD)
1/6A-b
2/6
3/6
4/6
5/6
6/6R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/6] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h

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/[email protected]

---
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