All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
@ 2021-05-07 12:13 ` Jessica Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Jessica Yu @ 2021-05-07 12:13 UTC (permalink / raw)
  To: Russell King; +Cc: Peter Zijlstra, linux-arm-kernel, linux-kernel, Jessica Yu

Dynamic code patching (alternatives, jump_label and static_call) can
have sites in __exit code, even if __exit is never executed. Therefore
__exit must be present at runtime, at least for as long as __init code is.

Additionally, for jump_label and static_call, the __exit sites must also
identify as within_module_init(), such that the infrastructure is aware
to never touch them after module init -- alternatives are only ran once
at init and hence don't have this particular constraint.

Previously, the module loader never loaded the exit sections in the first
place when CONFIG_MODULE_UNLOAD=n. Commit 33121347fb1c ("module: treat exit
sections the same as init sections when !CONFIG_MODULE_UNLOAD") addressed
the issue by having the module loader load the exit sections and then making
__exit identify as __init for !MODULE_UNLOAD. Then, since they are treated
like init sections, they will be also discarded after init.

That commit satisfied the above requirements for jump_labels and
static_calls by modifying the checks in the core module_init_section()
function in kernel/module.c to include exit sections. However, ARM
overrides these and implements their own module_{init,exit}_section()
functions. Add a similar check for exit sections to ARM's
module_init_section() function so that all arches are on the same page.

Fixes: 33121347fb1c ("module: treat exit sections the same as init
sections when !CONFIG_MODULE_UNLOAD")
Link: https://lore.kernel.org/lkml/YFiuphGw0RKehWsQ@gunter/
Link: https://lore.kernel.org/r/20210323142756.11443-1-jeyu@kernel.org
Signed-off-by: Jessica Yu <jeyu@kernel.org>
---
 arch/arm/kernel/module.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index beac45e89ba6..9d403fc1893b 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -56,9 +56,16 @@ void *module_alloc(unsigned long size)
 
 bool module_init_section(const char *name)
 {
+#ifndef CONFIG_MODULE_UNLOAD
+	return strstarts(name, ".init") ||
+		strstarts(name, ".ARM.extab.init") ||
+		strstarts(name, ".ARM.exidx.init") ||
+		module_exit_section(name);
+#else
 	return strstarts(name, ".init") ||
 		strstarts(name, ".ARM.extab.init") ||
 		strstarts(name, ".ARM.exidx.init");
+#endif
 }
 
 bool module_exit_section(const char *name)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] ARM: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
@ 2021-05-07 12:13 ` Jessica Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Jessica Yu @ 2021-05-07 12:13 UTC (permalink / raw)
  To: Russell King; +Cc: Peter Zijlstra, linux-arm-kernel, linux-kernel, Jessica Yu

Dynamic code patching (alternatives, jump_label and static_call) can
have sites in __exit code, even if __exit is never executed. Therefore
__exit must be present at runtime, at least for as long as __init code is.

Additionally, for jump_label and static_call, the __exit sites must also
identify as within_module_init(), such that the infrastructure is aware
to never touch them after module init -- alternatives are only ran once
at init and hence don't have this particular constraint.

