Skip to contentSkip to conversation

s390: audit and remove needless module.h includes

PATCH Applied Paul Gortmaker 2 participants 5 messages Feb 9, 2017 – Feb 13, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover s390: audit and remove needless module.h includes

Originally module.h provided support for both what was modular code and what was providing support to modules via EXPORT_SYMBOL and friends.

That changed when we forked out support for the latter into the export.h header; roughly five years ago[1].

We dealt with the immediate fallout of that change back then, but we did not go through and "downgrade" all the non-modular module.h users to export.h, once the merge of that change enabled us to do so.

This means we should be able to reduce the usage of module.h in code that is obj-y Makefile or bool Kconfig. In the case of some of these which are modular, we can extend that to also include files that are building basic support functionality but not related to loading or registering the final module; such files also have no need whatsoever for module.h

The advantage in removing such instances is that module.h itself sources about 15 other headers; adding significantly to what we feed cpp, and it can obscure what headers we are effectively using.

Consider the following pseudo patch to introduce a no-op source that just includes module.h:

    diff --git a/init/Makefile b/init/Makefile
    --- a/init/Makefile
    +++ b/init/Makefile
    @@ -2,7 +2,7 @@

    -obj-y                          := main.o version.o mounts.o
    +obj-y                          := main.o version.o mounts.o foo.o

    diff --git a/init/foo.c b/init/foo.c
    new file mode 100644
    --- /dev/null
    +++ b/init/foo.c
    @@ -0,0 +1 @@
    +#include <linux/module.h>

With that in place, we then can see the impact with this:

   paul@builder:~/git/linux-head$ make O=../build/ init/foo.i
   make[1]: Entering directory '/home/paul/git/build'
     CPP     init/foo.i
   paul@builder:~/git/linux-head$ ls -lh ../build/init/foo.i 
   -rw-rw-r-- 1 paul paul 754K Jul 12 20:04 ../build/init/foo.i

So, with every module.h include, we guarantee a minimum of 3/4 of a MB of text output from cpp as the baseline of header preamble to process.

Repeating the same experiment with <linux/init.h> and the result is less than 12kB; with <linux/export.h> it is only about 1/2kB; with both it still is less than 12kB.

Since module.h might be the implicit source for init.h (for __init) and for export.h (for EXPORT_SYMBOL) we consider each instance for the requirement of either and replace as needed. Some additional implicit include issues were also fixed up as they appeared during build coverage.

The series was done on a per directory level for the larger dirs and then we tackle the remainder in the final commit. This seemed like a better solution than one giant commit.

There is no urgency to get this in tree, it can easily wait three weeks. That said, the risk here is entirely on introducing build failures -- there is no changes to generated code, so if build coverage is exhaustive, the risk should be zero.

To that end, I have done allmodconfig, allyesconfig and allnoconfig for s390 with these changes on the linux-next from today. We've already merged the changes from similar audits for x86 and other supported architectures, so this isn't a new issue.

Paul.

[1] https://lwn.net/Articles/453517/

---

Cc Heiko Carstens <[email protected]>
Cc Martin Schwidefsky <[email protected]>

