Re: [PATCH v2 24/24] perf: Make perf_pmu_unregister() useable

From: Ravi Bangoria
Date: Wed Feb 19 2025 - 09:33:02 EST


>>>>> Apparently not, it ends up with:
>>>>>
>>>>> ------------[ cut here ]------------
>>>>> WARNING: CPU: 145 PID: 5459 at kernel/events/core.c:281 event_function+0xd2/0xf0
>>>>> WARNING: CPU: 145 PID: 5459 at kernel/events/core.c:286 event_function+0xd6/0xf0
>>>>
>>>>> remote_function+0x4f/0x70
>>>>> generic_exec_single+0x7f/0x160
>>>>> smp_call_function_single+0x110/0x160
>>>>> event_function_call+0x98/0x1d0
>>>>> _perf_event_disable+0x41/0x70
>>>>> perf_event_for_each_child+0x40/0x90
>>>>> _perf_ioctl+0xac/0xb00
>>>>> perf_ioctl+0x45/0x80
>>>>
>>>> Took me a long while trying to blame this on the 'event->parent =
>>>> NULL;', but AFAICT this is a new, unrelated issue.
>>>>
>>>> What I think happens is this perf_ioctl(DISABLE) vs pmu_detach_events()
>>>> race, where the crux is that perf_ioctl() path does not take
>>>> event2->mutex which allows the following interleave:
>>>
>>> This one was only with perf_fuzzer, so pmu_detach_events() code path was
>>> not invoked.
>>
>> I think the issue is, unaccount_event() gets called for the child event
>> after the child is detached. Since event->parent is NULL, unaccount_event()
>> abruptly corrupts the perf_sched_work.
>
> A different manifestation of the same underlying issue (perf_sched_work
> is getting corrupted because of event->parent = NULL):

Duh! I meant perf_sched_events gets corrupted by invoking perf_sched_work.

Thanks,
Ravi