* [PATCH bpf-next 0/3] Fix some build errors for bpf selftest on LoongArch
@ 2023-02-22 11:55 Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 1/3] libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for LoongArch Tiezhu Yang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tiezhu Yang @ 2023-02-22 11:55 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, linux-kernel
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: Check __ARCH_WANT_SET_GET_RLIMIT before
syscall(__NR_getrlimit)
tools/include/uapi/asm/bitsperlong.h | 2 +-
tools/lib/bpf/bpf_tracing.h | 2 ++
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
--
2.1.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf-next 1/3] libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for LoongArch
2023-02-22 11:55 [PATCH bpf-next 0/3] Fix some build errors for bpf selftest on LoongArch Tiezhu Yang
@ 2023-02-22 11:55 ` Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 2/3] selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf " Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) Tiezhu Yang
2 siblings, 0 replies; 7+ messages in thread
From: Tiezhu Yang @ 2023-02-22 11:55 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, linux-kernel
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 <yangtiezhu@loongson.cn>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf-next 2/3] selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf for LoongArch
2023-02-22 11:55 [PATCH bpf-next 0/3] Fix some build errors for bpf selftest on LoongArch Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 1/3] libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for LoongArch Tiezhu Yang
@ 2023-02-22 11:55 ` Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) Tiezhu Yang
2 siblings, 0 replies; 7+ messages in thread
From: Tiezhu Yang @ 2023-02-22 11:55 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, linux-kernel
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 <yangtiezhu@loongson.cn>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit)
2023-02-22 11:55 [PATCH bpf-next 0/3] Fix some build errors for bpf selftest on LoongArch Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 1/3] libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for LoongArch Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 2/3] selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf " Tiezhu Yang
@ 2023-02-22 11:55 ` Tiezhu Yang
2023-02-22 18:06 ` Alexei Starovoitov
2 siblings, 1 reply; 7+ messages in thread
From: Tiezhu Yang @ 2023-02-22 11:55 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, linux-kernel
__NR_getrlimit is defined only if __ARCH_WANT_SET_GET_RLIMIT is defined:
#ifdef __ARCH_WANT_SET_GET_RLIMIT
/* getrlimit and setrlimit are superseded with prlimit64 */
#define __NR_getrlimit 163
...
#endif
Some archs do not define __ARCH_WANT_SET_GET_RLIMIT, it should check
__ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) 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 <yangtiezhu@loongson.cn>
---
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
index 3a13e10..0550307 100644
--- a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
@@ -590,7 +590,9 @@ 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.
*/
+#ifdef __ARCH_WANT_SET_GET_RLIMIT
syscall(__NR_getrlimit);
+#endif
return NULL;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit)
2023-02-22 11:55 ` [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) Tiezhu Yang
@ 2023-02-22 18:06 ` Alexei Starovoitov
2023-02-22 20:03 ` Mykola Lysenko
0 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2023-02-22 18:06 UTC (permalink / raw)
To: Tiezhu Yang
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf, LKML
On Wed, Feb 22, 2023 at 3:55 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> __NR_getrlimit is defined only if __ARCH_WANT_SET_GET_RLIMIT is defined:
>
> #ifdef __ARCH_WANT_SET_GET_RLIMIT
> /* getrlimit and setrlimit are superseded with prlimit64 */
> #define __NR_getrlimit 163
> ...
> #endif
>
> Some archs do not define __ARCH_WANT_SET_GET_RLIMIT, it should check
> __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) 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 <yangtiezhu@loongson.cn>
> ---
> tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
> index 3a13e10..0550307 100644
> --- a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
> @@ -590,7 +590,9 @@ 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.
> */
> +#ifdef __ARCH_WANT_SET_GET_RLIMIT
> syscall(__NR_getrlimit);
> +#endif
This is clearly breaks user_ringbuf test on x86:
https://github.com/kernel-patches/bpf/actions/runs/4242660318/jobs/7374845859
Please do not send patches that make selftest compile on your favorite arch.
Make sure the patches work correctly on other archs too.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit)
2023-02-22 18:06 ` Alexei Starovoitov
@ 2023-02-22 20:03 ` Mykola Lysenko
2023-02-23 2:48 ` Tiezhu Yang
0 siblings, 1 reply; 7+ messages in thread
From: Mykola Lysenko @ 2023-02-22 20:03 UTC (permalink / raw)
To: Tiezhu Yang
Cc: Mykola Lysenko, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, bpf, LKML, Alexei Starovoitov
Hi Tiezhu,
You can run BPF CI tests on your patch before sending it out by following these instructions:
https://docs.kernel.org/bpf/bpf_devel_QA.html#q-how-do-i-run-bpf-ci-on-my-changes-before-sending-them-out-for-review
Thanks,
Mykola
> On Feb 22, 2023, at 10:06 AM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
>
> !-------------------------------------------------------------------|
> This Message Is From an External Sender
>
> |-------------------------------------------------------------------!
>
> On Wed, Feb 22, 2023 at 3:55 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>
>> __NR_getrlimit is defined only if __ARCH_WANT_SET_GET_RLIMIT is defined:
>>
>> #ifdef __ARCH_WANT_SET_GET_RLIMIT
>> /* getrlimit and setrlimit are superseded with prlimit64 */
>> #define __NR_getrlimit 163
>> ...
>> #endif
>>
>> Some archs do not define __ARCH_WANT_SET_GET_RLIMIT, it should check
>> __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) 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 <yangtiezhu@loongson.cn>
>> ---
>> tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
>> index 3a13e10..0550307 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
>> @@ -590,7 +590,9 @@ 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.
>> */
>> +#ifdef __ARCH_WANT_SET_GET_RLIMIT
>> syscall(__NR_getrlimit);
>> +#endif
>
> This is clearly breaks user_ringbuf test on x86:
> https://github.com/kernel-patches/bpf/actions/runs/4242660318/jobs/7374845859
>
> Please do not send patches that make selftest compile on your favorite arch.
> Make sure the patches work correctly on other archs too.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit)
2023-02-22 20:03 ` Mykola Lysenko
@ 2023-02-23 2:48 ` Tiezhu Yang
0 siblings, 0 replies; 7+ messages in thread
From: Tiezhu Yang @ 2023-02-23 2:48 UTC (permalink / raw)
To: Mykola Lysenko
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf, LKML,
Alexei Starovoitov
On 02/23/2023 04:03 AM, Mykola Lysenko wrote:
> Hi Tiezhu,
>
> You can run BPF CI tests on your patch before sending it out by following these instructions:
> https://docs.kernel.org/bpf/bpf_devel_QA.html#q-how-do-i-run-bpf-ci-on-my-changes-before-sending-them-out-for-review
OK, thank you.
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.c to fix the
build error.
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;
}
I will test it and then send v2. If you have more suggestions,
please let me know.
Thanks,
Tiezhu
>
> Thanks,
> Mykola
>
>> On Feb 22, 2023, at 10:06 AM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
>>
>> !-------------------------------------------------------------------|
>> This Message Is From an External Sender
>>
>> |-------------------------------------------------------------------!
>>
>> On Wed, Feb 22, 2023 at 3:55 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>>
>>> __NR_getrlimit is defined only if __ARCH_WANT_SET_GET_RLIMIT is defined:
>>>
>>> #ifdef __ARCH_WANT_SET_GET_RLIMIT
>>> /* getrlimit and setrlimit are superseded with prlimit64 */
>>> #define __NR_getrlimit 163
>>> ...
>>> #endif
>>>
>>> Some archs do not define __ARCH_WANT_SET_GET_RLIMIT, it should check
>>> __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) 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 <yangtiezhu@loongson.cn>
>>> ---
>>> tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 2 ++
>>> 1 file changed, 2 insertions(+)
>>>
>>> diff --git a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
>>> index 3a13e10..0550307 100644
>>> --- a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
>>> +++ b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
>>> @@ -590,7 +590,9 @@ 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.
>>> */
>>> +#ifdef __ARCH_WANT_SET_GET_RLIMIT
>>> syscall(__NR_getrlimit);
>>> +#endif
>>
>> This is clearly breaks user_ringbuf test on x86:
>> https://github.com/kernel-patches/bpf/actions/runs/4242660318/jobs/7374845859
>>
>> Please do not send patches that make selftest compile on your favorite arch.
>> Make sure the patches work correctly on other archs too.
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-02-23 2:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22 11:55 [PATCH bpf-next 0/3] Fix some build errors for bpf selftest on LoongArch Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 1/3] libbpf: Use struct user_pt_regs to define __PT_REGS_CAST() for LoongArch Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 2/3] selftests/bpf: Check __TARGET_ARCH_loongarch if target is bpf " Tiezhu Yang
2023-02-22 11:55 ` [PATCH bpf-next 3/3] selftests/bpf: Check __ARCH_WANT_SET_GET_RLIMIT before syscall(__NR_getrlimit) Tiezhu Yang
2023-02-22 18:06 ` Alexei Starovoitov
2023-02-22 20:03 ` Mykola Lysenko
2023-02-23 2:48 ` Tiezhu Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).