Paul Gortmaker (3):
s390: kernel: Audit and remove any unnecessary uses of module.h
s390: mm: Audit and remove any unnecessary uses of module.h
s390: Audit and remove any remaining unnecessary uses of module.h

 arch/s390/include/asm/livepatch.h | 2 +-
 arch/s390/kernel/compat_linux.c   | 1 -
 arch/s390/kernel/cpcmd.c          | 2 +-
 arch/s390/kernel/crash_dump.c     | 3 ++-
 arch/s390/kernel/debug.c          | 2 +-
 arch/s390/kernel/diag.c           | 3 ++-
 arch/s390/kernel/dis.c            | 2 +-
 arch/s390/kernel/ebcdic.c         | 4 ++--
 arch/s390/kernel/ipl.c            | 3 ++-
 arch/s390/kernel/irq.c            | 3 ++-
 arch/s390/kernel/jump_label.c     | 1 -
 arch/s390/kernel/nmi.c            | 2 +-
 arch/s390/kernel/process.c        | 2 +-
 arch/s390/kernel/smp.c            | 2 +-
 arch/s390/kernel/stacktrace.c     | 2 +-
 arch/s390/kernel/sysinfo.c        | 2 +-
 arch/s390/kernel/time.c           | 2 +-
 arch/s390/kernel/vdso.c           | 2 +-
 arch/s390/kvm/kvm-s390.c          | 1 +
 arch/s390/lib/delay.c             | 2 +-
 arch/s390/lib/spinlock.c          | 2 +-
 arch/s390/lib/string.c            | 3 ++-
 arch/s390/lib/xor.c               | 2 +-
 arch/s390/mm/cmm.c                | 1 +
 arch/s390/mm/dump_pagetables.c    | 1 -
 arch/s390/mm/extmem.c             | 2 +-
 arch/s390/mm/mem_detect.c         | 1 -
 arch/s390/mm/mmap.c               | 2 +-
 arch/s390/mm/pageattr.c           | 1 -
 arch/s390/mm/vmem.c               | 2 +-
 30 files changed, 31 insertions(+), 29 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 s390: kernel: Audit and remove any unnecessary uses of module.h

Historically a lot of these existed because we did not have a distinction between what was modular code and what was providing support to modules via EXPORT_SYMBOL and friends. That changed when we forked out support for the latter into the export.h file.

This means we should be able to reduce the usage of module.h in code that is obj-y Makefile or bool Kconfig. The advantage in doing so is that module.h itself sources about 15 other headers; adding significantly to what we feed cpp, and it can obscure what headers we are effectively using.

Since module.h was the source for init.h (for __init) and for export.h (for EXPORT_SYMBOL) we consider each change instance for the presence of either and replace as needed. Build testing revealed some implicit header usage that was fixed up accordingly.

Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
---
 arch/s390/kernel/compat_linux.c | 1 -
 arch/s390/kernel/cpcmd.c        | 2 +-
 arch/s390/kernel/crash_dump.c   | 3 ++-
 arch/s390/kernel/debug.c        | 2 +-
 arch/s390/kernel/diag.c         | 3 ++-
 arch/s390/kernel/dis.c          | 2 +-
 arch/s390/kernel/ebcdic.c       | 4 ++--
 arch/s390/kernel/ipl.c          | 3 ++-
 arch/s390/kernel/irq.c          | 3 ++-
 arch/s390/kernel/jump_label.c   | 1 -
 arch/s390/kernel/nmi.c          | 2 +-
 arch/s390/kernel/process.c      | 2 +-
 arch/s390/kernel/smp.c          | 2 +-
 arch/s390/kernel/stacktrace.c   | 2 +-
 arch/s390/kernel/sysinfo.c      | 2 +-
 arch/s390/kernel/time.c         | 2 +-
 arch/s390/kernel/vdso.c         | 2 +-
 17 files changed, 20 insertions(+), 18 deletions(-)
arch/s390/kernel/compat_linux.c +0 -1
index 96df4547377a..a3d14161abcb 100644
@@ -28,7 +28,6 @@
 #include <linux/shm.h>
 #include <linux/uio.h>
 #include <linux/quota.h>
-#include <linux/module.h>
 #include <linux/poll.h>
 #include <linux/personality.h>
 #include <linux/stat.h>
arch/s390/kernel/cpcmd.c +1 -1
index 7f48e568ac64..9f0e4a2785f7 100644
@@ -9,7 +9,7 @@
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
 #include <linux/kernel.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/stddef.h>
arch/s390/kernel/crash_dump.c +2 -1
index 9c9440dc253a..d49715398e47 100644
@@ -8,7 +8,8 @@
 #include <linux/crash_dump.h>
 #include <asm/lowcore.h>
 #include <linux/kernel.h>
