Skip to contentSkip to conversation

Relocate module code from init.h to module.h

PATCH In review Paul Gortmaker 3 participants 11 messages Jun 2, 2015 – Jun 10, 2015

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

cover Relocate module code from init.h to module.h

What started as a removal of no longer required include <linux/init.h> due to the earlier __cpuinit and __devinit removal led to the observation that some module specfic support was living in init.h itself, thus preventing the full removal from introducing compile regressions.

This series of commits includes the final relocation of the modular init code from <init.h> to <module.h> -- we do this because modular users will always be users of init functionality, but users of init functionality are not necessarily always modules. Once done, the trivial one line removals can be finalized at any time, a bit at a time, through maintainer trees etc.

In order to do that, a couple of final things that this will uncover are fixed up here -- things that weren't easily categorized into any of the other previous series leading up to this final one. The previous groupings of commits that get us to this final series are:

1: [PATCH 00/11] Delete new __cpuinit users and then delete stubs
https://lkml.kernel.org/r/1430174880-27958-1-git-send-email-paul.gortmaker at windriver.com

2: [PATCH 00/11] Fix implicit includes of <module.h> that will break.
https://lkml.kernel.org/r/1430444867-22342-1-git-send-email-paul.gortmaker at windriver.com>

3: [PATCH 00/15] Replace module_init with device_initcall in non modules
https://lkml.kernel.org/r/1432860493-23831-1-git-send-email-paul.gortmaker at windriver.com

4: [PATCH 00/11] Replace module_init with an alternate initcall in non modules
https://lkml.kernel.org/r/1433120052-18281-1-git-send-email-paul.gortmaker at windriver.com

5: [PATCH 0/7] Introduce builtin_driver and use it for non-modular code
https://lkml.kernel.org/r/1431287385-1526-1-git-send-email-paul.gortmaker at windriver.com>

This group of six is factored out from what was a previously larger series[1] so that there is a common theme and lower patch count to ease review. Setting aside the trivial one line include <linux/init.h> removals for later also greatly reduces the series size and makes all six parts more manageable.

Paul.

[1] http://lkml.kernel.org/r/1390339396-3479-1-git-send-email-paul.gortmaker at windriver.com

---

Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Russell King <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc linux-mips at linux-mips.org
Cc x86 at kernel.org

Paul Gortmaker (4):
x86: replace __init_or_module with __init in non-modular vsmp_64.c
arm: fix implicit #include <linux/init.h> in entry asm.
mips: make loongsoon serial driver explicitly modular
module: relocate module_init from init.h to module.h

 arch/arm/kernel/entry-armv.S       |  2 +
 arch/mips/loongson/common/serial.c |  9 +++-
 arch/x86/kernel/vsmp_64.c          |  2 +-
 include/linux/init.h               | 78 -----------------------------------
 include/linux/module.h             | 84 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 94 insertions(+), 81 deletions(-)
Signature · 1 line
2.2.1
#2 lore raw

PATCH 2/4 arm: fix implicit #include <linux/init.h> in entry asm.

They use the "_INIT" macro and friends, and hence need to source this header file, vs. relying on getting it implicitly.

Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/kernel/entry-armv.S | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/kernel/entry-armv.S +2 -0
index 570306c49406..4942fab6ae28 100644
@@ -15,6 +15,8 @@
  *  that causes it to save wrong values...  Be aware!
  */
 
+#include <linux/init.h>
+
 #include <asm/assembler.h>
 #include <asm/memory.h>
 #include <asm/glue-df.h>
Signature · 1 line
2.2.1
#3 lore raw

PATCH 3/4 mips: make loongsoon serial driver explicitly modular

In reply to Paul Gortmaker

The file looks as if it is non-modular, but it piggy-backs off CONFIG_SERIAL_8250 which is tristate. If set to "=m" we will get this after the init/module header cleanup:

arch/mips/loongson/common/serial.c:76:1: error: data definition has no type or storage class [-Werror] arch/mips/loongson/common/serial.c:76:1: error: type defaults to 'int' in declaration of 'device_initcall' [-Werror=implicit-int] arch/mips/loongson/common/serial.c:76:1: error: parameter names (without types) in function declaration [-Werror] arch/mips/loongson/common/serial.c:58:19: error: 'serial_init' defined but not used [-Werror=unused-function]
cc1: all warnings being treated as errors
make[3]: *** [arch/mips/loongson/common/serial.o] Error 1

Make it clearly modular, and add a module_exit function, so that we avoid the above breakage.

---
 arch/mips/loongson/common/serial.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/mips/loongson/common/serial.c +7 -2
