public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC bpf-next 0/2] selftests/bpf: Add support for get_preempt_count()
@ 2026-04-20 11:15 Tiezhu Yang
  2026-04-20 11:15 ` [PATCH RFC bpf-next 1/2] selftests/bpf: Add riscv " Tiezhu Yang
  2026-04-20 11:15 ` [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch " Tiezhu Yang
  0 siblings, 2 replies; 5+ messages in thread
From: Tiezhu Yang @ 2026-04-20 11:15 UTC (permalink / raw)
  To: bpf, linux-riscv

This series is based on the latest bpf-next tree.

I can not test the patch #1 on riscv due to no riscv machine, I only
tested the patch #2 with the same change on LoongArch based on the RFC
"LoongArch: Implement CONFIG_THREAD_INFO_IN_TASK" [1], it works well.

I think the patch #1 is right for riscv in theory, because it supports
CONFIG_THREAD_INFO_IN_TASK and there is member preempt_count in struct
thread_info. I hope someone from riscv side can help test this patch.
If no, I will try to test. Thanks in advance.

[1] https://lore.kernel.org/loongarch/20260420102907.4617-1-yangtiezhu@loongson.cn/

Tiezhu Yang (2):
  selftests/bpf: Add riscv support for get_preempt_count()
  selftests/bpf: Add LoongArch support for get_preempt_count()

 tools/testing/selftests/bpf/bpf_experimental.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH RFC bpf-next 1/2] selftests/bpf: Add riscv support for get_preempt_count()
  2026-04-20 11:15 [PATCH RFC bpf-next 0/2] selftests/bpf: Add support for get_preempt_count() Tiezhu Yang
@ 2026-04-20 11:15 ` Tiezhu Yang
  2026-04-20 11:15 ` [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch " Tiezhu Yang
  1 sibling, 0 replies; 5+ messages in thread
From: Tiezhu Yang @ 2026-04-20 11:15 UTC (permalink / raw)
  To: bpf, linux-riscv

There is no riscv support for get_preempt_count() currently and its
fallback path always returns 0, just add it so that bpf_in_interrupt(),
bpf_in_nmi(), bpf_in_hardirq(), bpf_in_serving_softirq(), bpf_in_task()
works for riscv as well. With this patch, "./test_progs -t exe_ctx"
should pass on riscv.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/testing/selftests/bpf/bpf_experimental.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index 2234bd6bc9d3..e5c039bc44cb 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -505,6 +505,8 @@ static inline int get_preempt_count(void)
 	return bpf_get_current_task_btf()->thread_info.preempt_count;
 #elif defined(bpf_target_s390)
 	return bpf_get_lowcore()->preempt_count;
+#elif defined(bpf_target_riscv)
+	return bpf_get_current_task_btf()->thread_info.preempt_count;
 #endif
 	return 0;
 }
@@ -515,6 +517,7 @@ static inline int get_preempt_count(void)
  *	* arm64
  *	* powerpc64
  *	* s390x