-#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/mm.h>
 #include <linux/gfp.h>
 #include <linux/slab.h>
 #include <linux/bootmem.h>
arch/s390/kernel/debug.c +1 -1
index 20a5a4286368..530226b6cb19 100644
@@ -20,7 +20,7 @@
 #include <linux/string.h>
 #include <linux/sysctl.h>
 #include <linux/uaccess.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/debugfs.h>
arch/s390/kernel/diag.c +2 -1
index a97354c8c667..ac6abcd3fe6a 100644
@@ -5,7 +5,8 @@
  * Author(s): Michael Holzheu <[email protected]>
  */
 
-#include <linux/module.h>
+#include <linux/export.h>
+#include <linux/init.h>
 #include <linux/cpu.h>
 #include <linux/seq_file.h>
 #include <linux/debugfs.h>
arch/s390/kernel/dis.c +1 -1
index 9f017cf417f6..f7e82302a71e 100644
@@ -16,7 +16,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/kallsyms.h>
 #include <linux/reboot.h>
 #include <linux/kprobes.h>
arch/s390/kernel/ebcdic.c +2 -2
index b971c6be6298..1d5392b36ad8 100644
@@ -8,8 +8,8 @@
  *               Martin Peschke <[email protected]>
  */
 
-#include <linux/module.h>
-#include <asm/types.h>
+#include <linux/types.h>
+#include <linux/export.h>
 #include <asm/ebcdic.h>
 
 /*
arch/s390/kernel/ipl.c +2 -1
index 5b91308f6117..b67dafb7b7cf 100644
@@ -8,7 +8,8 @@
  */
 
 #include <linux/types.h>
-#include <linux/module.h>
+#include <linux/export.h>
+#include <linux/init.h>
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/reboot.h>
arch/s390/kernel/irq.c +2 -1
index ef60f4177331..6dca93b29bed 100644
@@ -12,11 +12,12 @@
 #include <linux/seq_file.h>
 #include <linux/proc_fs.h>
 #include <linux/profile.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
+#include <linux/init.h>
 #include <linux/cpu.h>
 #include <linux/irq.h>
 #include <asm/irq_regs.h>
arch/s390/kernel/jump_label.c +0 -1
index 083b05f5f5ab..6aa630a8d24f 100644
@@ -4,7 +4,6 @@
  * Copyright IBM Corp. 2011
  * Author(s): Jan Glauber <[email protected]>
  */
-#include <linux/module.h>
 #include <linux/uaccess.h>
 #include <linux/stop_machine.h>
 #include <linux/jump_label.h>
arch/s390/kernel/nmi.c +1 -1
index 9862196b4b89..56e14d073167 100644
@@ -13,7 +13,7 @@
 #include <linux/errno.h>
 #include <linux/hardirq.h>
 #include <linux/time.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <asm/lowcore.h>
 #include <asm/smp.h>
 #include <asm/stp.h>
arch/s390/kernel/process.c +1 -1
index 400d14f0b9f5..c5b86b4a1a8b 100644
@@ -23,7 +23,7 @@
 #include <linux/compat.h>
 #include <linux/kprobes.h>
 #include <linux/random.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/init_task.h>
 #include <asm/io.h>
 #include <asm/processor.h>
arch/s390/kernel/smp.c +1 -1
index e49f61aadaf9..d0a74d7ce433 100644
@@ -20,7 +20,7 @@
 
 #include <linux/workqueue.h>
 #include <linux/bootmem.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/err.h>
arch/s390/kernel/stacktrace.c +1 -1
index 355db9db8210..0085b2d8ed7d 100644
@@ -8,7 +8,7 @@
 #include <linux/sched.h>
 #include <linux/stacktrace.h>
 #include <linux/kallsyms.h>
