linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] module: allow arch overrides for .init section names
@ 2020-05-06 15:25 Vincent Whitchurch
  2020-05-06 15:25 ` [PATCH 2/2] ARM: module: fix handling of unwind init sections Vincent Whitchurch
  2020-05-08  8:25 ` [PATCH 1/2] module: allow arch overrides for .init section names Jessica Yu
  0 siblings, 2 replies; 3+ messages in thread
From: Vincent Whitchurch @ 2020-05-06 15:25 UTC (permalink / raw)
  To: linux, jeyu; +Cc: Vincent Whitchurch, kernel, linux-kernel, linux-arm-kernel

ARM stores unwind information for .init.text in sections named
.ARM.extab.init.text and .ARM.exidx.init.text.  Since those aren't
currently recognized as init sections, they're allocated along with the
core section, and relocation fails if the core and the init section are
allocated from different regions and can't reach other.

  final section addresses:
        ...
        0x7f800000 .init.text
        ..
        0xcbb54078 .ARM.exidx.init.text
        ..

 section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 ->
 0x7f800000)

Allow architectures to override the section name so that ARM can fix
this.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 include/linux/moduleloader.h | 2 ++
 kernel/module.c              | 9 +++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
index ca92aea8a6bd..07d079085f11 100644
--- a/include/linux/moduleloader.h
+++ b/include/linux/moduleloader.h
@@ -29,6 +29,8 @@ void *module_alloc(unsigned long size);
 /* Free memory returned from module_alloc. */
 void module_memfree(void *module_region);
 
+bool module_init_section(const char *name);
+
 /* Determines if the section name is an exit section (that is only used during
  * module unloading)
  */
diff --git a/kernel/module.c b/kernel/module.c
index 33569a01d6e1..a5f2b4e1ef53 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2370,6 +2370,11 @@ static long get_offset(struct module *mod, unsigned int *size,
 	return ret;
 }
 
+bool __weak module_init_section(const char *name)
+{
+	return strstarts(name, ".init");
+}
+
 /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld
    might -- code, read-only data, read-write data, small data.  Tally
    sizes, and place the offsets into sh_entsize fields: high bit means it
@@ -2400,7 +2405,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 			if ((s->sh_flags & masks[m][0]) != masks[m][0]
 			    || (s->sh_flags & masks[m][1])
 			    || s->sh_entsize != ~0UL
-			    || strstarts(sname, ".init"))
+			    || module_init_section(sname))
 				continue;
 			s->sh_entsize = get_offset(mod, &mod->core_layout.size, s, i);
 			pr_debug("\t%s\n", sname);
@@ -2433,7 +2438,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
 			if ((s->sh_flags & masks[m][0]) != masks[m][0]
 			    || (s->sh_flags & masks[m][1])
 			    || s->sh_entsize != ~0UL
-			    || !strstarts(sname, ".init"))
+			    || !module_init_section(sname))
 				continue;
 			s->sh_entsize = (get_offset(mod, &mod->init_layout.size, s, i)
 					 | INIT_OFFSET_MASK);
-- 
2.25.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] 3+ messages in thread

* [PATCH 2/2] ARM: module: fix handling of unwind init sections
  2020-05-06 15:25 [PATCH 1/2] module: allow arch overrides for .init section names Vincent Whitchurch
@ 2020-05-06 15:25 ` Vincent Whitchurch
  2020-05-08  8:25 ` [PATCH 1/2] module: allow arch overrides for .init section names Jessica Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Whitchurch @ 2020-05-06 15:25 UTC (permalink / raw)
  To: linux, jeyu; +Cc: Vincent Whitchurch, kernel, linux-kernel, linux-arm-kernel

Unwind information for init sections is placed in .ARM.exidx.init.text
and .ARM.extab.init.text.  The module core doesn't know that these are
init sections so they are allocated along with the core sections, and if
the core and init sections get allocated in different memory regions
(which is possible with CONFIG_ARM_MODULE_PLTS=y) and they can't reach
each other, relocation fails:

  final section addresses:
  	...
  	0x7f800000 .init.text
	..
  	0xcbb54078 .ARM.exidx.init.text
	..

 section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 ->
 0x7f800000)

