[PATCH v2] selftests/bpf: Add powerpc support for get_preempt_count() in selftest
Venkat Rao Bagalkote
venkat88 at linux.ibm.com
Thu Feb 12 21:54:32 AEDT 2026
On 12/02/26 2:55 pm, Saket Kumar Bhaskar wrote:
> 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.
>
> Signed-off-by: Saket Kumar Bhaskar <skb99 at linux.ibm.com>
Tested this patch by applying on mainline kernel, and below selftests
passes.
Please add below tag.
Tested-by: Venkat Rao Bagalkote <venkat88 at linux.ibm.com>
./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.
> ---
> Changes since v1:
> * Updated the comments to include powerpc for the APIs.
>
> v1: https://lore.kernel.org/bpf/20260129054035.168078-1-skb99@linux.ibm.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 4b7210c318dd..9df77e59d4f5 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -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)
> {
More information about the Linuxppc-dev
mailing list