2023-02-24 10:38:39

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH bpf-next v2 0/3] Fix some build errors for bpf selftest on LoongArch

v2: Modify patch #3 to avoid breaking user_ringbuf test on x86

Tiezhu Yang (3):
libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for
LoongArch
selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf for
LoongArch
selftests/bpf: Use __NR_prlimit64 instead of __NR_getrlimit in
user_ringbuf test

tools/include/uapi/asm/bitsperlong.h | 2 +-
tools/lib/bpf/bpf_tracing.h | 2 ++
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 +-
tools/testing/selftests/bpf/progs/user_ringbuf_success.c | 2 +-
4 files changed, 5 insertions(+), 3 deletions(-)

--
2.1.0



2023-02-24 10:38:47

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH bpf-next v2 1/3] libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for LoongArch

LoongArch provides struct user_pt_regs instead of struct pt_regs
to userspace, use struct user_pt_regs to define __PT_REGS_CAST()
to fix the following build error:

CLNG-BPF [test_maps] loop1.bpf.o
progs/loop1.c:22:9: error: incomplete definition of type 'struct pt_regs'
m = PT_REGS_RC(ctx);
^~~~~~~~~~~~~~~
tools/testing/selftests/bpf/tools/include/bpf/bpf_tracing.h:493:41: note: expanded from macro 'PT_REGS_RC'
#define PT_REGS_RC(x) (__PT_REGS_CAST(x)->__PT_RC_REG)
~~~~~~~~~~~~~~~~~^
tools/testing/selftests/bpf/tools/include/bpf/bpf_helper_defs.h:20:8: note: forward declaration of 'struct pt_regs'
struct pt_regs;
^
1 error generated.
make: *** [Makefile:572: tools/testing/selftests/bpf/loop1.bpf.o] Error 1
make: Leaving directory 'tools/testing/selftests/bpf'

Signed-off-by: Tiezhu Yang <[email protected]>
---
tools/lib/bpf/bpf_tracing.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
index 6db88f4..137b13d 100644
--- a/tools/lib/bpf/bpf_tracing.h
+++ b/tools/lib/bpf/bpf_tracing.h
@@ -415,6 +415,8 @@ struct pt_regs___arm64 {
* https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
*/

+/* loongarch provides struct user_pt_regs instead of struct pt_regs to userspace */
+#define __PT_REGS_CAST(x) ((const struct user_pt_regs *)(x))
#define __PT_PARM1_REG regs[4]
#define __PT_PARM2_REG regs[5]
#define __PT_PARM3_REG regs[6]
--
2.1.0


2023-02-24 10:38:49

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH bpf-next v2 2/3] selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf for LoongArch

If target is bpf, there is no __loongarch__ definition, __BITS_PER_LONG
defaults to 32, __NR_nanosleep is not defined:

#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
#define __NR_nanosleep 101
__SC_3264(__NR_nanosleep, sys_nanosleep_time32, sys_nanosleep)
#endif

Check __TARGET_ARCH_loongarch to include arch specified bitsperlong.h,
then __BITS_PER_LONG is 64, __NR_nanosleep can also be defined to fix
the following build errors:

clang -g -Werror -D__TARGET_ARCH_loongarch ... -target bpf -c progs/test_vmlinux.c ...
progs/test_vmlinux.c:24:18: error: use of undeclared identifier '__NR_nanosleep'
if (args->id != __NR_nanosleep)
^
progs/test_vmlinux.c:42:12: error: use of undeclared identifier '__NR_nanosleep'
if (id != __NR_nanosleep)
^
progs/test_vmlinux.c:60:12: error: use of undeclared identifier '__NR_nanosleep'
if (id != __NR_nanosleep)
^
3 errors generated.
make: *** [Makefile:572: tools/testing/selftests/bpf/test_vmlinux.bpf.o] Error 1
make: Leaving directory 'tools/testing/selftests/bpf'

