linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	linuxppc-dev@lists.ozlabs.org
Subject: [PATCH] powerpc64/module elfv1: Set opd addresses after module relocation
Date: Tue, 29 May 2018 12:21:00 +0530	[thread overview]
Message-ID: <20180529065100.2017-1-naveen.n.rao@linux.vnet.ibm.com> (raw)

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

             reply	other threads:[~2018-05-29  6:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29  6:51 Naveen N. Rao [this message]
2018-10-22  9:34 ` powerpc64/module elfv1: Set opd addresses after module relocation Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180529065100.2017-1-naveen.n.rao@linux.vnet.ibm.com \
    --to=naveen.n.rao@linux.vnet.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=sergey.senozhatsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).