Skip to content

Commit 219ce2b

Browse files
Tao ChenKernel Patches Daemon
authored andcommitted
perf: Add atomic operation in get_recursion_context
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 <[email protected]> Signed-off-by: Tao Chen <[email protected]>
1 parent 98f9cad commit 219ce2b

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

kernel/events/internal.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,9 @@ static inline int get_recursion_context(u8 *recursion)
214214
{
215215
unsigned char rctx = interrupt_context_level();
216216

217-
if (recursion[rctx])
217+
if (cmpxchg(&recursion[rctx], 0, 1) != 0)
218218
return -1;
219219

220-
recursion[rctx]++;
221-
barrier();
222-
223220
return rctx;
224221
}
225222

0 commit comments

Comments
 (0)