Subject: Re: [PATCH v2] selftests/bpf: Add powerpc support for get_preempt_count() in selftest

From: Yonghong Song <[email-masked]>
Date: Thu, 12 Feb 2026 15:53:49 -0800

On 2/12/26 3:52 PM, Yonghong Song wrote:
>
>
> On 2/12/26 1:25 AM, 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 <[email-masked]>
>> ---
>> Changes since v1:
>> * Updated the comments to include powerpc for the APIs.
>>
>> v1: 
>> https://lore.kernel.org/bpf/[email-masked]/
>> ---
>>   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
>
> Maybe do
>   #elif defined(bpf_target_arm64) || defined(bpf_target_powerpc)
> ?

Sorry, my bad. Please ignore as missing preempt.count vs. preempt_count.

>
>>       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)
>>   {
>
>