selftests/bpf: Fix test_attach_probe for powerpc uprobes
Subsystems (5)
Jiri Olsa
reviewerPATCH 1/1 selftests/bpf: Fix test_attach_probe for powerpc uprobes
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/attach_probe.c +17 -1
@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). +*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset) +{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];
@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" ))
Signature · 1 line
2.29.2
Quoted 17 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 9
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +5
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point).
Any documentation in the kernel about this behavior? This will help to validate the change without trying with powerpc64 qemu...
Quoted 24 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +12
-1+*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset) +{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" ))
Quoted 15 lines · Yonghong Song
Quoted 12 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Quoted 15 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 8
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +5
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). Any documentation in the kernel about this behavior? This will help to validate the change without trying with powerpc64 qemu...
we got similar fix in perf:
7b6ff0bdbf4f perf probe ppc64le: Fixup function entry if using kallsyms lookup
CC-ing few other folks from ppc land for more info
jirka
Quoted 25 lines
Quoted 24 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +12
-1+*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset) +{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" ))
Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Yonghong Song
Quoted 12 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 4
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__)
This needs to be specific to ELF v2 ABI, so you'll need to check _CALL_ELF. See commit d5c2e2c17ae1d6 ("perf probe ppc64le: Prefer symbol table lookup over DWARF") for an example.
Quoted 7 lines
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 9
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +4
-0+/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). Any documentation in the kernel about this behavior? This will help to validate the change without trying with powerpc64 qemu...
I don't think we have documented this in the kernel anywhere, but this is specific to the ELF v2 ABI and is described there:
- 2.3.2.1. Function Prologue:
http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240___RefHeading___Toc377640597.html
- 3.4.1. Symbol Values:
http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655241_95185.html
Quoted 6 lines
we got similar fix in perf:
7b6ff0bdbf4fperf probe ppc64le: Fixup function entry if using kallsyms lookupCC-ing few other folks from ppc land for more info
Thanks.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +11
-0+*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset) +{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c void test_attach_probe(void)
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1
-1if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" ))
As documented in the links above, the right way to identify local entry point (LEP) is by looking at the symbol table. Falling back to using a hardcoded offset of 8 is a reasonable workaround if we don't have access to the symbol table.
- Naveen
Quoted 17 lines · Naveen N. Rao
Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Yonghong Song
Quoted 12 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 4
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__)This needs to be specific to ELF v2 ABI, so you'll need to check
_CALL_ELF. See commitd5c2e2c17ae1d6("perf probe ppc64le: Prefer symbol table lookup over DWARF") for an example.
i see, there's the outer #if _CALL_ELF I missed
Quoted 46 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 9
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +4
-0+/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). Any documentation in the kernel about this behavior? This will help to validate the change without trying with powerpc64 qemu...
I don't think we have documented this in the kernel anywhere, but this is specific to the ELF v2 ABI and is described there:
- 2.3.2.1. Function Prologue:
http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240___RefHeading___Toc377640597.html
- 3.4.1. Symbol Values:http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655241_95185.htmlQuoted 6 lines
we got similar fix in perf:
7b6ff0bdbf4fperf probe ppc64le: Fixup function entry if using kallsyms lookupCC-ing few other folks from ppc land for more info
Thanks.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +12
-1+*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset) +{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr);
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c void test_attach_probe(void)
Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" ))As documented in the links above, the right way to identify local entry point (LEP) is by looking at the symbol table. Falling back to using a hardcoded offset of 8 is a reasonable workaround if we don't have access to the symbol table.
thanks for the all the info, I'll send v2 with _CALL_ELF check
jirka
Quoted 38 lines · Naveen N. Rao
Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Yonghong Song
Quoted 12 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 4
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__)This needs to be specific to ELF v2 ABI, so you'll need to check
_CALL_ELF. See commitd5c2e2c17ae1d6("perf probe ppc64le: Prefer symbol table lookup over DWARF") for an example.Quoted 7 lines
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 9
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +4
-0+/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). Any documentation in the kernel about this behavior? This will help to validate the change without trying with powerpc64 qemu...
Quoted 6 lines
I don't think we have documented this in the kernel anywhere, but this is specific to the ELF v2 ABI and is described there:
- 2.3.2.1. Function Prologue:
http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240___RefHeading___Toc377640597.html
- 3.4.1. Symbol Values:http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655241_95185.html
There's a comment in ppc_function_entry(), but I don't think we have any actual "documentation".
static inline unsigned long ppc_function_entry(void *func) {
#ifdef PPC64_ELF_ABI_v2 u32 *insn = func; /* * A PPC64 ABIv2 function may have a local and a global entry * point. We need to use the local entry point when patching * functions, so identify and step over the global entry point * sequence. * * The global entry point sequence is always of the form: * * addis r2,r12,XXXX * addi r2,r2,XXXX * * A linker optimisation may convert the addis to lis: * * lis r2,XXXX * addi r2,r2,XXXX */ if ((((*insn & OP_RT_RA_MASK) == ADDIS_R2_R12) || ((*insn & OP_RT_RA_MASK) == LIS_R2)) && ((*(insn+1) & OP_RT_RA_MASK) == ADDI_R2_R2)) return (unsigned long)(insn + 2); else return (unsigned long)func;
cheers
Quoted 54 lines · Michael Ellerman
Quoted 38 lines · Naveen N. Rao
Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Yonghong Song
Quoted 12 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 4
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__)This needs to be specific to ELF v2 ABI, so you'll need to check
_CALL_ELF. See commitd5c2e2c17ae1d6("perf probe ppc64le: Prefer symbol table lookup over DWARF") for an example.Quoted 7 lines
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 9
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +4
-0+/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). Any documentation in the kernel about this behavior? This will help to validate the change without trying with powerpc64 qemu...
Quoted 6 lines
I don't think we have documented this in the kernel anywhere, but this is specific to the ELF v2 ABI and is described there:
- 2.3.2.1. Function Prologue:
http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240___RefHeading___Toc377640597.html
- 3.4.1. Symbol Values:http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655241_95185.htmlThere's a comment in
ppc_function_entry(), but I don't think we have any actual "documentation".static inline unsigned long
ppc_function_entry(void *func){
#ifdefPPC64_ELF_ABI_v2
u32 *insn = func;
Quoted 5 lines
/*
* A PPC64 ABIv2 function may have a local and a global entry
* point. We need to use the local entry point when patching
* functions, so identify and step over the global entry point
* sequence.
hm, so I need to do the instructions check below as well
Quoted 6 lines
* * The global entry point sequence is always of the form: * * addis r2,r12,XXXX * addi r2,r2,XXXX *
Quoted 8 lines
* A linker optimisation may convert the addis to lis: * * lis r2,XXXX * addi r2,r2,XXXX */ if ((((*insn & OP_RT_RA_MASK) == ADDIS_R2_R12) || ((*insn & OP_RT_RA_MASK) == LIS_R2)) && ((*(insn+1) & OP_RT_RA_MASK) == ADDI_R2_R2))
is this check/instructions specific to kernel code?
In the test prog I see following instructions:
Dump of assembler code for function get_base_addr:
0x0000000010034cb0 <+0>: lis r2,4256 0x0000000010034cb4 <+4>: addi r2,r2,31488
...
but first instruction does not match the check in kernel code above:
1.insn value: 0x3c4010a0 2.insn value: 0x38427b00
the used defines are:
#define OP_RT_RA_MASK 0xffff0000UL #define LIS_R2 0x3c020000UL #define ADDIS_R2_R12 0x3c4c0000UL #define ADDI_R2_R2 0x38420000UL
maybe we could skip the check, and run the test twice: first on kallsym address and if the uprobe is not hit we will run it again on address + 8
thanks,
jirka
Quoted 7 lines
return (unsigned long)(insn + 2); else return (unsigned long)func;cheers
Quoted 55 lines · Jiri Olsa
Quoted 54 lines · Michael Ellerman
Quoted 38 lines · Naveen N. Rao
Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Yonghong Song
Quoted 12 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 4
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" +#if defined(__powerpc64__)This needs to be specific to ELF v2 ABI, so you'll need to check
_CALL_ELF. See commitd5c2e2c17ae1d6("perf probe ppc64le: Prefer symbol table lookup over DWARF") for an example.Quoted 7 lines
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 9
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +4
-0+/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). Any documentation in the kernel about this behavior? This will help to validate the change without trying with powerpc64 qemu...
Quoted 6 lines
I don't think we have documented this in the kernel anywhere, but this is specific to the ELF v2 ABI and is described there:
- 2.3.2.1. Function Prologue:
http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240___RefHeading___Toc377640597.html
- 3.4.1. Symbol Values:http://cdn.openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655241_95185.htmlThere's a comment in
ppc_function_entry(), but I don't think we have any actual "documentation".static inline unsigned long
ppc_function_entry(void *func){#ifdef PPC64_ELF_ABI_v2 u32 *insn = func;
Quoted 7 lines
Quoted 5 lines
/*
* A PPC64 ABIv2 function may have a local and a global entry
* point. We need to use the local entry point when patching
* functions, so identify and step over the global entry point
* sequence.hm, so I need to do the instructions check below as well
It's a good check, but probably not necessary. In most functions, we expect to be able to probe two instructions later without much of a change to affect function tracing for userspace. For this reason, we just probe at an offset of 8 as a reasonable fallback.
It is definetely good if we can come up with a better approach though.
Quoted 27 lines
Quoted 15 lines
* * The global entry point sequence is always of the form: * * addis r2,r12,XXXX * addi r2,r2,XXXX * * A linker optimisation may convert the addis to lis: * * lis r2,XXXX * addi r2,r2,XXXX */ if ((((*insn & OP_RT_RA_MASK) == ADDIS_R2_R12) || ((*insn & OP_RT_RA_MASK) == LIS_R2)) && ((*(insn+1) & OP_RT_RA_MASK) == ADDI_R2_R2))is this check/instructions specific to kernel code?
In the test prog I see following instructions:
Dump of assembler code for function
get_base_addr:0x0000000010034cb0 <+0>: lis r2,4256 0x0000000010034cb4 <+4>: addi r2,r2,31488...
but first instruction does not match the check in kernel code above:
Quoted 8 lines
1.insn value: 0x3c4010a0 2.insn value: 0x38427b00the used defines are:
#define OP_RT_RA_MASK 0xffff0000UL #define LIS_R2 0x3c020000UL #define ADDIS_R2_R12 0x3c4c0000UL #define ADDI_R2_R2 0x38420000UL
Good catch! That's wrong, and I suspect we haven't noticed since kernel almost always ends up using the addis variant. I will send a fix for this.
Quoted 5 lines
maybe we could skip the check, and run the test twice: first on kallsym address and if the uprobe is not hit we will run it again on address + 8
Sure, like I mentioned, I'm fine with any approach. Offset'ing into the function by 8 is easy and generally works. Re-trying is fine too. The proper approach will requires us to consult the symbol table and check st_other field [see commit 0b3c2264ae30ed ("perf symbols: Fix kallsyms perf test on ppc64le")]
Thanks,
- Naveen
On Thu, Mar 04, 2021 at 07:04:59AM +0530, Naveen N. Rao wrote:
SNIP
Quoted 56 lines
Quoted 5 lines
Quoted 5 lines
static inline unsigned long
ppc_function_entry(void *func){#ifdef PPC64_ELF_ABI_v2 u32 *insn = func;Quoted 7 lines
Quoted 5 lines
/*
* A PPC64 ABIv2 function may have a local and a global entry
* point. We need to use the local entry point when patching
* functions, so identify and step over the global entry point
* sequence.hm, so I need to do the instructions check below as well
It's a good check, but probably not necessary. In most functions, we expect to be able to probe two instructions later without much of a change to affect function tracing for userspace. For this reason, we just probe at an offset of 8 as a reasonable fallback.
It is definetely good if we can come up with a better approach though.
Quoted 27 lines
Quoted 15 lines
* * The global entry point sequence is always of the form: * * addis r2,r12,XXXX * addi r2,r2,XXXX * * A linker optimisation may convert the addis to lis: * * lis r2,XXXX * addi r2,r2,XXXX */ if ((((*insn & OP_RT_RA_MASK) == ADDIS_R2_R12) || ((*insn & OP_RT_RA_MASK) == LIS_R2)) && ((*(insn+1) & OP_RT_RA_MASK) == ADDI_R2_R2))is this check/instructions specific to kernel code?
In the test prog I see following instructions:
Dump of assembler code for function
get_base_addr:0x0000000010034cb0 <+0>: lis r2,4256 0x0000000010034cb4 <+4>: addi r2,r2,31488...
but first instruction does not match the check in kernel code above:
Quoted 8 lines
1.insn value: 0x3c4010a0 2.insn value: 0x38427b00the used defines are:
#define OP_RT_RA_MASK 0xffff0000UL #define LIS_R2 0x3c020000UL #define ADDIS_R2_R12 0x3c4c0000UL #define ADDI_R2_R2 0x38420000UL
Quoted 3 lines
Good catch! That's wrong, and I suspect we haven't noticed since kernel almost always ends up using the addis variant. I will send a fix for this.
the new macro value from your fix works for the test, so I'll use it in v2, so we don't just blindly go to +8 offset.. I'll send it out shortly
Quoted 7 lines
Quoted 6 lines
maybe we could skip the check, and run the test twice: first on kallsym address and if the uprobe is not hit we will run it again on address + 8
Quoted 5 lines
Sure, like I mentioned, I'm fine with any approach. Offset'ing into the function by 8 is easy and generally works. Re-trying is fine too. The proper approach will requires us to consult the symbol table and check
st_otherfield [see commit0b3c2264ae30ed("perf symbols: Fix kallsyms perf test on ppc64le")]
I think we don't want to complicate this test with symbol table check. I'll propose the fix with the extra instructions check for now and we can add symbol table check in future if it's not enough
thanks for all the info,
jirka
Quoted 4 lines
Thanks,
- Naveen
Quoted 20 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h"
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 13
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +9
-0+#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). +*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset)
if we mark this function __weak global, would it work as is? Would it get an address of a global entry point? I know nothing about this GEP vs LEP stuff, interesting :)
Quoted 22 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +8
-2+{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" )) --2.29.2
Quoted 22 lines · Andrii Nakryiko
Quoted 21 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h"
Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 13
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +9
-0+#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). +*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset)if we mark this function
__weakglobal, would it work as is? Would it get an address of a global entry point? I know nothing about this GEP vs LEP stuff, interesting :)
you mean get_base_addr? it's already global
all the calls to get_base_addr within the object are made to get_base_addr+0x8
00000000100350c0 <test_attach_probe>:
...
100350e0: 59 fd ff 4b bl 10034e38 <get_base_addr+0x8>
...
100358a8: 91 f5 ff 4b bl 10034e38 <get_base_addr+0x8>I'm following perf fix we had for similar issue:
7b6ff0bdbf4f perf probe ppc64le: Fixup function entry if using kallsyms lookup
I'll get more info on that
jirka
Quoted 24 lines
Quoted 23 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +8
-2+{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" )) --2.29.2
Quoted 49 lines · Jiri Olsa
Quoted 22 lines · Andrii Nakryiko
Quoted 21 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 13
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +9
-0+#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). +*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset)if we mark this function
__weakglobal, would it work as is? Would it get an address of a global entry point? I know nothing about this GEP vs LEP stuff, interesting :)you mean
get_base_addr? it's already globalall the calls to
get_base_addrwithin the object are made toget_base_addr+0x8
00000000100350c0<test_attach_probe>:... 100350e0: 59 fd ff 4b bl 10034e38 <get_base_addr+0x8> ... 100358a8: 91 f5 ff 4b bl 10034e38 <get_base_addr+0x8>
Quoted 4 lines
I'm following perf fix we had for similar issue:
7b6ff0bdbf4fperf probe ppc64le: Fixup function entry if using kallsyms lookupI'll get more info on that
Thanks. The patch
7b6ff0bdbf4f perf probe ppc64le: Fixup function entry if using
kallsyms lookup
talked about offset + 8 for kernel symbols.
I guess uprobe symbol might be in the same situation if using the same compilation mechanism as kernel. But it would be good to get confirmation from ppc people.
Quoted 28 lines
jirka
Quoted 24 lines
Quoted 23 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +8
-2+{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" )) --2.29.2
Quoted 57 lines · Yonghong Song
Quoted 49 lines · Jiri Olsa
Quoted 22 lines · Andrii Nakryiko
Quoted 21 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 13
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +9
-0+#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). +*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset)if we mark this function
__weakglobal, would it work as is? Would it get an address of a global entry point? I know nothing about this GEP vs LEP stuff, interesting :)you mean
get_base_addr? it's already globalall the calls to
get_base_addrwithin the object are made toget_base_addr+0x8
00000000100350c0<test_attach_probe>:... 100350e0: 59 fd ff 4b bl 10034e38 <get_base_addr+0x8> ... 100358a8: 91 f5 ff 4b bl 10034e38 <get_base_addr+0x8>Quoted 4 lines
I'm following perf fix we had for similar issue:
7b6ff0bdbf4fperf probe ppc64le: Fixup function entry if using kallsyms lookupI'll get more info on that
Quoted 7 lines
Thanks. The patch
7b6ff0bdbf4fperf probe ppc64le: Fixup function entry if using kallsyms
lookup
talked about offset + 8 for kernel symbols.
I guess uprobe symbol might be in the same situation if using the same compilation mechanism as kernel. But it would be good
to get confirmation from ppc people.
Yes, this is part of the ELF V2 ABI, so it applies to both kernel and userspace.
- Naveen
Quoted 50 lines · Jiri Olsa
Quoted 22 lines · Andrii Nakryiko
Quoted 21 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 13
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +9
-0+#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). +*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset)if we mark this function
__weakglobal, would it work as is? Would it get an address of a global entry point? I know nothing about this GEP vs LEP stuff, interesting :)you mean
get_base_addr? it's already globalall the calls to
get_base_addrwithin the object are made toget_base_addr+0x8
00000000100350c0<test_attach_probe>:... 100350e0: 59 fd ff 4b bl 10034e38 <get_base_addr+0x8> ... 100358a8: 91 f5 ff 4b bl 10034e38 <get_base_addr+0x8>
Quoted 4 lines
I'm following perf fix we had for similar issue:
7b6ff0bdbf4fperf probe ppc64le: Fixup function entry if using kallsyms lookupI'll get more info on that
My thinking was that if you mark the function as __weak, then the compiler is not allowed to assume that the actual implementation of that function will come from the same object (because it might be replaced by the linker later), so it has to be pessimistic and use global entry, no? Totally theoritizing here, of course.
Quoted 28 lines
jirka
Quoted 24 lines
Quoted 23 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +8
-2+{ +return offset +LEP_OFFSET ; +} +#else +#define get_offset (offset) (offset) +#endif +ssize_t get_base_addr () {size_t start, offset;char buf[256 ];@@ -36,7 +52,7 @@ void test_attach_probe(void)if (CHECK (base_addr <0 ,"get_base_addr" ,"failed to find base addr: %zd" , base_addr))return ; - uprobe_offset = (size_t )&get_base_addr - base_addr; + uprobe_offset =get_offset ((size_t )&get_base_addr - base_addr); skel =test_attach_probe__open_and_load ();if (CHECK (!skel,"skel_open" ,"failed to open skeleton\n" )) --2.29.2
Quoted 54 lines · Andrii Nakryiko
Quoted 53 lines · Jiri Olsa
Quoted 22 lines · Andrii Nakryiko
Quoted 21 lines · Jiri Olsa
When testing uprobes we the test gets GEP (Global Entry Point) address from kallsyms, but then the function is called locally so the uprobe is not triggered.
Fixing this by adjusting the address to LEP (Local Entry Point) for powerpc arch.
Signed-off-by Jiri Olsa <[email protected]>--- .../selftests/bpf/prog_tests/attach_probe.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/attach_probe.c +0
-0@@ -2,6 +2,22 @@#include <test_progs.h> #include "test_attach_probe.skel.h" Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c line 13
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +9
-0+#if defined(__powerpc64__) +/* +* We get the GEP (Global Entry Point) address from kallsyms, +* but then the function is called locally, so we need to adjust +* the address to get LEP (Local Entry Point). +*/ +#define LEP_OFFSET 8 + +static ssize_t get_offset (ssize_t offset)if we mark this function
__weakglobal, would it work as is? Would it get an address of a global entry point? I know nothing about this GEP vs LEP stuff, interesting :)you mean
get_base_addr? it's already globalall the calls to
get_base_addrwithin the object are made toget_base_addr+0x8
00000000100350c0<test_attach_probe>:... 100350e0: 59 fd ff 4b bl 10034e38 <get_base_addr+0x8> ... 100358a8: 91 f5 ff 4b bl 10034e38 <get_base_addr+0x8>I'm following perf fix we had for similar issue:
7b6ff0bdbf4fperf probe ppc64le: Fixup function entry if using kallsyms lookup
Quoted 7 lines
Quoted 1 line
I'll get more info on that
My thinking was that if you mark the function as
__weak, then the compiler is not allowed to assume that the actual implementation of that function will come from the same object (because it might be replaced by the linker later), so it has to be pessimistic and use global entry, no? Totally theoritizing here, of course.
ah ok.. good idea, but it's still jumping to +8 in my test
# nm test_progs | grep get_base_addr
0000000010034e30 W get_base_addr100350e0: 59 fd ff 4b bl 10034e38 <get_base_addr+0x8>
looks like it's linker, because compiler leaves just jump to next instruction
jirka