index c23fa1373729..ffefc1cb2612 100644
@@ -11,7 +11,7 @@
  */
 
 #include <linux/io.h>
-#include <linux/init.h>
+#include <linux/module.h>
 #include <linux/serial_8250.h>
 
 #include <asm/bootinfo.h>
@@ -108,5 +108,10 @@ static int __init serial_init(void)
 
 	return platform_device_register(&uart8250_device);
 }
+module_init(serial_init);
 
-device_initcall(serial_init);
+static void __init serial_exit(void)
+{
+	platform_device_unregister(&uart8250_device);
+}
+module_exit(serial_exit);
Signature · 1 line
2.2.1
#10 lore raw

PATCH 4/4 module: relocate module_init from init.h to module.h

In reply to Paul Gortmaker

Modular users will always be users of init functionality, but users of init functionality are not necessarily always modules.

Hence any functionality like module_init and module_exit would be more at home in the module.h file. And module.h should explicitly include init.h to make the dependency clear.

We've already done all the legwork needed to ensure that this move does not cause any build regressions due to implicit header file include assumptions about where module_init lives.

---

[patch is essentially unchanged from the orignal Rusty acked here:
https://lkml.kernel.org/r/[email protected]
...and yes we still have the lingering semicolon issue mentioned there, it needs a treewide sweep before the header can be fixed.]

 include/linux/init.h   | 78 ----------------------------------------------
 include/linux/module.h | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 78 deletions(-)
include/linux/init.h +0 -78
index 21b6d768edd7..4e44857d8da4 100644
@@ -293,68 +293,8 @@ void __init parse_early_param(void);
 void __init parse_early_options(char *cmdline);
 #endif /* __ASSEMBLY__ */
 
-/**
- * module_init() - driver initialization entry point
- * @x: function to be run at kernel boot time or module insertion
- * 
- * module_init() will either be called during do_initcalls() (if
- * builtin) or at module insertion time (if a module).  There can only
- * be one per module.
- */
-#define module_init(x)	__initcall(x);
-
-/**
- * module_exit() - driver exit entry point
- * @x: function to be run when driver is removed
- * 
- * module_exit() will wrap the driver clean-up code
- * with cleanup_module() when used with rmmod when
- * the driver is a module.  If the driver is statically
- * compiled into the kernel, module_exit() has no effect.
- * There can only be one per module.
- */
-#define module_exit(x)	__exitcall(x);
-
 #else /* MODULE */
 
