Replace module_init with an alternate initcall in non modules
Subsystems (13)
cover Replace module_init with an alternate initcall in non modules
This series of commits converts non-modular code that is using the module_init() call to hook itself into the system to instead use one of the alternate priority initcalls.
Unlike the earlier series[1] that used device_initcall and hence was a runtime no-op, these commits change to one of the alternate initcalls, because (a) we have them and (b) it seems like the right thing to do. For example, it would seem logical to use arch_initcall for arch specific setup code and fs_initcall for filesystem setup code.
This does mean however, that changes in the init ordering will be taking place, and so there is a small risk that some kind of implicit init ordering issue may lie uncovered. But I think it is still better to give these ones sensible priorities than to just assign them all to device_initcall in order to exactly preserve the old ordering.
Thad said, we have already made similar changes in core kernel code in commit c96d6660dc65b0a90aea9834bfd8be1d5656da18 ("kernel: audit/fix non-modular users of module_init in core code") without any regressions reported, so this type of change isn't without precedent.
This work is factored out from what was a previously larger series[2] so that there is a common theme and lower patch count to ease review.
Paul.
[1] https://lkml.org/lkml/2015/5/28/809
[2] https://marc.info/?l=linux-kernel&m=139033951228828
---
Paul Gortmaker (11):
mm: replace module_init usages with subsys_initcall in nommu.c fs/notify: don't use module_init for non-modular inotify_user code
netfilter: don't use module_init/exit in core IPV4 code
x86: don't use module_init for non-modular core bootflag code
powerpc: use subsys_initcall for Freescale Local Bus
powerpc: don't use module_init for non-modular core hugetlb code
arm: use subsys_initcall in non-modular pl320 IPC code lib/list_sort: use late_initcall to hook in self tests mm/page_owner.c: use late_initcall to hook in enabling
x86: perf_event_intel_bts.c: use arch_initcall to hook in enabling
x86: perf_event_intel_pt.c: use arch_initcall to hook in enabling
arch/powerpc/mm/hugetlbpage.c | 2 +- arch/powerpc/sysdev/fsl_lbc.c | 2 +- arch/x86/kernel/bootflag.c | 2 +- arch/x86/kernel/cpu/perf_event_intel_bts.c | 3 +-- arch/x86/kernel/cpu/perf_event_intel_pt.c | 3 +-- drivers/mailbox/pl320-ipc.c | 2 +- fs/notify/inotify/inotify_user.c | 4 ++-- lib/list_sort.c | 2 +- mm/nommu.c | 4 ++-- mm/page_owner.c | 2 +- net/ipv4/netfilter.c | 9 +-------- 11 files changed, 13 insertions(+), 22 deletions(-)
Signature · 1 line
2.2.1
PATCH 3/11 netfilter: don't use module_init/exit in core IPV4 code
The file net/ipv4/netfilter.o is created based on whether CONFIG_NETFILTER is set. However that is defined as a bool, and hence this file with the core netfilter hooks will never be modular. So using module_init as an alias for __initcall can be somewhat misleading.
Fix this up now, so that we can relocate module_init from init.h into module.h in the future. If we don't do this, we'd have to add module.h to obviously non-modular code, and that would be a worse thing. Also add an inclusion of init.h, as that was previously implicit here in the netfilter.c file.
Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of subsys_initcall (which seems to make sense for netfilter code) will thus change this registration from level 6-device to level 4-subsys (i.e. slightly earlier). However no observable impact of that small difference has been observed during testing, or is expected. (i.e. the location of the netfilter messages in dmesg remains unchanged with respect to all the other surrounding messages.)
As for the module_exit, rather than replace it with __exitcall, we simply remove it, since it appears only UML does anything with those, and even for UML, there is no relevant cleanup to be done here.
--- net/ipv4/netfilter.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
net/ipv4/netfilter.c +1 -8
@@ -197,11 +197,4 @@ static int __init ipv4_netfilter_init(void) {return nf_register_afinfo (&nf_ip_afinfo); } - -static void __exit ipv4_netfilter_fini(void) -{ -nf_unregister_afinfo (&nf_ip_afinfo); -} - -module_init (ipv4_netfilter_init); -module_exit (ipv4_netfilter_fini); +subsys_initcall (ipv4_netfilter_init);
Signature · 1 line
2.2.1
PATCH 7/11 arm: use subsys_initcall in non-modular pl320 IPC code
In reply to Paul GortmakerThe drivers/mailbox/pl320-ipc.o is dependent on config PL320_MBOX which is declared as a bool. Hence the code is never going to be modular. So using module_init as an alias for __initcall can be somewhat misleading.
Fix this up now, so that we can relocate module_init from init.h into module.h in the future. If we don't do this, we'd have to add module.h to obviously non-modular code, and that would be a worse thing. Also add an inclusion of init.h, as that was previously implicit.
Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of subsys_initcall (which seems to make sense for IPC code) will thus change this registration from level 6-device to level 4-subsys (i.e. slightly earlier). However no impact of that small difference is expected.
--- drivers/mailbox/pl320-ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mailbox/pl320-ipc.c +1 -1
@@ -195,4 +195,4 @@ static int __init ipc_init(void) {return amba_driver_register (&pl320_driver); } -module_init (ipc_init); +subsys_initcall (ipc_init);
Signature · 1 line
2.2.1
PATCH 1/11 mm: replace module_init usages with subsys_initcall in nommu.c
In reply to Paul GortmakerCompiling some arm/m68k configs with "# CONFIG_MMU is not set" reveals two more instances of module_init being used for code that can't possibly be modular, as CONFIG_MMU is either on or off.
We replace them with subsys_initcall as per what was done in other mmu-enabled code.
Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of subsys_initcall (which makes sense for these files) will thus change this registration from level 6-device to level 4-subsys (i.e. slightly earlier).
One might think that core_initcall (l2) or postcore_initcall (l3) would be more appropriate for anything in mm/ but if we look at the actual init functions themselves, we see they are just sysctl setup stuff, and hence the choice of subsys_initcall (l4) seems reasonable. At the same time it minimizes the risk of changing the priority too drastically all at once. We can adjust further in the future.
Also, a couple instances of missing ";" at EOL are fixed.
--- mm/nommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/nommu.c +2 -2
@@ -2157,7 +2157,7 @@ static int __meminit init_user_reserve(void) sysctl_user_reserve_kbytes =min (free_kbytes /32 ,1UL <<17 );return 0 ; } -module_init (init_user_reserve) +subsys_initcall (init_user_reserve);/* * Initialise sysctl_admin_reserve_kbytes.
@@ -2178,4 +2178,4 @@ static int __meminit init_admin_reserve(void) sysctl_admin_reserve_kbytes =min (free_kbytes /32 ,1UL <<13 );return 0 ; } -module_init (init_admin_reserve) +subsys_initcall (init_admin_reserve);
Signature · 7 lines
2.2.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/11 powerpc: don't use module_init for non-modular core hugetlb code
In reply to Paul GortmakerThe hugetlbpage.o is obj-y (always built in). It will never be modular, so using module_init as an alias for __initcall is somewhat misleading.
Fix this up now, so that we can relocate module_init from init.h into module.h in the future. If we don't do this, we'd have to add module.h to obviously non-modular code, and that would be a worse thing.
Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of arch_initcall (which makes sense for arch code) will thus change this registration from level 6-device to level 3-arch (i.e. slightly earlier). However no observable impact of that small difference has been observed during testing, or is expected.
--- arch/powerpc/mm/hugetlbpage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/mm/hugetlbpage.c +1 -1
@@ -933,7 +933,7 @@ static int __init hugetlbpage_init(void) return 0; }#endif -module_init (hugetlbpage_init); +arch_initcall (hugetlbpage_init);void flush_dcache_icache_hugepage (struct page *page) {
Signature · 1 line
2.2.1
PATCH 9/11 mm/page_owner.c: use late_initcall to hook in enabling
In reply to Paul GortmakerThis was using module_init, but there is no way this code can be modular. In the non-modular case, a module_init becomes adevice_initcall, but this really isn't a device. So we should
choose a more appropriate initcall bucket to put it in.
In order of execution, our close choices are:
fs_initcall(fn)
rootfs_initcall(fn)
device_initcall(fn)
late_initcall(fn)
..and since the initcall here goes after debugfs, we really should be post-rootfs, which means late_initcall makes the most sense here.
--- mm/page_owner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_owner.c +1 -1
@@ -310,4 +310,4 @@ static int __init pageowner_init(void)return 0 ; } -module_init (pageowner_init) +late_initcall (pageowner_init)
Signature · 7 lines
2.2.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/11 fs/notify: don't use module_init for non-modular inotify_user code
In reply to Paul GortmakerThe INOTIFY_USER option is bool, and hence this code is either present or absent. It will never be modular, so using module_init as an alias for __initcall is rather misleading.
Fix this up now, so that we can relocate module_init from init.h into module.h in the future. If we don't do this, we'd have to add module.h to obviously non-modular code, and that would be a worse thing.
Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of fs_initcall (which makes sense for fs code) will thus change this registration from level 6-device to level 5-fs (i.e. slightly earlier). However no observable impact of that small difference has been observed during testing, or is expected.
--- fs/notify/inotify/inotify_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/notify/inotify/inotify_user.c +2 -2
@@ -26,7 +26,7 @@#include <linux/fs.h> /* struct inode */ #include <linux/fsnotify_backend.h> #include <linux/idr.h> -#include <linux/init.h> /* module_init */ +#include <linux/init.h> /* fs_initcall */ #include <linux/inotify.h> #include <linux/kernel.h> /* roundup() */ #include <linux/namei.h> /* LOOKUP_FOLLOW */
@@ -812,4 +812,4 @@ static int __init inotify_user_setup(void)return 0 ; } -module_init (inotify_user_setup); +fs_initcall (inotify_user_setup);
Signature · 1 line
2.2.1
PATCH 5/11 powerpc: use subsys_initcall for Freescale Local Bus
In reply to Paul GortmakerThe FSL_SOC option is bool, and hence this code is either present or absent. It will never be modular, so using module_init as an alias for __initcall is rather misleading.
Fix this up now, so that we can relocate module_init from init.h into module.h in the future. If we don't do this, we'd have to add module.h to obviously non-modular code, and that would be a worse thing.
Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of subsys_initcall (which makes sense for bus code) will thus change this registration from level 6-device to level 4-subsys (i.e. slightly earlier). However no observable impact of that small difference has been observed during testing, or is expected.
--- arch/powerpc/sysdev/fsl_lbc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/fsl_lbc.c +1 -1
@@ -407,4 +407,4 @@ static int __init fsl_lbc_init(void) {return platform_driver_register (&fsl_lbc_ctrl_driver); } -module_init (fsl_lbc_init); +subsys_initcall (fsl_lbc_init);
Signature · 1 line
2.2.1
PATCH 11/11 x86: perf_event_intel_pt.c: use arch_initcall to hook in enabling
In reply to Paul GortmakerThis was using module_init, but there is no way this code can be modular. In the non-modular case, a module_init becomes adevice_initcall, but this really isn't a device. So we should
choose a more appropriate initcall bucket to put it in.
The obvious choice here seems to be arch_initcall, but that does make it earlier than it was currently through device_initcall. As long as perf_pmu_register() is functional, we should be OK.
--- arch/x86/kernel/cpu/perf_event_intel_pt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_intel_pt.c +1 -2
@@ -1096,5 +1096,4 @@ static __init int pt_init(void)return ret; } - -module_init (pt_init); +arch_initcall (pt_init);
Signature · 1 line
2.2.1
PATCH 10/11 x86: perf_event_intel_bts.c: use arch_initcall to hook in enabling
In reply to Paul GortmakerThis was using module_init, but there is no way this code can be modular. In the non-modular case, a module_init becomes adevice_initcall, but this really isn't a device. So we should
choose a more appropriate initcall bucket to put it in.
The obvious choice here seems to be arch_initcall, but that does make it earlier than it was currently through device_initcall. As long as perf_pmu_register() is functional, we should be OK.
--- arch/x86/kernel/cpu/perf_event_intel_bts.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_intel_bts.c +1 -2
@@ -521,5 +521,4 @@ static __init int bts_init(void)return perf_pmu_register (&bts_pmu,"intel_bts" ,-1 ); } - -module_init (bts_init); +arch_initcall (bts_init);
Signature · 1 line
2.2.1
PATCH 8/11 lib/list_sort: use late_initcall to hook in self tests
In reply to Paul GortmakerThis was using module_init, but there is no way this code can be modular. In the non-modular case, a module_init becomes adevice_initcall, but this really isn't a device. So we should
choose a more appropriate initcall bucket to put it in.
Assuming boot time self tests need to be observed over a console to be useful, and that the console device could possibly not be fully functional until after device_initcall, we move this to the late_initcall bucket, which is immediately after device_initcall.
--- lib/list_sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/list_sort.c +1 -1
@@ -289,5 +289,5 @@ exit:kfree (elts); return err; } -module_init (list_sort_test); +late_initcall (list_sort_test);#endif /* CONFIG_TEST_LIST_SORT */
Signature · 1 line
2.2.1
PATCH 4/11 x86: don't use module_init for non-modular core bootflag code
In reply to Paul GortmakerThe bootflag.o is obj-y (always built in). It will never be modular, so using module_init as an alias for __initcall is somewhat misleading.
Fix this up now, so that we can relocate module_init from init.h into module.h in the future. If we don't do this, we'd have to add module.h to obviously non-modular code, and that would be a worse thing.
Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of arch_initcall (which makes sense for arch code) will thus change this registration from level 6-device to level 3-arch (i.e. slightly earlier). However no observable impact of that small difference has been observed during testing, or is expected.
--- arch/x86/kernel/bootflag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/bootflag.c +1 -1
@@ -98,4 +98,4 @@ static int __init sbf_init(void)return 0 ; } -module_init (sbf_init); +arch_initcall (sbf_init);
Signature · 1 line
2.2.1
Peter Zijlstra
maintainerRe: [PATCH 10/11] x86: perf_event_intel_bts.c: use arch_initcall to hook in enabling
In reply to Paul GortmakerQuoted 2 lines · Paul Gortmaker
This was using
module_init, but there is no way this code can be modular.
No, I think you could actually make it modular if you really wanted to.
Peter Zijlstra
maintainerRe: [PATCH 11/11] x86: perf_event_intel_pt.c: use arch_initcall to hook in enabling
In reply to Paul GortmakerQuoted 2 lines · Paul Gortmaker
This was using
module_init, but there is no way this code can be modular.
Same thing; you could actually make this modular if you wanted to.
Re: [PATCH 10/11] x86: perf_event_intel_bts.c: use arch_initcall to hook in enabling
In reply to Peter ZijlstraQuoted 5 lines · Peter Zijlstra
Quoted 2 lines · Paul Gortmaker
This was using
module_init, but there is no way this code can be modular.No, I think you could actually make it modular if you really wanted to.
By "really wanted to" -- do you mean future changes that someone might do?
Since currently, I can't see how this could be modular. We have...
In arch/x86/kernel/cpu/Makefile:
obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o
and in arch/x86/Kconfig.cpu:
config CPU_SUP_INTEL
default y
bool "Support Intel processors" if PROCESSOR_SELECT
...so this seems always built in to me, in the current code base.
Paul.
Re: [PATCH 11/11] x86: perf_event_intel_pt.c: use arch_initcall to hook in enabling
In reply to Peter ZijlstraQuoted 6 lines · Peter Zijlstra
Quoted 2 lines · Paul Gortmaker
This was using
module_init, but there is no way this code can be modular.Same thing; you could actually make this modular if you wanted to.
..and this file is even in the same Makefile line of the prev. one:
arch/x86/kernel/cpu/Makefile:
obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o
and in arch/x86/Kconfig.cpu:
config CPU_SUP_INTEL
default y
bool "Support Intel processors" if PROCESSOR_SELECT
...so again, unless I'm missing something obvious (entirely possible for a Monday) this too seems always built in to me.
Paul.
Peter Zijlstra
maintainerRe: [PATCH 10/11] x86: perf_event_intel_bts.c: use arch_initcall to hook in enabling
In reply to Paul GortmakerQuoted 8 lines · Paul Gortmaker
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Paul Gortmaker
This was using
module_init, but there is no way this code can be modular.No, I think you could actually make it modular if you really wanted to.
By "really wanted to" -- do you mean future changes that someone might do?
Yeah, I think we read "no way this code can be modular" differently.
I'm reading it like; it can easily be, all it requires is this little patch, where you're reading it like Kconfig changes.
Re: [PATCH 10/11] x86: perf_event_intel_bts.c: use arch_initcall to hook in enabling
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Paul Gortmaker
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Paul Gortmaker
This was using
module_init, but there is no way this code can be modular.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
No, I think you could actually make it modular if you really wanted to.
By "really wanted to" -- do you mean future changes that someone might do?
Yeah, I think we read "no way this code can be modular" differently.
I'm reading it like; it can easily be, all it requires is this little patch, where you're reading it like
Kconfigchanges.
OK, so how about I update both logs with something like this, to clarify I meant "no way this code can be modular currently, given the existing Kconfig situation":
----------------------8<---------------------------
This was using module_init, but the current Kconfig situation is as follows:
In arch/x86/kernel/cpu/Makefile:
obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o
and in arch/x86/Kconfig.cpu:
config CPU_SUP_INTEL
default y
bool "Support Intel processors" if PROCESSOR_SELECT
So currently, the end user can not build this code into a module. If in the future, there is desire for this to be modular, then it can be changed to include <linux/module.h> and use module_init.
But currently, in the non-modular case, a module_init becomes a device_initcall. But this really isn't a device, so we should choose a more appropriate initcall bucket to put it in.
The obvious choice here seems to be arch_initcall, but that does make it earlier than it was currently through device_initcall. As long as perf_pmu_register() is functional, we should be OK.
----------------------8<----------------------------------
Paul.
Quoted 2 lines
Peter Zijlstra
maintainerRe: [PATCH 10/11] x86: perf_event_intel_bts.c: use arch_initcall to hook in enabling
Quoted 3 lines · Paul Gortmaker
OK, so how about I update both logs with something like this, to clarify I meant "no way this code can be modular currently, given the existing
Kconfigsituation":
That looks good to me; thanks!
Re: [PATCH 03/11] netfilter: don't use module_init/exit in core IPV4 code
In reply to Paul GortmakerQuoted 27 lines · Paul Gortmaker
The file
net/ipv4/netfilter.ois created based on whetherCONFIG_NETFILTERis set. However that is defined as a bool, and hence this file with the core netfilter hooks will never be modular. So usingmodule_initas an alias for__initcallcan be somewhat misleading.Fix this up now, so that we can relocate
module_initfrominit.hintomodule.hin the future. If we don't do this, we'd have to addmodule.hto obviously non-modular code, and that would be a worse thing. Also add an inclusion ofinit.h, as that was previously implicit here in thenetfilter.cfile.Note that direct use of
__initcallis discouraged, vs. one of the priority categorized subgroups. As__initcallgets mapped ontodevice_initcall, our use ofsubsys_initcall(which seems to make sense for netfilter code) will thus change this registration from level 6-device to level 4-subsys (i.e. slightly earlier). However no observable impact of that small difference has been observed during testing, or is expected. (i.e. the location of the netfilter messages in dmesg remains unchanged with respect to all the other surrounding messages.)As for the
module_exit, rather than replace it with__exitcall, we simply remove it, since it appears only UML does anything with those, and even for UML, there is no relevant cleanup to be done here.
Quoted 7 lines
Cc Pablo Neira Ayuso <[email protected]>Cc Patrick McHardy <[email protected]>Cc Jozsef Kadlecsik <[email protected]>Cc "David S. Miller" <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Or I can integrate this into the nf-next tree if you prefer it.
Thanks.
Re: [PATCH 03/11] netfilter: don't use module_init/exit in core IPV4 code
Quoted 36 lines · Pablo Neira Ayuso
Quoted 27 lines · Paul Gortmaker
The file
net/ipv4/netfilter.ois created based on whetherCONFIG_NETFILTERis set. However that is defined as a bool, and hence this file with the core netfilter hooks will never be modular. So usingmodule_initas an alias for__initcallcan be somewhat misleading.Fix this up now, so that we can relocate
module_initfrominit.hintomodule.hin the future. If we don't do this, we'd have to addmodule.hto obviously non-modular code, and that would be a worse thing. Also add an inclusion ofinit.h, as that was previously implicit here in thenetfilter.cfile.Note that direct use of
__initcallis discouraged, vs. one of the priority categorized subgroups. As__initcallgets mapped ontodevice_initcall, our use ofsubsys_initcall(which seems to make sense for netfilter code) will thus change this registration from level 6-device to level 4-subsys (i.e. slightly earlier). However no observable impact of that small difference has been observed during testing, or is expected. (i.e. the location of the netfilter messages in dmesg remains unchanged with respect to all the other surrounding messages.)As for the
module_exit, rather than replace it with__exitcall, we simply remove it, since it appears only UML does anything with those, and even for UML, there is no relevant cleanup to be done here.Quoted 7 lines
Cc Pablo Neira Ayuso <[email protected]>Cc Patrick McHardy <[email protected]>Cc Jozsef Kadlecsik <[email protected]>Cc "David S. Miller" <[email protected]>Signed-off-by Paul Gortmaker <[email protected]>
Quoted 3 lines
Or I can integrate this into the nf-next tree if you prefer it.
I need to keep it in my series to avoid introducing compile fails into the bisect history, so I'll just add your Ack.
Thanks,
Paul.
--
Quoted 3 lines
Thanks.