Previously, the module loader never loaded the exit sections in the first
place when CONFIG_MODULE_UNLOAD=n. Commit 33121347fb1c ("module: treat exit
sections the same as init sections when !CONFIG_MODULE_UNLOAD") addressed
the issue by having the module loader load the exit sections and then making
__exit identify as __init for !MODULE_UNLOAD. Then, since they are treated
like init sections, they will be also discarded after init.

That commit satisfied the above requirements for jump_labels and
static_calls by modifying the checks in the core module_init_section()
function in kernel/module.c to include exit sections. However, ARM
overrides these and implements their own module_{init,exit}_section()
functions. Add a similar check for exit sections to ARM's
module_init_section() function so that all arches are on the same page.

Fixes: 33121347fb1c ("module: treat exit sections the same as init
sections when !CONFIG_MODULE_UNLOAD")
Link: https://lore.kernel.org/lkml/YFiuphGw0RKehWsQ@gunter/
Link: https://lore.kernel.org/r/20210323142756.11443-1-jeyu@kernel.org
Signed-off-by: Jessica Yu <jeyu@kernel.org>
---
 arch/arm/kernel/module.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index beac45e89ba6..9d403fc1893b 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -56,9 +56,16 @@ void *module_alloc(unsigned long size)
 
 bool module_init_section(const char *name)
 {
+#ifndef CONFIG_MODULE_UNLOAD
+	return strstarts(name, ".init") ||
+		strstarts(name, ".ARM.extab.init") ||
+		strstarts(name, ".ARM.exidx.init") ||
+		module_exit_section(name);
+#else
 	return strstarts(name, ".init") ||
 		strstarts(name, ".ARM.extab.init") ||
 		strstarts(name, ".ARM.exidx.init");
+#endif
 }
 
 bool module_exit_section(const char *name)
-- 
2.31.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
  2021-05-07 12:13 ` Jessica Yu
@ 2021-05-07 12:30   ` Russell King - ARM Linux admin
  -1 siblings, 0 replies; 6+ messages in thread
From: Russell King - ARM Linux admin @ 2021-05-07 12:30 UTC (permalink / raw)
  To: Jessica Yu; +Cc: Peter Zijlstra, linux-arm-kernel, linux-kernel

On Fri, May 07, 2021 at 02:13:22PM +0200, Jessica Yu wrote:
> Dynamic code patching (alternatives, jump_label and static_call) can
> have sites in __exit code, even if __exit is never executed. Therefore
> __exit must be present at runtime, at least for as long as __init code is.
...
> Previously, the module loader never loaded the exit sections in the first
> place when CONFIG_MODULE_UNLOAD=n. Commit 33121347fb1c ("module: treat exit
> sections the same as init sections when !CONFIG_MODULE_UNLOAD") addressed
> the issue by having the module loader load the exit sections and then making
> __exit identify as __init for !MODULE_UNLOAD. Then, since they are treated
> like init sections, they will be also discarded after init.
> 
> That commit satisfied the above requirements for jump_labels and
> static_calls by modifying the checks in the core module_init_section()
> function in kernel/module.c to include exit sections. However, ARM
> overrides these and implements their own module_{init,exit}_section()
> functions. Add a similar check for exit sections to ARM's
> module_init_section() function so that all arches are on the same page.

Shouldn't the module core code itself be doing:

	module_init_section(name) || module_exit_section(name)

itself when CONFIG_MODULE_UNLOAD is not set, rather than pushing this
logic down into every module_init_section() implementation?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
@ 2021-05-07 12:30   ` Russell King - ARM Linux admin
  0 siblings, 0 replies; 6+ messages in thread
From: Russell King - ARM Linux admin @ 2021-05-07 12:30 UTC (permalink / raw)
  To: Jessica Yu; +Cc: Peter Zijlstra, linux-arm-kernel, linux-kernel

On Fri, May 07, 2021 at 02:13:22PM +0200, Jessica Yu wrote:
> Dynamic code patching (alternatives, jump_label and static_call) can
> have sites in __exit code, even if __exit is never executed. Therefore
> __exit must be present at runtime, at least for as long as __init code is.
...
> Previously, the module loader never loaded the exit sections in the first
> place when CONFIG_MODULE_UNLOAD=n. Commit 33121347fb1c ("module: treat exit
> sections the same as init sections when !CONFIG_MODULE_UNLOAD") addressed
> the issue by having the module loader load the exit sections and then making
> __exit identify as __init for !MODULE_UNLOAD. Then, since they are treated
> like init sections, they will be also discarded after init.
> 
> That commit satisfied the above requirements for jump_labels and
> static_calls by modifying the checks in the core module_init_section()
> function in kernel/module.c to include exit sections. However, ARM
> overrides these and implements their own module_{init,exit}_section()
> functions. Add a similar check for exit sections to ARM's
> module_init_section() function so that all arches are on the same page.

Shouldn't the module core code itself be doing:

	module_init_section(name) || module_exit_section(name)

itself when CONFIG_MODULE_UNLOAD is not set, rather than pushing this
logic down into every module_init_section() implementation?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
  2021-05-07 12:30   ` Russell King - ARM Linux admin
@ 2021-05-07 12:48     ` Jessica Yu
  -1 siblings, 0 replies; 6+ messages in thread
From: Jessica Yu @ 2021-05-07 12:48 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: Peter Zijlstra, linux-arm-kernel, linux-kernel

+++ Russell King - ARM Linux admin [07/05/21 13:30 +0100]:
>On Fri, May 07, 2021 at 02:13:22PM +0200, Jessica Yu wrote:
>> Dynamic code patching (alternatives, jump_label and static_call) can
>> have sites in __exit code, even if __exit is never executed. Therefore
>> __exit must be present at runtime, at least for as long as __init code is.
>...
>> Previously, the module loader never loaded the exit sections in the first
>> place when CONFIG_MODULE_UNLOAD=n. Commit 33121347fb1c ("module: treat exit
>> sections the same as init sections when !CONFIG_MODULE_UNLOAD") addressed
>> the issue by having the module loader load the exit sections and then making
>> __exit identify as __init for !MODULE_UNLOAD. Then, since they are treated
>> like init sections, they will be also discarded after init.
>>
>> That commit satisfied the above requirements for jump_labels and
>> static_calls by modifying the checks in the core module_init_section()
>> function in kernel/module.c to include exit sections. However, ARM
>> overrides these and implements their own module_{init,exit}_section()
>> functions. Add a similar check for exit sections to ARM's
>> module_init_section() function so that all arches are on the same page.
>
>Shouldn't the module core code itself be doing:
>
>	module_init_section(name) || module_exit_section(name)
>
>itself when CONFIG_MODULE_UNLOAD is not set, rather than pushing this
>logic down into every module_init_section() implementation?

Yeah, that sounds better. Originally, I had wanted to keep the #ifndef
in one place to keep the churn to a minimum.

But seeing that we have to patch up ARM too, it's probably the less
ugly option now. Let me cook up an alternative patch and resend.

Thanks,

Jessica

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
@ 2021-05-07 12:48     ` Jessica Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Jessica Yu @ 2021-05-07 12:48 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: Peter Zijlstra, linux-arm-kernel, linux-kernel

+++ Russell King - ARM Linux admin [07/05/21 13:30 +0100]:
>On Fri, May 07, 2021 at 02:13:22PM +0200, Jessica Yu wrote:
>> Dynamic code patching (alternatives, jump_label and static_call) can
>> have sites in __exit code, even if __exit is never executed. Therefore
>> __exit must be present at runtime, at least for as long as __init code is.
>...
>> Previously, the module loader never loaded the exit sections in the first
>> place when CONFIG_MODULE_UNLOAD=n. Commit 33121347fb1c ("module: treat exit
>> sections the same as init sections when !CONFIG_MODULE_UNLOAD") addressed
>> the issue by having the module loader load the exit sections and then making
>> __exit identify as __init for !MODULE_UNLOAD. Then, since they are treated
>> like init sections, they will be also discarded after init.
>>
>> That commit satisfied the above requirements for jump_labels and
>> static_calls by modifying the checks in the core module_init_section()
>> function in kernel/module.c to include exit sections. However, ARM
>> overrides these and implements their own module_{init,exit}_section()
>> functions. Add a similar check for exit sections to ARM's
>> module_init_section() function so that all arches are on the same page.
>
>Shouldn't the module core code itself be doing:
>
>	module_init_section(name) || module_exit_section(name)
>
>itself when CONFIG_MODULE_UNLOAD is not set, rather than pushing this
>logic down into every module_init_section() implementation?

Yeah, that sounds better. Originally, I had wanted to keep the #ifndef
in one place to keep the churn to a minimum.

But seeing that we have to patch up ARM too, it's probably the less
ugly option now. Let me cook up an alternative patch and resend.

Thanks,

Jessica

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-07 12:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 12:13 [PATCH] ARM: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD Jessica Yu
2021-05-07 12:13 ` Jessica Yu
2021-05-07 12:30 ` Russell King - ARM Linux admin
2021-05-07 12:30   ` Russell King - ARM Linux admin
2021-05-07 12:48   ` Jessica Yu
2021-05-07 12:48     ` Jessica Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.