Since, syscall wrapper is supported on powerpc with syscall entry symbols as sys_*, changes done to fix selftests like test_bpf_syscall_macro, attach_probe/auto, etc.
Saket Kumar Bhaskar (3): libbpf: Fix accessing the syscall argument on powerpc libbpf: Remove powerpc prefix from syscall function names selftests/bpf: Define SYS_PREFIX for powerpc
tools/lib/bpf/bpf_tracing.h | 9 +++++++-- tools/lib/bpf/libbpf.c | 10 ++++++++-- tools/testing/selftests/bpf/progs/bpf_misc.h | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-)
Since commit 7e92e01b7245 ("powerpc: Provide syscall wrapper"), powerpc selects ARCH_HAS_SYSCALL_WRAPPER so let's use the generic implementation of PT_REGS_SYSCALL_REGS().
Also, allow overriding PT_REGS_PARM1{_CORE}_SYSCALL for powerpc as powerpc needs orig_gpr3, similar to s390 and arm64.
Signed-off-by: Saket Kumar Bhaskar skb99@linux.ibm.com --- tools/lib/bpf/bpf_tracing.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h index a8f6cd4841b0..933e1dab6c8f 100644 --- a/tools/lib/bpf/bpf_tracing.h +++ b/tools/lib/bpf/bpf_tracing.h @@ -287,6 +287,10 @@ struct pt_regs___arm64 { * section "Function Calling Sequence") */
+struct pt_regs___powerpc { + unsigned long orig_gpr3; +} __attribute__((preserve_access_index)); + #define __PT_PARM1_REG gpr[3] #define __PT_PARM2_REG gpr[4] #define __PT_PARM3_REG gpr[5] @@ -296,8 +300,6 @@ struct pt_regs___arm64 { #define __PT_PARM7_REG gpr[9] #define __PT_PARM8_REG gpr[10]
-/* powerpc does not select ARCH_HAS_SYSCALL_WRAPPER. */ -#define PT_REGS_SYSCALL_REGS(ctx) ctx #define __PT_PARM1_SYSCALL_REG orig_gpr3 #define __PT_PARM2_SYSCALL_REG __PT_PARM2_REG #define __PT_PARM3_SYSCALL_REG __PT_PARM3_REG @@ -307,6 +309,9 @@ struct pt_regs___arm64 { #if !defined(__arch64__) #define __PT_PARM7_SYSCALL_REG __PT_PARM7_REG /* only powerpc (not powerpc64) */ #endif +#define PT_REGS_PARM1_SYSCALL(x) (((const struct pt_regs___powerpc *)(x))->orig_gpr3) +#define PT_REGS_PARM1_CORE_SYSCALL(x) \ + BPF_CORE_READ((const struct pt_regs___powerpc *)(x), __PT_PARM1_SYSCALL_REG)
#define __PT_RET_REG regs[31] #define __PT_FP_REG __unsupported__
Since commit 94746890202cf ("powerpc: Don't add __powerpc_ prefix to syscall entry points") drops _powerpc prefix to syscall entry points, even though powerpc now supports syscall wrapper, so /proc/kallsyms have symbols for syscall entry without powerpc prefix(sys_*).
For this reason, arch specific prefix for syscall functions in powerpc is dropped.
Signed-off-by: Saket Kumar Bhaskar skb99@linux.ibm.com --- tools/lib/bpf/libbpf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 219facd0e66e..3a370fa37d8a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -11110,9 +11110,7 @@ static const char *arch_specific_syscall_pfx(void) #elif defined(__riscv) return "riscv"; #elif defined(__powerpc__) - return "powerpc"; -#elif defined(__powerpc64__) - return "powerpc64"; + return ""; #else return NULL; #endif @@ -11127,7 +11125,11 @@ int probe_kern_syscall_wrapper(int token_fd) if (!ksys_pfx) return 0;
+#if defined(__powerpc__) + snprintf(syscall_name, sizeof(syscall_name), "sys_bpf"); +#else snprintf(syscall_name, sizeof(syscall_name), "__%s_sys_bpf", ksys_pfx); +#endif
if (determine_kprobe_perf_type() >= 0) { int pfd; @@ -11272,8 +11274,12 @@ struct bpf_link *bpf_program__attach_ksyscall(const struct bpf_program *prog, * compiler does not know that we have an explicit conditional * as well. */ +#if defined(__powerpc__) + snprintf(func_name, sizeof(func_name), "sys_%s", syscall_name); +#else snprintf(func_name, sizeof(func_name), "__%s_sys_%s", arch_specific_syscall_pfx() ? : "", syscall_name); +#endif } else { snprintf(func_name, sizeof(func_name), "__se_sys_%s", syscall_name); }
On Sun, Nov 3, 2024 at 9:00 PM Saket Kumar Bhaskar skb99@linux.ibm.com wrote:
Since commit 94746890202cf ("powerpc: Don't add __powerpc_ prefix to syscall entry points") drops _powerpc prefix to syscall entry points, even though powerpc now supports syscall wrapper, so /proc/kallsyms have symbols for syscall entry without powerpc prefix(sys_*).
For this reason, arch specific prefix for syscall functions in powerpc is dropped.
Signed-off-by: Saket Kumar Bhaskar skb99@linux.ibm.com
tools/lib/bpf/libbpf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 219facd0e66e..3a370fa37d8a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -11110,9 +11110,7 @@ static const char *arch_specific_syscall_pfx(void) #elif defined(__riscv) return "riscv"; #elif defined(__powerpc__)
return "powerpc";
-#elif defined(__powerpc64__)
return "powerpc64";
return "";
#else return NULL; #endif @@ -11127,7 +11125,11 @@ int probe_kern_syscall_wrapper(int token_fd) if (!ksys_pfx) return 0;
+#if defined(__powerpc__)
snprintf(syscall_name, sizeof(syscall_name), "sys_bpf");
+#else snprintf(syscall_name, sizeof(syscall_name), "__%s_sys_bpf", ksys_pfx); +#endif
The problem is that on older versions of kernel it will have this prefix, while on newer ones it won't. So to not break anything on old kernels, we'd need to do feature detection and pick whether to use prefix or not, right?
So it seems like this change needs a bit more work.
pw-bot: cr
if (determine_kprobe_perf_type() >= 0) { int pfd;
@@ -11272,8 +11274,12 @@ struct bpf_link *bpf_program__attach_ksyscall(const struct bpf_program *prog, * compiler does not know that we have an explicit conditional * as well. */ +#if defined(__powerpc__)
snprintf(func_name, sizeof(func_name), "sys_%s", syscall_name);
+#else snprintf(func_name, sizeof(func_name), "__%s_sys_%s", arch_specific_syscall_pfx() ? : "", syscall_name); +#endif } else { snprintf(func_name, sizeof(func_name), "__se_sys_%s", syscall_name); } -- 2.43.5
On Fri, Nov 08, 2024 at 10:43:54AM -0800, Andrii Nakryiko wrote:
On Sun, Nov 3, 2024 at 9:00 PM Saket Kumar Bhaskar skb99@linux.ibm.com wrote:
Since commit 94746890202cf ("powerpc: Don't add __powerpc_ prefix to syscall entry points") drops _powerpc prefix to syscall entry points, even though powerpc now supports syscall wrapper, so /proc/kallsyms have symbols for syscall entry without powerpc prefix(sys_*).
For this reason, arch specific prefix for syscall functions in powerpc is dropped.
Signed-off-by: Saket Kumar Bhaskar skb99@linux.ibm.com
tools/lib/bpf/libbpf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 219facd0e66e..3a370fa37d8a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -11110,9 +11110,7 @@ static const char *arch_specific_syscall_pfx(void) #elif defined(__riscv) return "riscv"; #elif defined(__powerpc__)
return "powerpc";
-#elif defined(__powerpc64__)
return "powerpc64";
return "";
#else return NULL; #endif @@ -11127,7 +11125,11 @@ int probe_kern_syscall_wrapper(int token_fd) if (!ksys_pfx) return 0;
+#if defined(__powerpc__)
snprintf(syscall_name, sizeof(syscall_name), "sys_bpf");
+#else snprintf(syscall_name, sizeof(syscall_name), "__%s_sys_bpf", ksys_pfx); +#endif
The problem is that on older versions of kernel it will have this prefix, while on newer ones it won't. So to not break anything on old kernels, we'd need to do feature detection and pick whether to use prefix or not, right?
So it seems like this change needs a bit more work.
pw-bot: cr
Hi Andrii,
IMO since both the patches 7e92e01b7245(powerpc: Provide syscall wrapper) and 94746890202cf(powerpc: Don't add __powerpc_ prefix to syscall entry points) went into the same kernel version v6.1-rc1, there won't me much kernel versions that has only one of these patches.
Also, to test more I tried this patch with ARCH_HAS_SYSCALL_WRAPPER disabled, and it the test passed in this case too.
Thanks, Saket
if (determine_kprobe_perf_type() >= 0) { int pfd;
@@ -11272,8 +11274,12 @@ struct bpf_link *bpf_program__attach_ksyscall(const struct bpf_program *prog, * compiler does not know that we have an explicit conditional * as well. */ +#if defined(__powerpc__)
snprintf(func_name, sizeof(func_name), "sys_%s", syscall_name);
+#else snprintf(func_name, sizeof(func_name), "__%s_sys_%s", arch_specific_syscall_pfx() ? : "", syscall_name); +#endif } else { snprintf(func_name, sizeof(func_name), "__se_sys_%s", syscall_name); } -- 2.43.5
On Wed, Nov 20, 2024 at 6:52 AM Saket Kumar Bhaskar skb99@linux.ibm.com wrote:
On Fri, Nov 08, 2024 at 10:43:54AM -0800, Andrii Nakryiko wrote:
On Sun, Nov 3, 2024 at 9:00 PM Saket Kumar Bhaskar skb99@linux.ibm.com wrote:
Since commit 94746890202cf ("powerpc: Don't add __powerpc_ prefix to syscall entry points") drops _powerpc prefix to syscall entry points, even though powerpc now supports syscall wrapper, so /proc/kallsyms have symbols for syscall entry without powerpc prefix(sys_*).
For this reason, arch specific prefix for syscall functions in powerpc is dropped.
Signed-off-by: Saket Kumar Bhaskar skb99@linux.ibm.com
tools/lib/bpf/libbpf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 219facd0e66e..3a370fa37d8a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -11110,9 +11110,7 @@ static const char *arch_specific_syscall_pfx(void) #elif defined(__riscv) return "riscv"; #elif defined(__powerpc__)
return "powerpc";
-#elif defined(__powerpc64__)
return "powerpc64";
return "";
#else return NULL; #endif @@ -11127,7 +11125,11 @@ int probe_kern_syscall_wrapper(int token_fd) if (!ksys_pfx) return 0;
+#if defined(__powerpc__)
snprintf(syscall_name, sizeof(syscall_name), "sys_bpf");
+#else snprintf(syscall_name, sizeof(syscall_name), "__%s_sys_bpf", ksys_pfx); +#endif
The problem is that on older versions of kernel it will have this prefix, while on newer ones it won't. So to not break anything on old kernels, we'd need to do feature detection and pick whether to use prefix or not, right?
So it seems like this change needs a bit more work.
pw-bot: cr
Hi Andrii,
IMO since both the patches 7e92e01b7245(powerpc: Provide syscall wrapper) and 94746890202cf(powerpc: Don't add __powerpc_ prefix to syscall entry points) went into the same kernel version v6.1-rc1, there won't me much kernel versions that has only one of these patches.
Also, to test more I tried this patch with ARCH_HAS_SYSCALL_WRAPPER disabled, and it the test passed in this case too.
Keep in mind that libbpf is supposed to work across many kernel versions. So as long as there are powerpc (old) kernels that do use arch-specific prefix, we need to detect them and supply prefix when attaching ksyscall programs.
Thanks, Saket
if (determine_kprobe_perf_type() >= 0) { int pfd;
@@ -11272,8 +11274,12 @@ struct bpf_link *bpf_program__attach_ksyscall(const struct bpf_program *prog, * compiler does not know that we have an explicit conditional * as well. */ +#if defined(__powerpc__)
snprintf(func_name, sizeof(func_name), "sys_%s", syscall_name);
+#else snprintf(func_name, sizeof(func_name), "__%s_sys_%s", arch_specific_syscall_pfx() ? : "", syscall_name); +#endif } else { snprintf(func_name, sizeof(func_name), "__se_sys_%s", syscall_name); } -- 2.43.5
SYS_PREFIX was missing for a powerpc, which made a kprobe test to sys_prctl fail.
Add missing SYS_PREFIX for powerpc.
Fixes: 7e92e01b7245 ("powerpc: Provide syscall wrapper") Fixes: 94746890202c ("powerpc: Don't add __powerpc_ prefix to syscall entry points") Signed-off-by: Saket Kumar Bhaskar skb99@linux.ibm.com --- tools/testing/selftests/bpf/progs/bpf_misc.h | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h index eccaf955e394..ae6beb2fb480 100644 --- a/tools/testing/selftests/bpf/progs/bpf_misc.h +++ b/tools/testing/selftests/bpf/progs/bpf_misc.h @@ -160,6 +160,9 @@ #elif defined(__TARGET_ARCH_riscv) #define SYSCALL_WRAPPER 1 #define SYS_PREFIX "__riscv_" +#elif defined(__TARGET_ARCH_powerpc) +#define SYSCALL_WRAPPER 1 +#define SYS_PREFIX "" #else #define SYSCALL_WRAPPER 0 #define SYS_PREFIX "__se_"
linux-kselftest-mirror@lists.linaro.org