]> www.infradead.org Git - users/jedix/linux-maple.git/commit
perf: Fix failing inherit_event() doing extra refcount decrement on parent
authorFrederic Weisbecker <frederic@kernel.org>
Thu, 24 Apr 2025 16:11:25 +0000 (18:11 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 8 May 2025 19:50:18 +0000 (21:50 +0200)
commit22d38babb3adcb1227ecfb91d9423008a46548fe
treeae88b4dcb54d5e841b537b7eea797523d9ce3cfa
parent3e830f657f69ab6a4822d72ec2f364c6d51beef8
perf: Fix failing inherit_event() doing extra refcount decrement on parent

When inherit_event() fails after the child allocation but before the
parent refcount has been incremented, calling put_event() wrongly
decrements the reference to the parent, risking to free it too early.

Also pmu_get_event() can't be holding a reference to the child
concurrently at this point since it is under pmus_srcu critical section.

Fix it with restoring the deleted free_event() function and call it on
the failing child in order to free it directly under the verified
assumption that its refcount is only 1. The refcount to the parent is
then voluntarily omitted.

Fixes: da916e96e2de ("perf: Make perf_pmu_unregister() useable")
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250424161128.29176-2-frederic@kernel.org
kernel/events/core.c