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/[email protected]
2: [PATCH 00/11] Fix implicit includes of <module.h> that will break.
https://lkml.kernel.org/r/[email protected]>
3: [PATCH 00/15] Replace module_init with device_initcall in non modules
https://lkml.kernel.org/r/[email protected]
4: [PATCH 00/11] Replace module_init with an alternate initcall in non modules
https://lkml.kernel.org/r/[email protected]
5: [PATCH 0/7] Introduce builtin_driver and use it for non-modular code
https://lkml.kernel.org/r/[email protected]>
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/[email protected]
---
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: [email protected]
Cc: [email protected]
Cc: [email protected]
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(-)
--
2.2.1
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]>
Cc: [email protected]
Signed-off-by: Paul Gortmaker <[email protected]>
---
arch/x86/kernel/vsmp_64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
index ee22c1d93ae5..b034b1b14b9c 100644
--- a/arch/x86/kernel/vsmp_64.c
+++ b/arch/x86/kernel/vsmp_64.c
@@ -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) {
--
2.2.1
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: [email protected]
Signed-off-by: Paul Gortmaker <[email protected]>
---
arch/arm/kernel/entry-armv.S | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 570306c49406..4942fab6ae28 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -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>
--
2.2.1
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.
Reported-by: kbuild test robot <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: [email protected]
Signed-off-by: Paul Gortmaker <[email protected]>
---
arch/mips/loongson/common/serial.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/mips/loongson/common/serial.c b/arch/mips/loongson/common/serial.c
index c23fa1373729..ffefc1cb2612 100644
--- a/arch/mips/loongson/common/serial.c
+++ b/arch/mips/loongson/common/serial.c
@@ -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);
--
2.2.1
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.
Cc: Rusty Russell <[email protected]>
Acked-by: Rusty Russell <[email protected]>
Signed-off-by: Paul Gortmaker <[email protected]>
---
[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(-)
diff --git a/include/linux/init.h b/include/linux/init.h
index 21b6d768edd7..4e44857d8da4 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -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
diff --git a/include/linux/module.h b/include/linux/module.h
index c883b86ea964..64779468f8e8 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -11,6 +11,7 @@
#include <linux/compiler.h>
#include <linux/cache.h>
#include <linux/kmod.h>
+#include <linux/init.h>
#include <linux/elf.h>
#include <linux/stringify.h>
#include <linux/kobject.h>
@@ -70,6 +71,89 @@ extern struct module_attribute module_uevent;
extern int init_module(void);
extern void cleanup_module(void);
+#ifndef MODULE
+/**
+ * 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)));
+
+#endif
+
+/* 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*/
+
/* Archs provide a method of finding the correct exception table. */
struct exception_table_entry;
--
2.2.1
On Tue, 2015-06-02 at 16:16 -0400, Paul Gortmaker wrote:
> +static void __init serial_exit(void)
s/__init/__exit/
> +{
> + platform_device_unregister(&uart8250_device);
> +}
> +module_exit(serial_exit);
Paul Bolle
[Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular] On 02/06/2015 (Tue 23:47) Paul Bolle wrote:
> On Tue, 2015-06-02 at 16:16 -0400, Paul Gortmaker wrote:
> > +static void __init serial_exit(void)
>
> s/__init/__exit/
Argh, yes thanks for spotting that copy-n-waste error. Will fix.
Paul.
--
>
> > +{
> > + platform_device_unregister(&uart8250_device);
> > +}
> > +module_exit(serial_exit);
>
>
> Paul Bolle
>
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
On Tue, Jun 02, 2015 at 04:16:07PM -0400, Paul Gortmaker wrote:
Ccing a few people with interest in Loongson stuff.
> 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.
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
Signed-off-by: Ralf Baechle <[email protected]>
diff --git a/arch/mips/loongson/common/Makefile b/arch/mips/loongson/common/Makefile
index e70c33f..f2e8153 100644
--- a/arch/mips/loongson/common/Makefile
+++ b/arch/mips/loongson/common/Makefile
@@ -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
[Re: [PATCH 3/4] mips: make loongsoon serial driver explicitly modular] On 09/06/2015 (Tue 09:35) Ralf Baechle wrote:
> On Tue, Jun 02, 2015 at 04:16:07PM -0400, Paul Gortmaker wrote:
>
> Ccing a few people with interest in Loongson stuff.
>
> > 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.
>
> 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
>
> Signed-off-by: Ralf Baechle <[email protected]>
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.
--
>
> diff --git a/arch/mips/loongson/common/Makefile b/arch/mips/loongson/common/Makefile
> index e70c33f..f2e8153 100644
> --- a/arch/mips/loongson/common/Makefile
> +++ b/arch/mips/loongson/common/Makefile
> @@ -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
>
On Tue, Jun 09, 2015 at 07:15:28PM -0400, Paul Gortmaker wrote:
> 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