-/*
- * In most cases loadable modules do not need custom
- * initcall levels. There are still some valid cases where
- * a driver may be needed early if built in, and does not
- * matter when built as a loadable module. Like bus
- * snooping debug drivers.
- */
-#define early_initcall(fn)		module_init(fn)
-#define core_initcall(fn)		module_init(fn)
-#define core_initcall_sync(fn)		module_init(fn)
-#define postcore_initcall(fn)		module_init(fn)
-#define postcore_initcall_sync(fn)	module_init(fn)
-#define arch_initcall(fn)		module_init(fn)
-#define subsys_initcall(fn)		module_init(fn)
-#define subsys_initcall_sync(fn)	module_init(fn)
-#define fs_initcall(fn)			module_init(fn)
-#define fs_initcall_sync(fn)		module_init(fn)
-#define rootfs_initcall(fn)		module_init(fn)
-#define device_initcall(fn)		module_init(fn)
-#define device_initcall_sync(fn)	module_init(fn)
-#define late_initcall(fn)		module_init(fn)
-#define late_initcall_sync(fn)		module_init(fn)
-
-#define console_initcall(fn)		module_init(fn)
-#define security_initcall(fn)		module_init(fn)
-
-/* Each module must use one module_init(). */
-#define module_init(initfn)					\
-	static inline initcall_t __inittest(void)		\
-	{ return initfn; }					\
-	int init_module(void) __attribute__((alias(#initfn)));
-
-/* This is only required if you want to be unloadable. */
-#define module_exit(exitfn)					\
-	static inline exitcall_t __exittest(void)		\
-	{ return exitfn; }					\
-	void cleanup_module(void) __attribute__((alias(#exitfn)));
-
 #define __setup_param(str, unique_id, fn)	/* nothing */
 #define __setup(str, func) 			/* nothing */
 #endif
@@ -362,24 +302,6 @@ void __init parse_early_options(char *cmdline);
 /* Data marked not to be saved by software suspend */
 #define __nosavedata __section(.data..nosave)
 
-/* This means "can be init if no module support, otherwise module load
-   may call it." */
-#ifdef CONFIG_MODULES
-#define __init_or_module
-#define __initdata_or_module
-#define __initconst_or_module
-#define __INIT_OR_MODULE	.text
-#define __INITDATA_OR_MODULE	.data
-#define __INITRODATA_OR_MODULE	.section ".rodata","a",%progbits
-#else
-#define __init_or_module __init
-#define __initdata_or_module __initdata
-#define __initconst_or_module __initconst
-#define __INIT_OR_MODULE __INIT
-#define __INITDATA_OR_MODULE __INITDATA
-#define __INITRODATA_OR_MODULE __INITRODATA
-#endif /*CONFIG_MODULES*/
-
 #ifdef MODULE
 #define __exit_p(x) x
 #else
include/linux/module.h +84 -0

96 lines not on this page · raw message

Signature · 1 line
2.2.1
#1 lore raw

PATCH 1/4 x86: replace __init_or_module with __init in non-modular vsmp_64.c

In reply to Paul Gortmaker

The __init_or_module is from commit 05e12e1c4c09cd35ac9f4e6af1e ("x86: fix 27-rc crash on vsmp due to paravirt during module load").

But as of commit 70511134f61bd6e5eed19f767381f9fb3e762d49 ("Revert "x86: don't compile vsmp_64 for 32bit") this file became obj-y and hence is now only for built-in. That makes any "_or_module" support no longer necessary.

We need to distinguish between the two in order to do some header reorganization between init.h and module.h and we don't want to be including module.h in non-modular code.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/vsmp_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/vsmp_64.c +1 -1
index ee22c1d93ae5..b034b1b14b9c 100644
@@ -72,7 +72,7 @@ asmlinkage __visible void vsmp_irq_enable(void)
 }
 PV_CALLEE_SAVE_REGS_THUNK(vsmp_irq_enable);
 
-static unsigned __init_or_module vsmp_patch(u8 type, u16 clobbers, void *ibuf,
+static unsigned __init vsmp_patch(u8 type, u16 clobbers, void *ibuf,
 				  unsigned long addr, unsigned len)
 {
 	switch (type) {
Signature · 1 line
2.2.1
#4 lore raw

Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular

In reply to Paul Gortmaker
Quoted 1 line · Paul Gortmaker

+static void __init serial_exit(void)

s/__init/__exit/

arch/mips/loongson/common/serial.c static int __init serial_init(void) · line 117

Quoted 4 lines
arch/mips/loongson/common/serial.c +4 -0
+{
+	platform_device_unregister(&uart8250_device);
+}
+module_exit(serial_exit);

Paul Bolle

#5 lore raw

Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular

Quoted 4 lines · [Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular] On…
Quoted 1 line · Paul Gortmaker

+static void __init serial_exit(void)

s/__init/__exit/

Argh, yes thanks for spotting that copy-n-waste error. Will fix.

Paul.
--

Quoted 9 lines

arch/mips/loongson/common/serial.c static int __init serial_init(void) · line 117

Quoted 5 lines
arch/mips/loongson/common/serial.c +4 -0
+{
+	platform_device_unregister(&uart8250_device);
+}
+module_exit(serial_exit);

Paul Bolle

#6 lore raw

Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular

In reply to Paul Gortmaker

On Tue, Jun 02, 2015 at 04:16:07PM -0400, Paul Gortmaker wrote:

Bad timing for a Loongson patch - I just applied a patch that moves every file around. I resolved that conflict and applied your patch.

Ralf

#7 lore raw

Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular

In reply to Paul Gortmaker

On Tue, Jun 02, 2015 at 04:16:07PM -0400, Paul Gortmaker wrote:

Ccing a few people with interest in Loongson stuff.

Quoted 11 lines

The file looks as if it is non-modular, but it piggy-backs off CONFIG_SERIAL_8250 which is tristate. If set to "=m" we will get this after the init/module header cleanup:

arch/mips/loongson/common/serial.c:76:1: error: data definition has no type or storage class [-Werror] arch/mips/loongson/common/serial.c:76:1: error: type defaults to 'int' in declaration of 'device_initcall' [-Werror=implicit-int] arch/mips/loongson/common/serial.c:76:1: error: parameter names (without types) in function declaration [-Werror] arch/mips/loongson/common/serial.c:58:19: error: 'serial_init' defined but not used [-Werror=unused-function]
cc1: all warnings being treated as errors
make[3]: *** [arch/mips/loongson/common/serial.o] Error 1

Quoted 2 lines

Make it clearly modular, and add a module_exit function, so that we avoid the above breakage.

Following up on our IRC discussion - your commit would result in platform device registrations from module code which opens another can of worms. This and the whole philosophy of platforms devices to show what devices do exist in a system, not which drivers are configured. So just always build serial.c into the kernel.

A related issue is uart_base.o which I think is required to register properly initialized platform devices. It depends on CONFIG_LOONGSON_UART_BASE but probably should also be put into the kernel whenever we register the UART platform devices and that's always.

Ralf

arch/mips/loongson/common/Makefile +1 -3
index e70c33f..f2e8153 100644
@@ -3,15 +3,13 @@
 #
 
 obj-y += setup.o init.o cmdline.o env.o time.o reset.o irq.o \
-    bonito-irq.o mem.o machtype.o platform.o
+    bonito-irq.o mem.o machtype.o platform.o serial.o
 obj-$(CONFIG_PCI) += pci.o
 
 #
 # Serial port support
 #
 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
-loongson-serial-$(CONFIG_SERIAL_8250) := serial.o
-obj-y += $(loongson-serial-m) $(loongson-serial-y)
 obj-$(CONFIG_LOONGSON_UART_BASE) += uart_base.o
 obj-$(CONFIG_LOONGSON_MC146818) += rtc.o
 
#8 lore raw

Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular

Quoted 30 lines · [Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular] On…

On Tue, Jun 02, 2015 at 04:16:07PM -0400, Paul Gortmaker wrote:

Ccing a few people with interest in Loongson stuff.

Quoted 11 lines

The file looks as if it is non-modular, but it piggy-backs off CONFIG_SERIAL_8250 which is tristate. If set to "=m" we will get this after the init/module header cleanup:

arch/mips/loongson/common/serial.c:76:1: error: data definition has no type or storage class [-Werror] arch/mips/loongson/common/serial.c:76:1: error: type defaults to 'int' in declaration of 'device_initcall' [-Werror=implicit-int] arch/mips/loongson/common/serial.c:76:1: error: parameter names (without types) in function declaration [-Werror] arch/mips/loongson/common/serial.c:58:19: error: 'serial_init' defined but not used [-Werror=unused-function]
cc1: all warnings being treated as errors
make[3]: *** [arch/mips/loongson/common/serial.o] Error 1

Quoted 2 lines

Make it clearly modular, and add a module_exit function, so that we avoid the above breakage.

Following up on our IRC discussion - your commit would result in platform device registrations from module code which opens another can of worms. This and the whole philosophy of platforms devices to show what devices do exist in a system, not which drivers are configured. So just always build serial.c into the kernel.

A related issue is uart_base.o which I think is required to register properly initialized platform devices. It depends on CONFIG_LOONGSON_UART_BASE but probably should also be put into the kernel whenever we register the UART platform devices and that's always.

Quoted 3 lines

Ralf

I've dropped my change in favour of this one, and crafted up a commit log from this e-mail exchange as follows:

https://git.kernel.org/cgit/linux/kernel/git/paulg/linux.git/commit/?h=init-v4.1-rc6&id=5eee56adcce9b0baf2da55c0bff88eb0f1c0eb61

Assuming nobody else has an issue with it, then we should be done here (i.e. it doesn't even need to be in mips-next; it just needs to be here in this series so we don't get bisect fails introduced.)

Thanks,
Paul.
--

Quoted 22 lines
arch/mips/loongson/common/Makefile +1 -3
index e70c33f..f2e8153 100644
@@ -3,15 +3,13 @@
 #
 
 obj-y += setup.o init.o cmdline.o env.o time.o reset.o irq.o \
-    bonito-irq.o mem.o machtype.o platform.o
+    bonito-irq.o mem.o machtype.o platform.o serial.o
 obj-$(CONFIG_PCI) += pci.o
 
 #
 # Serial port support
 #
 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
-loongson-serial-$(CONFIG_SERIAL_8250) := serial.o
-obj-y += $(loongson-serial-m) $(loongson-serial-y)
 obj-$(CONFIG_LOONGSON_UART_BASE) += uart_base.o
 obj-$(CONFIG_LOONGSON_MC146818) += rtc.o
 
#9 lore raw

Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular

Quoted 8 lines · Paul Gortmaker

I've dropped my change in favour of this one, and crafted up a commit log from this e-mail exchange as follows:

https://git.kernel.org/cgit/linux/kernel/git/paulg/linux.git/commit/?h=init-v4.1-rc6&id=5eee56adcce9b0baf2da55c0bff88eb0f1c0eb61

Assuming nobody else has an issue with it, then we should be done here (i.e. it doesn't even need to be in mips-next; it just needs to be here in this series so we don't get bisect fails introduced.)

I've committed this as d9fb5660459819513d510e72caa3120a7cf41ee1 (MIPS:
Loongson: Do not register 8250 platform device from module.) on my 4.1-fixes branch and intend to send it out on Friday to Linus.

Still nothing heared about the uart_base.o situation.

Ralf