* [PATCH bpf-next v1] selftests/bpf: Add get_preempt_count() support for RISC-V
@ 2026-07-22 2:29 Tiezhu Yang
2026-07-22 2:51 ` Pu Lehui
2026-07-24 21:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Tiezhu Yang @ 2026-07-22 2:29 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai; +Cc: bpf, linux-kernel
Currently, there is no RISC-V support for get_preempt_count() and
its fallback path always returns 0.
Add it so that bpf_in_interrupt(), bpf_in_nmi(), bpf_in_hardirq(),
bpf_in_serving_softirq(), and bpf_in_task() work for RISC-V as well.
Given that RISC-V has supported CONFIG_THREAD_INFO_IN_TASK since its
initial commit fbe934d69eb7 ("RISC-V: Build Infrastructure") in 2017,
directly retrieve preempt_count from the thread_info embedded within
task_struct via bpf_get_current_task_btf().
This aligns the implementation with arm64, powerpc, and loongarch.
Tested on a RISC-V virtual machine.
Before:
$ sudo ./test_progs -t exe_ctx
...
#114 exe_ctx:FAIL
Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
After:
$ sudo ./test_progs -t exe_ctx
#114 exe_ctx:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Tested-by: Pu Lehui <pulehui@huawei.com>
Reviewed-by: Pu Lehui <pulehui@huawei.com>
---
RFC -> v1:
-- No code changes
-- Update the commit message
-- Add Tested-by and Reviewed-by
https://lore.kernel.org/bpf/0191fe3f-b956-480d-aef2-a4d75f9e02de@huawei.com/
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 67ff7882299e..ff37ae5a113d 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -425,6 +425,8 @@ static inline int get_preempt_count(void)
return bpf_get_lowcore()->preempt_count;
#elif defined(bpf_target_loongarch)
return bpf_get_current_task_btf()->thread_info.preempt_count;
+#elif defined(bpf_target_riscv)
+ return bpf_get_current_task_btf()->thread_info.preempt_count;
#endif
return 0;
}
@@ -436,6 +438,7 @@ static inline int get_preempt_count(void)
* * powerpc64
* * s390x
* * loongarch
+ * * riscv
*/
static inline int bpf_in_interrupt(void)
{
@@ -458,6 +461,7 @@ static inline int bpf_in_interrupt(void)
* * powerpc64
* * s390x
* * loongarch
+ * * riscv
*/
static inline int bpf_in_nmi(void)
{
@@ -471,6 +475,7 @@ static inline int bpf_in_nmi(void)
* * powerpc64
* * s390x
* * loongarch
+ * * riscv
*/
static inline int bpf_in_hardirq(void)
{
@@ -484,6 +489,7 @@ static inline int bpf_in_hardirq(void)
* * powerpc64
* * s390x
* * loongarch
+ * * riscv
*/
static inline int bpf_in_serving_softirq(void)
{
@@ -505,6 +511,7 @@ static inline int bpf_in_serving_softirq(void)
* * powerpc64
* * s390x
* * loongarch
+ * * riscv
*/
static inline int bpf_in_task(void)
{
--
2.42.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH bpf-next v1] selftests/bpf: Add get_preempt_count() support for RISC-V
2026-07-22 2:29 [PATCH bpf-next v1] selftests/bpf: Add get_preempt_count() support for RISC-V Tiezhu Yang
@ 2026-07-22 2:51 ` Pu Lehui
2026-07-24 21:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Pu Lehui @ 2026-07-22 2:51 UTC (permalink / raw)
To: Tiezhu Yang, Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai
Cc: bpf, linux-kernel
Hi Tiezhu,
Thanks to respin it, we need this to cover more selftests.
On 2026/7/22 10:29, Tiezhu Yang wrote:
> Currently, there is no RISC-V support for get_preempt_count() and
> its fallback path always returns 0.
>
> Add it so that bpf_in_interrupt(), bpf_in_nmi(), bpf_in_hardirq(),
> bpf_in_serving_softirq(), and bpf_in_task() work for RISC-V as well.
>
> Given that RISC-V has supported CONFIG_THREAD_INFO_IN_TASK since its
> initial commit fbe934d69eb7 ("RISC-V: Build Infrastructure") in 2017,
> directly retrieve preempt_count from the thread_info embedded within
> task_struct via bpf_get_current_task_btf().
>
> This aligns the implementation with arm64, powerpc, and loongarch.
>
> Tested on a RISC-V virtual machine.
>
> Before:
> $ sudo ./test_progs -t exe_ctx
> ...
> #114 exe_ctx:FAIL
> Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
>
> After:
> $ sudo ./test_progs -t exe_ctx
> #114 exe_ctx:OK
> Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> Tested-by: Pu Lehui <pulehui@huawei.com>
> Reviewed-by: Pu Lehui <pulehui@huawei.com>
> ---
> RFC -> v1:
> -- No code changes
> -- Update the commit message
> -- Add Tested-by and Reviewed-by
> https://lore.kernel.org/bpf/0191fe3f-b956-480d-aef2-a4d75f9e02de@huawei.com/
>
> 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 67ff7882299e..ff37ae5a113d 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -425,6 +425,8 @@ static inline int get_preempt_count(void)
> return bpf_get_lowcore()->preempt_count;
> #elif defined(bpf_target_loongarch)
> return bpf_get_current_task_btf()->thread_info.preempt_count;
> +#elif defined(bpf_target_riscv)
> + return bpf_get_current_task_btf()->thread_info.preempt_count;
> #endif
> return 0;
> }
> @@ -436,6 +438,7 @@ static inline int get_preempt_count(void)
> * * powerpc64
> * * s390x
> * * loongarch
> + * * riscv
> */
> static inline int bpf_in_interrupt(void)
> {
> @@ -458,6 +461,7 @@ static inline int bpf_in_interrupt(void)
> * * powerpc64
> * * s390x
> * * loongarch
> + * * riscv
> */
> static inline int bpf_in_nmi(void)
> {
> @@ -471,6 +475,7 @@ static inline int bpf_in_nmi(void)
> * * powerpc64
> * * s390x
> * * loongarch
> + * * riscv
> */
> static inline int bpf_in_hardirq(void)
> {
> @@ -484,6 +489,7 @@ static inline int bpf_in_hardirq(void)
> * * powerpc64
> * * s390x
> * * loongarch
> + * * riscv
> */
> static inline int bpf_in_serving_softirq(void)
> {
> @@ -505,6 +511,7 @@ static inline int bpf_in_serving_softirq(void)
> * * powerpc64
> * * s390x
> * * loongarch
> + * * riscv
> */
> static inline int bpf_in_task(void)
> {
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH bpf-next v1] selftests/bpf: Add get_preempt_count() support for RISC-V
2026-07-22 2:29 [PATCH bpf-next v1] selftests/bpf: Add get_preempt_count() support for RISC-V Tiezhu Yang
2026-07-22 2:51 ` Pu Lehui
@ 2026-07-24 21:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-07-24 21:00 UTC (permalink / raw)
To: Tiezhu Yang; +Cc: andrii, eddyz87, ihor.solodrai, bpf, linux-kernel
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Kumar Kartikeya Dwivedi <memxor@gmail.com>:
On Wed, 22 Jul 2026 10:29:06 +0800 you wrote:
> Currently, there is no RISC-V support for get_preempt_count() and
> its fallback path always returns 0.
>
> Add it so that bpf_in_interrupt(), bpf_in_nmi(), bpf_in_hardirq(),
> bpf_in_serving_softirq(), and bpf_in_task() work for RISC-V as well.
>
> Given that RISC-V has supported CONFIG_THREAD_INFO_IN_TASK since its
> initial commit fbe934d69eb7 ("RISC-V: Build Infrastructure") in 2017,
> directly retrieve preempt_count from the thread_info embedded within
> task_struct via bpf_get_current_task_btf().
>
> [...]
Here is the summary with links:
- [bpf-next,v1] selftests/bpf: Add get_preempt_count() support for RISC-V
https://git.kernel.org/bpf/bpf-next/c/9b19237a46e7
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-24 21:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 2:29 [PATCH bpf-next v1] selftests/bpf: Add get_preempt_count() support for RISC-V Tiezhu Yang
2026-07-22 2:51 ` Pu Lehui
2026-07-24 21:00 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.