[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3d26b162-d218-41ec-b5ab-3657eaffadf6@linux.dev>
Date: Mon, 10 Nov 2025 17:26:42 +0800
From: Tao Chen <chen.dylane@...ux.dev>
To: Peter Zijlstra <peterz@...radead.org>
Cc: mingo@...hat.com, acme@...nel.org, namhyung@...nel.org,
mark.rutland@....com, alexander.shishkin@...ux.intel.com, jolsa@...nel.org,
irogers@...gle.com, adrian.hunter@...el.com, kan.liang@...ux.intel.com,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org, Yonghong Song <yonghong.song@...ux.dev>
Subject: Re: [PATCH bpf-next v5 2/3] perf: Add atomic operation in
get_recursion_context
在 2025/11/10 16:52, Peter Zijlstra 写道:
> On Mon, Nov 10, 2025 at 12:35:58AM +0800, Tao Chen wrote:
>> From BPF side, preemption usually is enabled. Yonghong said, it is
>> possible that both tasks (at process level) may reach right before
>> "recursion[rctx]++;". In such cases, both tasks will be able to get
>> buffer and this is not right.
>>
>> Signed-off-by: Yonghong Song <yonghong.song@...ux.dev>
>> Signed-off-by: Tao Chen <chen.dylane@...ux.dev>
>> ---
>
> Nope, this function really is meant to be used with preemption disabled.
> If BPF doesn't abide, fix that.
>
Ok, let us use preempt_disable in bpf stackmap, thanks. I will change it
in v6.
>> kernel/events/internal.h | 5 +----
>> 1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/kernel/events/internal.h b/kernel/events/internal.h
>> index d9cc5708309..684bde972ba 100644
>> --- a/kernel/events/internal.h
>> +++ b/kernel/events/internal.h
>> @@ -214,12 +214,9 @@ static inline int get_recursion_context(u8 *recursion)
>> {
>> unsigned char rctx = interrupt_context_level();
>>
>> - if (recursion[rctx])
>> + if (cmpxchg(&recursion[rctx], 0, 1) != 0)
>> return -1;
>>
>> - recursion[rctx]++;
>> - barrier();
>> -
>> return rctx;
>> }
>>
>> --
>> 2.48.1
>>
--
Best Regards
Tao Chen
Powered by blists - more mailing lists