linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] perf: Fix event leak upon exec and file release
@ 2024-08-23 13:43 Dan Carpenter
  2024-09-02 21:47 ` Frederic Weisbecker
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2024-08-23 13:43 UTC (permalink / raw)
  To: Frederic Weisbecker; +Cc: linux-perf-users

Hello Frederic Weisbecker,

Commit 3a5465418f5f ("perf: Fix event leak upon exec and file
release") from Jun 21, 2024 (linux-next), leads to the following
Smatch static checker warning:

	kernel/events/core.c:5301 perf_pending_task_sync()
	warn: sleeping in atomic context

kernel/events/core.c
    5280 static void perf_pending_task_sync(struct perf_event *event)
    5281 {
    5282         struct callback_head *head = &event->pending_task;
    5283 
    5284         if (!event->pending_work)
    5285                 return;
    5286         /*
    5287          * If the task is queued to the current task's queue, we
    5288          * obviously can't wait for it to complete. Simply cancel it.
    5289          */
    5290         if (task_work_cancel(current, head)) {
    5291                 event->pending_work = 0;
    5292                 local_dec(&event->ctx->nr_no_switch_fast);
    5293                 return;
    5294         }
    5295 
    5296         /*
    5297          * All accesses related to the event are within the same RCU section in
    5298          * perf_pending_task(). The RCU grace period before the event is freed
    5299          * will make sure all those accesses are complete by then.
    5300          */
--> 5301         rcuwait_wait_event(&event->pending_work_wait, !event->pending_work, TASK_UNINTERRUPTIBLE);
                         ^^^^^^^^^^
The commit adds a sleep

    5302 }

Smatch is complaining about four call trees which are holding a spinlock.

One:
pl330_free_chan_resources() <- disables preempt
-> pl330_release_channel()
   -> _free_event()
      -> perf_pending_task_sync()

Two and three:
perf_remove_from_context() <- disables preempt
__perf_event_exit_context() <- disables preempt
-> __perf_remove_from_context()
   -> perf_group_detach()
      -> perf_put_aux_event()
         -> put_event()
            -> _free_event()
               -> perf_pending_task_sync()

Four:
perf_free_event() <- disables preempt
-> perf_group_detach()
   -> perf_put_aux_event()
      -> put_event()
         -> _free_event()
            -> perf_pending_task_sync()


This check tends to have more false positive when the call tree is long.  For
example, maybe event->pending_work is always zero or something.  I've looked it
over, but I'm a newbie to this code.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-02 14:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-23 13:43 [bug report] perf: Fix event leak upon exec and file release Dan Carpenter
2024-09-02 21:47 ` Frederic Weisbecker
2024-09-30  9:04   ` Sebastian Andrzej Siewior
2024-10-02 13:51     ` Frederic Weisbecker
2024-10-02 14:57       ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).