Fix this by informing the module core that these sections are init
sections, and by removing the init unwind tables before the module core
frees the init sections.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 arch/arm/kernel/module.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index deef17f34bd2..af0a8500a24e 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -55,6 +55,13 @@ void *module_alloc(unsigned long size)
 }
 #endif
 
+bool module_init_section(const char *name)
+{
+	return strstarts(name, ".init") ||
+		strstarts(name, ".ARM.extab.init") ||
+		strstarts(name, ".ARM.exidx.init");
+}
+
 bool module_exit_section(const char *name)
 {
 	return strstarts(name, ".exit") ||
@@ -409,8 +416,17 @@ module_arch_cleanup(struct module *mod)
 #ifdef CONFIG_ARM_UNWIND
 	int i;
 
-	for (i = 0; i < ARM_SEC_MAX; i++)
-		if (mod->arch.unwind[i])
-			unwind_table_del(mod->arch.unwind[i]);
+	for (i = 0; i < ARM_SEC_MAX; i++) {
+		unwind_table_del(mod->arch.unwind[i]);
+		mod->arch.unwind[i] = NULL;
+	}
+#endif
+}
+
+void __weak module_arch_freeing_init(struct module *mod)
+{
+#ifdef CONFIG_ARM_UNWIND
+	unwind_table_del(mod->arch.unwind[ARM_SEC_INIT]);
+	mod->arch.unwind[ARM_SEC_INIT] = NULL;
 #endif
 }
-- 
2.25.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] 3+ messages in thread

* Re: [PATCH 1/2] module: allow arch overrides for .init section names
  2020-05-06 15:25 [PATCH 1/2] module: allow arch overrides for .init section names Vincent Whitchurch
  2020-05-06 15:25 ` [PATCH 2/2] ARM: module: fix handling of unwind init sections Vincent Whitchurch
@ 2020-05-08  8:25 ` Jessica Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Jessica Yu @ 2020-05-08  8:25 UTC (permalink / raw)
  To: Vincent Whitchurch; +Cc: kernel, linux, linux-arm-kernel, linux-kernel

+++ Vincent Whitchurch [06/05/20 17:25 +0200]:
>ARM stores unwind information for .init.text in sections named
>.ARM.extab.init.text and .ARM.exidx.init.text.  Since those aren't
>currently recognized as init sections, they're allocated along with the
>core section, and relocation fails if the core and the init section are
>allocated from different regions and can't reach other.
>
>  final section addresses:
>        ...
>        0x7f800000 .init.text
>        ..
>        0xcbb54078 .ARM.exidx.init.text
>        ..
>
> section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 ->
> 0x7f800000)
>
>Allow architectures to override the section name so that ARM can fix
>this.
>
>Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
>---
> include/linux/moduleloader.h | 2 ++
> kernel/module.c              | 9 +++++++--
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
>diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
>index ca92aea8a6bd..07d079085f11 100644
>--- a/include/linux/moduleloader.h
>+++ b/include/linux/moduleloader.h
>@@ -29,6 +29,8 @@ void *module_alloc(unsigned long size);
> /* Free memory returned from module_alloc. */
> void module_memfree(void *module_region);
>
>+bool module_init_section(const char *name);
>+

Hi, I just have two small nits. Could you please add a comment on top of
module_init_section to document it? (similar to module_exit_section())

> /* Determines if the section name is an exit section (that is only used during
>  * module unloading)
>  */
>diff --git a/kernel/module.c b/kernel/module.c
>index 33569a01d6e1..a5f2b4e1ef53 100644
>--- a/kernel/module.c
>+++ b/kernel/module.c
>@@ -2370,6 +2370,11 @@ static long get_offset(struct module *mod, unsigned int *size,
> 	return ret;
> }
>
>+bool __weak module_init_section(const char *name)
>+{
>+	return strstarts(name, ".init");
>+}
>+

Could you move this next to module_exit_section()? Just trying to keep
similar functions together. Otherwise, the patch looks fine to me.

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] 3+ messages in thread

end of thread, other threads:[~2020-05-08  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-06 15:25 [PATCH 1/2] module: allow arch overrides for .init section names Vincent Whitchurch
2020-05-06 15:25 ` [PATCH 2/2] ARM: module: fix handling of unwind init sections Vincent Whitchurch
2020-05-08  8:25 ` [PATCH 1/2] module: allow arch overrides for .init section names Jessica Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).