+ *	* riscv
  */
 static inline int bpf_in_interrupt(void)
 {
@@ -536,6 +539,7 @@ static inline int bpf_in_interrupt(void)
  *	* arm64
  *	* powerpc64
  *	* s390x
+ *	* riscv
  */
 static inline int bpf_in_nmi(void)
 {
@@ -548,6 +552,7 @@ static inline int bpf_in_nmi(void)
  *	* arm64
  *	* powerpc64
  *	* s390x
+ *	* riscv
  */
 static inline int bpf_in_hardirq(void)
 {
@@ -560,6 +565,7 @@ static inline int bpf_in_hardirq(void)
  *	* arm64
  *	* powerpc64
  *	* s390x
+ *	* riscv
  */
 static inline int bpf_in_serving_softirq(void)
 {
@@ -580,6 +586,7 @@ static inline int bpf_in_serving_softirq(void)
  *	* arm64
  *	* powerpc64
  *	* s390x
+ *	* riscv
  */
 static inline int bpf_in_task(void)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count()
  2026-04-20 11:15 [PATCH RFC bpf-next 0/2] selftests/bpf: Add support for get_preempt_count() Tiezhu Yang
  2026-04-20 11:15 ` [PATCH RFC bpf-next 1/2] selftests/bpf: Add riscv " Tiezhu Yang
@ 2026-04-20 11:15 ` Tiezhu Yang
  2026-04-20 13:35   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Tiezhu Yang @ 2026-04-20 11:15 UTC (permalink / raw)
  To: bpf, linux-riscv

There is no LoongArch support for get_preempt_count() currently and its
fallback path always returns 0, just add it so that bpf_in_interrupt(),
bpf_in_nmi(), bpf_in_hardirq(), bpf_in_serving_softirq(), bpf_in_task()
works for LoongArch as well. With this patch, "./test_progs -t exe_ctx"
should pass on LoongArch.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/testing/selftests/bpf/bpf_experimental.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index e5c039bc44cb..5847bbf12d24 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -507,6 +507,8 @@ static inline int get_preempt_count(void)
 	return bpf_get_lowcore()->preempt_count;
 #elif defined(bpf_target_riscv)
 	return bpf_get_current_task_btf()->thread_info.preempt_count;
+#elif defined(bpf_target_loongarch)
+	return bpf_get_current_task_btf()->thread_info.preempt_count;
 #endif
 	return 0;
 }
@@ -518,6 +520,7 @@ static inline int get_preempt_count(void)
  *	* powerpc64
  *	* s390x
  *	* riscv
+ *	* loongarch
  */
 static inline int bpf_in_interrupt(void)
 {
@@ -540,6 +543,7 @@ static inline int bpf_in_interrupt(void)
  *	* powerpc64
  *	* s390x
  *	* riscv
+ *	* loongarch
  */
 static inline int bpf_in_nmi(void)
 {
@@ -553,6 +557,7 @@ static inline int bpf_in_nmi(void)
  *	* powerpc64
  *	* s390x
  *	* riscv
+ *	* loongarch
  */
 static inline int bpf_in_hardirq(void)
 {
@@ -566,6 +571,7 @@ static inline int bpf_in_hardirq(void)
  *	* powerpc64
  *	* s390x
  *	* riscv
+ *	* loongarch
  */
 static inline int bpf_in_serving_softirq(void)
 {
@@ -587,6 +593,7 @@ static inline int bpf_in_serving_softirq(void)
  *	* powerpc64
  *	* s390x
  *	* riscv
+ *	* loongarch
  */
 static inline int bpf_in_task(void)
 {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count()
  2026-04-20 11:15 ` [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch " Tiezhu Yang
@ 2026-04-20 13:35   ` sashiko-bot
  2026-04-21  0:47     ` Tiezhu Yang
  0 siblings, 1 reply; 5+ messages in thread
From: sashiko-bot @ 2026-04-20 13:35 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: bpf

Sashiko AI review found 1 potential issue(s):
- [High] BPF programs including `bpf_experimental.h` will fail to compile on LoongArch due to a non-existent `thread_info` field in `struct task_struct`.
--

commit 82453686fe5eacd9f219e2a050dc016b297cfc79
Author: Tiezhu Yang <yangtiezhu@loongson.cn>

selftests/bpf: Add LoongArch support for get_preempt_count()

This commit adds LoongArch support for get_preempt_count() in the BPF
experimental helpers. It enables bpf_in_interrupt() and related macros to
work properly on LoongArch systems.

> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
> index e5c039bc44cb4..5847bbf12d240 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -507,6 +507,8 @@ static inline int get_preempt_count(void)
>  	return bpf_get_lowcore()->preempt_count;
>  #elif defined(bpf_target_riscv)
>  	return bpf_get_current_task_btf()->thread_info.preempt_count;
> +#elif defined(bpf_target_loongarch)
> +	return bpf_get_current_task_btf()->thread_info.preempt_count;

Will this compile successfully on LoongArch?

Since LoongArch does not select CONFIG_THREAD_INFO_IN_TASK, struct
thread_info is allocated on the kernel stack rather than being embedded
within struct task_struct. Because of this, the generated BTF and vmlinux.h
for LoongArch will not contain a thread_info field in task_struct.

Could this lead to a compiler error indicating that there is no member named
thread_info in struct task_struct when building BPF selftests?

>  #endif
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260420111516.19982-1-yangtiezhu@loongson.cn?part=2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count()
  2026-04-20 13:35   ` sashiko-bot
@ 2026-04-21  0:47     ` Tiezhu Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Tiezhu Yang @ 2026-04-21  0:47 UTC (permalink / raw)
  To: sashiko; +Cc: bpf

On 2026/4/20 下午9:35, sashiko-bot@kernel.org wrote:
> Sashiko AI review found 1 potential issue(s):
> - [High] BPF programs including `bpf_experimental.h` will fail to compile on LoongArch due to a non-existent `thread_info` field in `struct task_struct`.
> --
> 
> commit 82453686fe5eacd9f219e2a050dc016b297cfc79
> Author: Tiezhu Yang <yangtiezhu@loongson.cn>
> 
> selftests/bpf: Add LoongArch support for get_preempt_count()
> 
> This commit adds LoongArch support for get_preempt_count() in the BPF
> experimental helpers. It enables bpf_in_interrupt() and related macros to
> work properly on LoongArch systems.
> 
>> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
>> index e5c039bc44cb4..5847bbf12d240 100644
>> --- a/tools/testing/selftests/bpf/bpf_experimental.h
>> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
>> @@ -507,6 +507,8 @@ static inline int get_preempt_count(void)
>>   	return bpf_get_lowcore()->preempt_count;
>>   #elif defined(bpf_target_riscv)
>>   	return bpf_get_current_task_btf()->thread_info.preempt_count;
>> +#elif defined(bpf_target_loongarch)
>> +	return bpf_get_current_task_btf()->thread_info.preempt_count;
> 
> Will this compile successfully on LoongArch?
> 
> Since LoongArch does not select CONFIG_THREAD_INFO_IN_TASK, struct
> thread_info is allocated on the kernel stack rather than being embedded
> within struct task_struct. Because of this, the generated BTF and vmlinux.h
> for LoongArch will not contain a thread_info field in task_struct.
> 
> Could this lead to a compiler error indicating that there is no member named
> thread_info in struct task_struct when building BPF selftests?

As mentioned in the cover letter, it needs to apply the kernel patch
"LoongArch: Implement CONFIG_THREAD_INFO_IN_TASK" [1] before testing.

[1] 
https://lore.kernel.org/loongarch/20260420102907.4617-1-yangtiezhu@loongson.cn/

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-04-21  0:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 11:15 [PATCH RFC bpf-next 0/2] selftests/bpf: Add support for get_preempt_count() Tiezhu Yang
2026-04-20 11:15 ` [PATCH RFC bpf-next 1/2] selftests/bpf: Add riscv " Tiezhu Yang
2026-04-20 11:15 ` [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch " Tiezhu Yang
2026-04-20 13:35   ` sashiko-bot
2026-04-21  0:47     ` Tiezhu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox