[PATCH] powerpc64/module elfv1: Set opd addresses after module relocation
Naveen N. Rao
naveen.n.rao at linux.vnet.ibm.com
Tue May 29 16:51:00 AEST 2018
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 at vger.kernel.org # v4.16
Signed-off-by: Naveen N. Rao <naveen.n.rao at 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
More information about the Linuxppc-dev
mailing list