linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc64/module elfv1: Set opd addresses after module relocation
@ 2018-05-29  6:51 Naveen N. Rao
  2018-10-22  9:34 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Naveen N. Rao @ 2018-05-29  6:51 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: Sergey Senozhatsky, linuxppc-dev

module_frob_arch_sections() is called before the module is moved to its
final location. The function descriptor section addresses we are setting
here are thus invalid. Fix this by processing opd section during 
module_finalize()

Fixes: 5633e85b2c313 ("powerpc64: Add .opd based function descriptor dereference")
Cc: stable@vger.kernel.org # v4.16
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
This can easily be seen by doing:

  $ sudo perf probe -L module_frob_arch_sections | grep -A5 opd
       20  		else if (!strcmp(secstrings + sechdrs[i].sh_name, ".opd")) {
       21  			me->arch.start_opd = sechdrs[i].sh_addr;
       22  			me->arch.end_opd = sechdrs[i].sh_addr +
						     sechdrs[i].sh_size;
			  }

			  /* We don't handle .init for the moment: rename to _init */
       27  		while ((p = strstr(secstrings + sechdrs[i].sh_name, ".init")))
  $ sudo perf probe module_frob_arch_sections:27 me-\>arch.start_opd me-\>arch.end_opd
  Added new events:
    probe:module_frob_arch_sections (on module_frob_arch_sections:27 with start_opd=me->arch.start_opd end_opd=me->arch.end_opd)
    probe:module_frob_arch_sections_1 (on module_frob_arch_sections:27 with start_opd=me->arch.start_opd end_opd=me->arch.end_opd)

  You can now use it in all perf tools, such as:

	  perf record -e probe:module_frob_arch_sections_1 -aR sleep 1

  $ sudo perf record -e probe:* modprobe kprobe_example
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.011 MB perf.data (48 samples) ]
  $ sudo perf script
	  modprobe 10463 [001] 311838.332208:   probe:module_frob_arch_sections: (c000000000043b0c) start_opd=0xd000000000910750 end_opd=0xd0000000009107a0
	  modprobe 10463 [001] 311838.332209:   probe:module_frob_arch_sections: (c000000000043b0c) start_opd=0xd000000000910750 end_opd=0xd0000000009107a0
  $ sudo cat /proc/modules | grep kprobe_example
  kprobe_example 3716 0 - Live 0xd000000000970000

With this patch, probing on module_finalize() shows the expected values.


- Naveen


 arch/powerpc/kernel/module.c    | 8 ++++++++
 arch/powerpc/kernel/module_64.c | 5 -----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
index 3f7ba0f5bf29..fc9fa24cfe05 100644
--- a/arch/powerpc/kernel/module.c
+++ b/arch/powerpc/kernel/module.c
@@ -72,6 +72,14 @@ int module_finalize(const Elf_Ehdr *hdr,
 		do_feature_fixups(powerpc_firmware_features,
 				  (void *)sect->sh_addr,
 				  (void *)sect->sh_addr + sect->sh_size);
+
+#ifdef PPC64_ELF_ABI_v1
+	sect = find_section(hdr, sechdrs, ".opd");
+	if (sect != NULL) {
+		me->arch.start_opd = sect->sh_addr;
+		me->arch.end_opd = sect->sh_addr + sect->sh_size;
+	}
+#endif
 #endif
 
 	sect = find_section(hdr, sechdrs, "__lwsync_fixup");
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index f7667e2ebfcb..a45204b48d56 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -360,11 +360,6 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr,
 		else if (strcmp(secstrings+sechdrs[i].sh_name,"__versions")==0)
 			dedotify_versions((void *)hdr + sechdrs[i].sh_offset,
 					  sechdrs[i].sh_size);
-		else if (!strcmp(secstrings + sechdrs[i].sh_name, ".opd")) {
-			me->arch.start_opd = sechdrs[i].sh_addr;
-			me->arch.end_opd = sechdrs[i].sh_addr +
-					   sechdrs[i].sh_size;
-		}
 
 		/* We don't handle .init for the moment: rename to _init */
 		while ((p = strstr(secstrings + sechdrs[i].sh_name, ".init")))
-- 
2.17.0

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

* Re: powerpc64/module elfv1: Set opd addresses after module relocation
  2018-05-29  6:51 [PATCH] powerpc64/module elfv1: Set opd addresses after module relocation Naveen N. Rao
@ 2018-10-22  9:34 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2018-10-22  9:34 UTC (permalink / raw)
  To: Naveen N. Rao; +Cc: Sergey Senozhatsky, linuxppc-dev

On Tue, 2018-05-29 at 06:51:00 UTC, "Naveen N. Rao" wrote:
> module_frob_arch_sections() is called before the module is moved to its
> final location. The function descriptor section addresses we are setting
> here are thus invalid. Fix this by processing opd section during 
> module_finalize()
> 
> Fixes: 5633e85b2c313 ("powerpc64: Add .opd based function descriptor dereference")
> Cc: stable@vger.kernel.org # v4.16
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/59fe7eaf3598a89cbcd72e645b1d08

cheers

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

end of thread, other threads:[~2018-10-22  9:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-29  6:51 [PATCH] powerpc64/module elfv1: Set opd addresses after module relocation Naveen N. Rao
2018-10-22  9:34 ` Michael Ellerman

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).