diff mbox series

[2/3] libbpf: Remove powerpc prefix from syscall function names

Message ID 20241104050007.13812-3-skb99@linux.ibm.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series Fix test_bpf_syscall_macro selftest on powerpc | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-7 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-10 success Logs for x86_64-gcc / build-release

Commit Message

Saket Kumar Bhaskar Nov. 4, 2024, 5 a.m. UTC
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(-)

Comments

Andrii Nakryiko Nov. 8, 2024, 6:43 p.m. UTC | #1
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
>
Saket Kumar Bhaskar Nov. 20, 2024, 2:52 p.m. UTC | #2
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
> >
Andrii Nakryiko Nov. 22, 2024, midnight UTC | #3
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
> > >
diff mbox series

Patch

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);
 	}