* [PATCH bpf-next] selftests/bpf: Return -1 from get_preempt_count() for unsupported architecture
@ 2026-01-29 5:09 Saket Kumar Bhaskar
2026-01-29 5:38 ` bot+bpf-ci
2026-01-29 16:03 ` Yonghong Song
0 siblings, 2 replies; 4+ messages in thread
From: Saket Kumar Bhaskar @ 2026-01-29 5:09 UTC (permalink / raw)
To: linux-kernel, linux-kselftest, bpf
Cc: hbathini, sachinpb, venkat88, andrii, eddyz87, ast, daniel,
martin.lau, song, yonghong.song, john.fastabend, kpsingh, sdf,
haoluo, jolsa
Make get_preempt_count() to return -1 for unsupported
architectures instead of 0, so callers can distinguish not supported
from a valid preempt_count of 0.
Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com>
---
tools/testing/selftests/bpf/bpf_experimental.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index 2cd9165c7348..6759d2ae6151 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -631,7 +631,7 @@ static inline int get_preempt_count(void)
#elif defined(bpf_target_arm64)
return bpf_get_current_task_btf()->thread_info.preempt.count;
#endif
- return 0;
+ return -1;
}
/* Description
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Return -1 from get_preempt_count() for unsupported architecture
2026-01-29 5:09 [PATCH bpf-next] selftests/bpf: Return -1 from get_preempt_count() for unsupported architecture Saket Kumar Bhaskar
@ 2026-01-29 5:38 ` bot+bpf-ci
2026-01-29 16:03 ` Yonghong Song
1 sibling, 0 replies; 4+ messages in thread
From: bot+bpf-ci @ 2026-01-29 5:38 UTC (permalink / raw)
To: skb99, linux-kernel, linux-kselftest, bpf
Cc: hbathini, sachinpb, venkat88, andrii, eddyz87, ast, daniel,
martin.lau, song, yonghong.song, john.fastabend, kpsingh, sdf,
haoluo, jolsa, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, clm, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 2122 bytes --]
> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
> index a39576c8ba..87706a213a 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -628,7 +628,7 @@ static inline int get_preempt_count(void)
> #elif defined(bpf_target_arm64)
> return bpf_get_current_task_btf()->thread_info.preempt.count;
> #endif
> - return 0;
> + return -1;
> }
Returning -1 here causes incorrect behavior in all the bpf_in_* helper
functions that call get_preempt_count(). Since -1 is 0xFFFFFFFF in
twos complement, the bitmask operations in the callers produce non-zero
results:
bpf_in_nmi(): -1 & NMI_MASK = 0x00F00000 (non-zero)
bpf_in_hardirq(): -1 & HARDIRQ_MASK = 0x000F0000 (non-zero)
bpf_in_interrupt(): returns non-zero (falsely indicates interrupt ctx)
bpf_in_serving_softirq(): returns non-zero
bpf_in_task(): returns 0 (falsely indicates NOT in task context)
Previously with return 0, these functions would return 0 on unsupported
architectures. Now they return false positives indicating the system is
in NMI/hardirq/softirq context when it may not be.
Should the callers be updated to check for -1 before performing the
bitmask operations? For example:
static inline int bpf_in_nmi(void)
{
int pcnt = get_preempt_count();
if (pcnt < 0)
return -1; /* or 0? */
return pcnt & NMI_MASK;
}
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21466700415
AI-authorship-score: low
AI-authorship-explanation: Simple one-line change with clear human-authored commit message following standard kernel conventions.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Incomplete API change causes bpf_in_* functions to return false positives on unsupported architectures, but this only affects selftest code on non-x86/arm64 systems.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH bpf-next] selftests/bpf: Return -1 from get_preempt_count() for unsupported architecture
2026-01-29 5:09 [PATCH bpf-next] selftests/bpf: Return -1 from get_preempt_count() for unsupported architecture Saket Kumar Bhaskar
2026-01-29 5:38 ` bot+bpf-ci
@ 2026-01-29 16:03 ` Yonghong Song
2026-01-29 16:13 ` Yonghong Song
1 sibling, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2026-01-29 16:03 UTC (permalink / raw)
To: Saket Kumar Bhaskar, linux-kernel, linux-kselftest, bpf
Cc: hbathini, sachinpb, venkat88, andrii, eddyz87, ast, daniel,
martin.lau, song, john.fastabend, kpsingh, sdf, haoluo, jolsa
On 1/28/26 9:09 PM, Saket Kumar Bhaskar wrote:
> Make get_preempt_count() to return -1 for unsupported
> architectures instead of 0, so callers can distinguish not supported
> from a valid preempt_count of 0.
>
> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com>
LGTM.
Acked-by: Yonghong Song <yonghong.song@linux.dev>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Return -1 from get_preempt_count() for unsupported architecture
2026-01-29 16:03 ` Yonghong Song
@ 2026-01-29 16:13 ` Yonghong Song
0 siblings, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2026-01-29 16:13 UTC (permalink / raw)
To: Saket Kumar Bhaskar, linux-kernel, linux-kselftest, bpf
Cc: hbathini, sachinpb, venkat88, andrii, eddyz87, ast, daniel,
martin.lau, song, john.fastabend, kpsingh, sdf, haoluo, jolsa
On 1/29/26 8:03 AM, Yonghong Song wrote:
>
>
> On 1/28/26 9:09 PM, Saket Kumar Bhaskar wrote:
>> Make get_preempt_count() to return -1 for unsupported
>> architectures instead of 0, so callers can distinguish not supported
>> from a valid preempt_count of 0.
>>
>> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com>
>
> LGTM.
>
> Acked-by: Yonghong Song <yonghong.song@linux.dev>
Dig through further. My above Ack is invalid due the following usage
e.g.
static inline int bpf_in_nmi(void)
{
return get_preempt_count() & NMI_MASK;
}
in bpf_experimental.h. In such cases, returning -1 for get_preempt_count()
may cause bpf_in_nmi() to be true, but this is incorrect.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-29 16:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-29 5:09 [PATCH bpf-next] selftests/bpf: Return -1 from get_preempt_count() for unsupported architecture Saket Kumar Bhaskar
2026-01-29 5:38 ` bot+bpf-ci
2026-01-29 16:03 ` Yonghong Song
2026-01-29 16:13 ` Yonghong Song
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.