Signed-off-by: Tiezhu Yang <[email protected]>
---
tools/include/uapi/asm/bitsperlong.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/include/uapi/asm/bitsperlong.h b/tools/include/uapi/asm/bitsperlong.h
index da52065..10b4023 100644
--- a/tools/include/uapi/asm/bitsperlong.h
+++ b/tools/include/uapi/asm/bitsperlong.h
@@ -17,7 +17,7 @@
#include "../../../arch/riscv/include/uapi/asm/bitsperlong.h"
#elif defined(__alpha__)
#include "../../../arch/alpha/include/uapi/asm/bitsperlong.h"
-#elif defined(__loongarch__)
+#elif defined(__loongarch__) || defined(__TARGET_ARCH_loongarch)
#include "../../../arch/loongarch/include/uapi/asm/bitsperlong.h"
#else
#include <asm-generic/bitsperlong.h>
--
2.1.0


2023-02-24 10:38:54

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH bpf-next v2 3/3] selftests/bpf: Use __NR_prlimit64 instead of __NR_getrlimit in user_ringbuf test

After commit 80d7da1cac62 ("asm-generic: Drop getrlimit and setrlimit
syscalls from default list"), new architectures won't need to include
getrlimit and setrlimit, they are superseded with prlimit64.

In order to maintain compatibility for the new architectures, such as
LoongArch which does not define __NR_getrlimit, it is better to use
__NR_prlimit64 instead of __NR_getrlimit in user_ringbuf test to fix
the following build error:

TEST-OBJ [test_progs] user_ringbuf.test.o
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c: In function 'kick_kernel_cb':
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c:593:17: error: '__NR_getrlimit' undeclared (first use in this function)
593 | syscall(__NR_getrlimit);
| ^~~~~~~~~~~~~~
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c:593:17: note: each undeclared identifier is reported only once for each function it appears in
make: *** [Makefile:573: tools/testing/selftests/bpf/user_ringbuf.test.o] Error 1
make: Leaving directory 'tools/testing/selftests/bpf'

Signed-off-by: Tiezhu Yang <[email protected]>
---
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 +-
tools/testing/selftests/bpf/progs/user_ringbuf_success.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
index 3a13e10..e51721d 100644
--- a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
@@ -590,7 +590,7 @@ static void *kick_kernel_cb(void *arg)
/* Kick the kernel, causing it to drain the ring buffer and then wake
* up the test thread waiting on epoll.
*/
- syscall(__NR_getrlimit);
+ syscall(__NR_prlimit64);

return NULL;
}
diff --git a/tools/testing/selftests/bpf/progs/user_ringbuf_success.c b/tools/testing/selftests/bpf/progs/user_ringbuf_success.c
index b39093d..0ade111 100644
--- a/tools/testing/selftests/bpf/progs/user_ringbuf_success.c
+++ b/tools/testing/selftests/bpf/progs/user_ringbuf_success.c
@@ -202,7 +202,7 @@ do_nothing_cb(struct bpf_dynptr *dynptr, void *context)
return 0;
}

-SEC("fentry/" SYS_PREFIX "sys_getrlimit")
+SEC("fentry/" SYS_PREFIX "sys_prlimit64")
int test_user_ringbuf_epoll(void *ctx)
{
long num_samples;
--
2.1.0


2023-02-27 17:42:13

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 2/3] selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf for LoongArch