-#include <linux/module.h>
+#include <linux/export.h>
 
 static int __save_address(void *data, unsigned long address, int nosched)
 {
arch/s390/kernel/sysinfo.c +1 -1
index 24021c1e3ecb..12b6b138e354 100644
@@ -10,7 +10,7 @@
 #include <linux/seq_file.h>
 #include <linux/init.h>
 #include <linux/delay.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/slab.h>
 #include <asm/ebcdic.h>
 #include <asm/sysinfo.h>
arch/s390/kernel/time.c +1 -1
index 546e513a0271..de66abb479c9 100644
@@ -16,7 +16,7 @@
 
 #include <linux/kernel_stat.h>
 #include <linux/errno.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/param.h>
arch/s390/kernel/vdso.c +1 -1
index 5904abf6b1ae..10516ae3b55e 100644
@@ -9,7 +9,7 @@
  * as published by the Free Software Foundation.
  */
 
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/3 s390: mm: Audit and remove any unnecessary uses of module.h

In reply to Paul Gortmaker

Historically a lot of these existed because we did not have a distinction between what was modular code and what was providing support to modules via EXPORT_SYMBOL and friends. That changed when we forked out support for the latter into the export.h file.

This means we should be able to reduce the usage of module.h in code that is obj-y Makefile or bool Kconfig. The advantage in doing so is that module.h itself sources about 15 other headers; adding significantly to what we feed cpp, and it can obscure what headers we are effectively using.

Since module.h was the source for init.h (for __init) and for export.h (for EXPORT_SYMBOL) we consider each change instance for the presence of either and replace as needed. An instance where module_param was used without moduleparam.h was also fixed, as well as an implict use of asm/elf.h header.

Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
---
 arch/s390/mm/cmm.c             | 1 +
 arch/s390/mm/dump_pagetables.c | 1 -
 arch/s390/mm/extmem.c          | 2 +-
 arch/s390/mm/mem_detect.c      | 1 -
 arch/s390/mm/mmap.c            | 2 +-
 arch/s390/mm/pageattr.c        | 1 -
 arch/s390/mm/vmem.c            | 2 +-
 7 files changed, 4 insertions(+), 6 deletions(-)
arch/s390/mm/cmm.c +1 -0
index 79ddd580d605..829c63dbc81a 100644
@@ -10,6 +10,7 @@
 #include <linux/fs.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/gfp.h>
 #include <linux/sched.h>
 #include <linux/sysctl.h>
arch/s390/mm/dump_pagetables.c +0 -1
index 5a46b1d7e578..145a0ccb5845 100644
@@ -1,6 +1,5 @@
 #include <linux/seq_file.h>
 #include <linux/debugfs.h>
-#include <linux/module.h>
 #include <linux/mm.h>
 #include <asm/sections.h>
 #include <asm/pgtable.h>
arch/s390/mm/extmem.c +1 -1
index 91af69f1dce5..9f118629b55f 100644
@@ -14,7 +14,7 @@
 #include <linux/spinlock.h>
 #include <linux/list.h>
 #include <linux/slab.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/bootmem.h>
 #include <linux/ctype.h>
 #include <linux/ioport.h>
arch/s390/mm/mem_detect.c +0 -1
index 185e70d3e153..e58dca05b962 100644
@@ -5,7 +5,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/module.h>
 #include <linux/memblock.h>
 #include <linux/init.h>
 #include <linux/debugfs.h>
arch/s390/mm/mmap.c +1 -1
index eb9df2822da1..7ae1282d5be9 100644
@@ -26,11 +26,11 @@
 #include <linux/personality.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
-#include <linux/module.h>
 #include <linux/random.h>
 #include <linux/compat.h>
 #include <linux/security.h>
 #include <asm/pgalloc.h>
+#include <asm/elf.h>
 
 static unsigned long stack_maxrandom_size(void)
 {
arch/s390/mm/pageattr.c +0 -1
index a1543b74ee00..fc5dc33bb141 100644
@@ -3,7 +3,6 @@
  * Author(s): Jan Glauber <[email protected]>
  */
 #include <linux/hugetlb.h>
-#include <linux/module.h>
 #include <linux/mm.h>
 #include <asm/cacheflush.h>
 #include <asm/facility.h>
arch/s390/mm/vmem.c +1 -1
index 253046344b3c..60d38993f232 100644
@@ -6,7 +6,7 @@
 #include <linux/bootmem.h>
 #include <linux/pfn.h>
 #include <linux/mm.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/list.h>
 #include <linux/hugetlb.h>
 #include <linux/slab.h>
Signature · 1 line
2.11.0
#3 lore raw

PATCH 3/3 s390: Audit and remove any remaining unnecessary uses of module.h

In reply to Paul Gortmaker

Historically a lot of these existed because we did not have a distinction between what was modular code and what was providing support to modules via EXPORT_SYMBOL and friends. That changed when we forked out support for the latter into the export.h file.

This means we should be able to reduce the usage of module.h in code that is obj-y Makefile or bool Kconfig. The advantage in doing so is that module.h itself sources about 15 other headers; adding significantly to what we feed cpp, and it can obscure what headers we are effectively using.

Since module.h was the source for init.h (for __init) and for export.h (for EXPORT_SYMBOL) we consider each change instance for the presence of either and replace as needed. An instance where module_param was used without moduleparam.h was also fixed, as well as implicit use of ptrace.h and string.h headers.

Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
---
 arch/s390/include/asm/livepatch.h | 2 +-
 arch/s390/kvm/kvm-s390.c          | 1 +
 arch/s390/lib/delay.c             | 2 +-
 arch/s390/lib/spinlock.c          | 2 +-
 arch/s390/lib/string.c            | 3 ++-
 arch/s390/lib/xor.c               | 2 +-
 6 files changed, 7 insertions(+), 5 deletions(-)
arch/s390/include/asm/livepatch.h +1 -1
index 2c1213785892..6de5c6cb0061 100644
@@ -17,7 +17,7 @@
 #ifndef ASM_LIVEPATCH_H
 #define ASM_LIVEPATCH_H
 
-#include <linux/module.h>
+#include <asm/ptrace.h>
 
 static inline int klp_check_compiler_support(void)
 {
arch/s390/kvm/kvm-s390.c +1 -0
index 502de74ea984..7ec5d86ca61a 100644
@@ -23,6 +23,7 @@
 #include <linux/kvm_host.h>
 #include <linux/mman.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/timer.h>
arch/s390/lib/delay.c +1 -1
index 501dcd4ca4a0..92e90e40b6fb 100644
@@ -9,7 +9,7 @@
 #include <linux/sched.h>
 #include <linux/delay.h>
 #include <linux/timex.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/irqflags.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
arch/s390/lib/spinlock.c +1 -1
index e48a48ec24bc..03462326ca3e 100644
@@ -6,7 +6,7 @@
  */
 
 #include <linux/types.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/spinlock.h>
 #include <linux/init.h>
 #include <linux/smp.h>
arch/s390/lib/string.c +2 -1
index f71d9f655970..4ee27339c792 100644
@@ -9,7 +9,8 @@
 #define IN_ARCH_STRING_C 1
 
 #include <linux/types.h>
-#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/export.h>
 
 /*
  * Helper functions to find the end of a string
arch/s390/lib/xor.c +1 -1
index 7d94e3ec34a9..b4fd05c36151 100644
@@ -6,7 +6,7 @@
  */
 
 #include <linux/types.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/raid/xor.h>
 
 static void xor_xc_2(unsigned long bytes, unsigned long *p1, unsigned long *p2)
Signature · 1 line
2.11.0
#4 lore raw
In reply to Paul Gortmaker
Quoted 4 lines · Paul Gortmaker

Paul Gortmaker (3):
s390: kernel: Audit and remove any unnecessary uses of module.h
s390: mm: Audit and remove any unnecessary uses of module.h
s390: Audit and remove any remaining unnecessary uses of module.h

Applied, thanks!