selftests/bpf: Add powerpc support for get_preempt_count() in selftest
Subsystems (3)
PATCH v2 1/1 selftests/bpf: Add powerpc support for get_preempt_count() in selftest
get_preempt_count() is enabled to return preempt_count for powerpc, so that bpf_in_interrupt()/bpf_in_nmi()/bpf_in_serving_softirq()/ bpf_in_task()/bpf_in_hardirq()/get_preempt_count() works for powerpc as well.
---
Changes since v1:
* Updated the comments to include powerpc for the APIs.
v1: https://lore.kernel.org/bpf/[email protected]/
--- tools/testing/selftests/bpf/bpf_experimental.h | 7 +++++++ 1 file changed, 7 insertions(+)
tools/testing/selftests/bpf/bpf_experimental.h +7 -0
@@ -645,6 +645,8 @@ static inline int get_preempt_count(void) bpf_this_cpu_ptr(&pcpu_hot))->preempt_count;#elif defined(bpf_target_arm64)return bpf_get_current_task_btf ()->thread_info.preempt.count; +#elif defined(bpf_target_powerpc) +return bpf_get_current_task_btf ()->thread_info.preempt_count;#endif return 0 ; }
@@ -653,6 +655,7 @@ static inline int get_preempt_count(void)* Report whether it is in interrupt context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_interrupt (void ) {
@@ -672,6 +675,7 @@ static inline int bpf_in_interrupt(void)* Report whether it is in NMI context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_nmi (void ) {
@@ -682,6 +686,7 @@ static inline int bpf_in_nmi(void)* Report whether it is in hard IRQ context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_hardirq (void ) {
@@ -692,6 +697,7 @@ static inline int bpf_in_hardirq(void)* Report whether it is in softirq context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_serving_softirq (void ) {
@@ -710,6 +716,7 @@ static inline int bpf_in_serving_softirq(void)* Report whether it is in task context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_task (void ) {
Signature · 1 line
2.52.0
Quoted 6 lines · Saket Kumar Bhaskar
get_preempt_count()is enabled to returnpreempt_countfor powerpc, so that bpf_in_interrupt()/bpf_in_nmi()/bpf_in_serving_softirq()/ bpf_in_task()/bpf_in_hardirq()/get_preempt_count() works for powerpc as well.Signed-off-by Saket Kumar Bhaskar <[email protected]>
Tested this patch by applying on mainline kernel, and below selftests passes.
Please add below tag.
./test_progs -t exe_ctx
[ 610.897388] bpf_testmod: loading out-of-tree module taints kernel. [ 610.907373] audit: type=1334 audit(1771408772.036:229): prog-id=72 op=LOAD [ 610.907385] audit: type=1334 audit(1771408772.036:230): prog-id=72 op=UNLOAD [ 610.907461] audit: type=1334 audit(1771408772.036:231): prog-id=73 op=LOAD [ 610.907467] audit: type=1334 audit(1771408772.036:232): prog-id=73 op=UNLOAD [ 610.941282] audit: type=1334 audit(1771408772.076:233): prog-id=74 op=LOAD [ 610.941290] audit: type=1334 audit(1771408772.076:234): prog-id=74 op=UNLOAD [ 610.956474] audit: type=1334 audit(1771408772.086:235): prog-id=75 op=LOAD [ 610.956481] audit: type=1334 audit(1771408772.086:236): prog-id=75 op=UNLOAD [ 610.956964] audit: type=1334 audit(1771408772.086:237): prog-id=76 op=LOAD [ 610.956970] audit: type=1334 audit(1771408772.086:238): prog-id=76 op=UNLOAD #109 exe_ctx:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
./test_progs -t timer_interrupt
[ 730.106678] kauditd_printk_skb: 6 callbacks suppressed
[ 730.106685] audit: type=1334 audit(1771408891.236:245): prog-id=80 op=LOAD [ 730.106700] audit: type=1334 audit(1771408891.236:246): prog-id=80 op=UNLOAD [ 730.106787] audit: type=1334 audit(1771408891.236:247): prog-id=81 op=LOAD [ 730.106794] audit: type=1334 audit(1771408891.236:248): prog-id=81 op=UNLOAD [ 730.136150] audit: type=1334 audit(1771408891.266:249): prog-id=82 op=LOAD [ 730.136158] audit: type=1334 audit(1771408891.266:250): prog-id=82 op=UNLOAD [ 730.151245] audit: type=1334 audit(1771408891.286:251): prog-id=83 op=LOAD [ 730.151252] audit: type=1334 audit(1771408891.286:252): prog-id=83 op=UNLOAD [ 730.151572] audit: type=1334 audit(1771408891.286:253): prog-id=84 op=LOAD [ 730.151578] audit: type=1334 audit(1771408891.286:254): prog-id=84 op=UNLOAD #490 timer_interrupt:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
Regards,
Venkat.
Quoted 62 lines
---
Changes since v1:
* Updated the comments to include powerpc for the APIs.v1: https://lore.kernel.org/bpf/[email protected]/
--- tools/testing/selftests/bpf/bpf_experimental.h | 7 +++++++ 1 file changed, 7 insertions(+)tools/testing/selftests/bpf/bpf_experimental.h +7
-0@@ -645,6 +645,8 @@ static inline int get_preempt_count(void) bpf_this_cpu_ptr(&pcpu_hot))->preempt_count;#elif defined(bpf_target_arm64)return bpf_get_current_task_btf ()->thread_info.preempt.count; +#elif defined(bpf_target_powerpc) +return bpf_get_current_task_btf ()->thread_info.preempt_count;#endif return 0 ; }@@ -653,6 +655,7 @@ static inline int get_preempt_count(void)* Report whether it is in interrupt context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_interrupt (void ) {@@ -672,6 +675,7 @@ static inline int bpf_in_interrupt(void)* Report whether it is in NMI context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_nmi (void ) {@@ -682,6 +686,7 @@ static inline int bpf_in_nmi(void)* Report whether it is in hard IRQ context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_hardirq (void ) {@@ -692,6 +697,7 @@ static inline int bpf_in_hardirq(void)* Report whether it is in softirq context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_serving_softirq (void ) {@@ -710,6 +716,7 @@ static inline int bpf_in_serving_softirq(void)* Report whether it is in task context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_task (void ) {
Yonghong Song
reviewerQuoted 20 lines · Saket Kumar Bhaskar
get_preempt_count()is enabled to returnpreempt_countfor powerpc, so that bpf_in_interrupt()/bpf_in_nmi()/bpf_in_serving_softirq()/ bpf_in_task()/bpf_in_hardirq()/get_preempt_count() works for powerpc as well.Signed-off-by Saket Kumar Bhaskar <[email protected]>---
Changes since v1:
* Updated the comments to include powerpc for the APIs.v1: https://lore.kernel.org/bpf/[email protected]/
--- tools/testing/selftests/bpf/bpf_experimental.h | 7 +++++++ 1 file changed, 7 insertions(+)tools/testing/selftests/bpf/bpf_experimental.h +0
-0
tools/testing/selftests/bpf/bpf_experimental.h static inline int get_preempt_count(void) · line 650
Quoted 6 lines
tools/testing/selftests/bpf/bpf_experimental.h +2
-0@@ -645,6 +645,8 @@ static inline int get_preempt_count(void) bpf_this_cpu_ptr(&pcpu_hot))->preempt_count;#elif defined(bpf_target_arm64)return bpf_get_current_task_btf ()->thread_info.preempt.count; +#elif defined(bpf_target_powerpc) +return bpf_get_current_task_btf ()->thread_info.preempt_count;#endif
Maybe do
#elif defined(bpf_target_arm64) || defined(bpf_target_powerpc)
?
Quoted 42 lines
tools/testing/selftests/bpf/bpf_experimental.h +5
-0return 0 ; }@@ -653,6 +655,7 @@ static inline int get_preempt_count(void)* Report whether it is in interrupt context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_interrupt (void ) {@@ -672,6 +675,7 @@ static inline int bpf_in_interrupt(void)* Report whether it is in NMI context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_nmi (void ) {@@ -682,6 +686,7 @@ static inline int bpf_in_nmi(void)* Report whether it is in hard IRQ context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_hardirq (void ) {@@ -692,6 +697,7 @@ static inline int bpf_in_hardirq(void)* Report whether it is in softirq context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_serving_softirq (void ) {@@ -710,6 +716,7 @@ static inline int bpf_in_serving_softirq(void)* Report whether it is in task context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_task (void ) {
Yonghong Song
reviewerQuoted 18 lines · Yonghong Song
Quoted 15 lines · Saket Kumar Bhaskar
get_preempt_count()is enabled to returnpreempt_countfor powerpc, so that bpf_in_interrupt()/bpf_in_nmi()/bpf_in_serving_softirq()/ bpf_in_task()/bpf_in_hardirq()/get_preempt_count() works for powerpc as well.Signed-off-by Saket Kumar Bhaskar <[email protected]>---
Changes since v1:
* Updated the comments to include powerpc for the APIs.v1: https://lore.kernel.org/bpf/[email protected]/
---
tools/testing/selftests/bpf/bpf_experimental.h| 7 +++++++1 file changed, 7 insertions(+)
Quoted 15 lines
tools/testing/selftests/bpf/bpf_experimental.h static inline int get_preempt_count(void) · line 650
Quoted 11 lines
tools/testing/selftests/bpf/bpf_experimental.h +2
-0@@ -645,6 +645,8 @@ static inline int get_preempt_count(void) bpf_this_cpu_ptr(&pcpu_hot))->preempt_count; #elif defined(bpf_target_arm64) return bpf_get_current_task_btf()->thread_info.preempt.count; +#elif defined(bpf_target_powerpc) + return bpf_get_current_task_btf()->thread_info.preempt_count; #endifMaybe do
#elifdefined(bpf_target_arm64)||defined(bpf_target_powerpc)?
Sorry, my bad. Please ignore as missing preempt.count vs. preempt_count.
Quoted 45 lines
Quoted 43 lines
tools/testing/selftests/bpf/bpf_experimental.h +5
-0return 0; }@@ -653,6 +655,7 @@ static inline int get_preempt_count(void)* Report whether it is in interrupt context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_interrupt(void) {@@ -672,6 +675,7 @@ static inline int bpf_in_interrupt(void)* Report whether it is in NMI context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_nmi(void) {@@ -682,6 +686,7 @@ static inline int bpf_in_nmi(void)* Report whether it is in hard IRQ context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_hardirq(void) {@@ -692,6 +697,7 @@ static inline int bpf_in_hardirq(void)* Report whether it is in softirq context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_serving_softirq(void) {@@ -710,6 +716,7 @@ static inline int bpf_in_serving_softirq(void)* Report whether it is in task context. Only works on the following archs: * * x86 * * arm64 +* * powerpc64 */ static inline int bpf_in_task(void) {
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Thu, 12 Feb 2026 14:55:58 +0530 you wrote:
get_preempt_count()is enabled to returnpreempt_countfor powerpc, so that bpf_in_interrupt()/bpf_in_nmi()/bpf_in_serving_softirq()/ bpf_in_task()/bpf_in_hardirq()/get_preempt_count() works for powerpc as well.Signed-off-by Saket Kumar Bhaskar <[email protected]>[...]
Here is the summary with links:
- [v2] selftests/bpf: Add powerpc support for get_preempt_count() in selftest
https://git.kernel.org/bpf/bpf-next/c/4c51f90d45dc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html