On Fri, Feb 24, 2023 at 2:37 AM Tiezhu Yang <[email protected]> wrote:
>
> If target is bpf, there is no __loongarch__ definition, __BITS_PER_LONG
> defaults to 32, __NR_nanosleep is not defined:
>
> #if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
> #define __NR_nanosleep 101
> __SC_3264(__NR_nanosleep, sys_nanosleep_time32, sys_nanosleep)
> #endif
>
> Check __TARGET_ARCH_loongarch to include arch specified bitsperlong.h,
> then __BITS_PER_LONG is 64, __NR_nanosleep can also be defined to fix
> the following build errors:
>
> clang -g -Werror -D__TARGET_ARCH_loongarch ... -target bpf -c progs/test_vmlinux.c ...
> progs/test_vmlinux.c:24:18: error: use of undeclared identifier '__NR_nanosleep'
> if (args->id != __NR_nanosleep)
> ^
> progs/test_vmlinux.c:42:12: error: use of undeclared identifier '__NR_nanosleep'
> if (id != __NR_nanosleep)
> ^
> progs/test_vmlinux.c:60:12: error: use of undeclared identifier '__NR_nanosleep'
> if (id != __NR_nanosleep)
> ^
> 3 errors generated.
> make: *** [Makefile:572: tools/testing/selftests/bpf/test_vmlinux.bpf.o] Error 1
> make: Leaving directory 'tools/testing/selftests/bpf'
>
> Signed-off-by: Tiezhu Yang <[email protected]>
> ---
> tools/include/uapi/asm/bitsperlong.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/include/uapi/asm/bitsperlong.h b/tools/include/uapi/asm/bitsperlong.h
> index da52065..10b4023 100644
> --- a/tools/include/uapi/asm/bitsperlong.h
> +++ b/tools/include/uapi/asm/bitsperlong.h
> @@ -17,7 +17,7 @@
> #include "../../../arch/riscv/include/uapi/asm/bitsperlong.h"
> #elif defined(__alpha__)
> #include "../../../arch/alpha/include/uapi/asm/bitsperlong.h"
> -#elif defined(__loongarch__)
> +#elif defined(__loongarch__) || defined(__TARGET_ARCH_loongarch)

__TARGET_ARCH_ is libbpf-specific convention, we can't add that to UAPI headers


let's think about some other solution


> #include "../../../arch/loongarch/include/uapi/asm/bitsperlong.h"
> #else
> #include <asm-generic/bitsperlong.h>
> --
> 2.1.0
>

2023-02-27 17:52:59

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 0/3] Fix some build errors for bpf selftest on LoongArch

On Fri, Feb 24, 2023 at 2:37 AM Tiezhu Yang <[email protected]> wrote:
>
> v2: Modify patch #3 to avoid breaking user_ringbuf test on x86
>
> Tiezhu Yang (3):
> libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for
> LoongArch
> selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf for
> LoongArch
> selftests/bpf: Use __NR_prlimit64 instead of __NR_getrlimit in
> user_ringbuf test

I've applied patches 1 and 3 to bpf-next, but we can't do what patch 2
does. Also, please provide a proper cover letter message next time,
just version log isn't enough.

>
> tools/include/uapi/asm/bitsperlong.h | 2 +-
> tools/lib/bpf/bpf_tracing.h | 2 ++
> tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 +-
> tools/testing/selftests/bpf/progs/user_ringbuf_success.c | 2 +-
> 4 files changed, 5 insertions(+), 3 deletions(-)
>
> --
> 2.1.0
>

2023-02-27 18:03:09

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 0/3] Fix some build errors for bpf selftest on LoongArch

Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <[email protected]>:

On Fri, 24 Feb 2023 18:36:52 +0800 you wrote:
> v2: Modify patch #3 to avoid breaking user_ringbuf test on x86
>
> Tiezhu Yang (3):
> libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for
> LoongArch
> selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf for
> LoongArch
> selftests/bpf: Use __NR_prlimit64 instead of __NR_getrlimit in
> user_ringbuf test
>
> [...]

Here is the summary with links:
- [bpf-next,v2,1/3] libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for LoongArch
https://git.kernel.org/bpf/bpf-next/c/29c66ad1c3ad
- [bpf-next,v2,2/3] selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf for LoongArch
(no matching commit)
- [bpf-next,v2,3/3] selftests/bpf: Use __NR_prlimit64 instead of __NR_getrlimit in user_ringbuf test
https://git.kernel.org/bpf/bpf-next/c/84c22fa83f9c

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html