All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support.
@ 2022-01-19 13:37 Dan Carpenter
  2022-01-26 12:11 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2022-01-19 13:37 UTC (permalink / raw)
  To: bigeasy; +Cc: linux-perf-users

Hello Sebastian Andrzej Siewior,

The patch 810979682ccc: "irq_work: Allow irq_work_sync() to sleep if
irq_work() no IRQ support." from Oct 6, 2021, leads to the following
Smatch static checker warning:

	kernel/events/core.c:4955 _free_event()
	warn: sleeping in atomic context

There are two potential call trees where preemption is disabled.

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()

_free_event() calls irq_work_sync() which can now sleep.

regards,
dan carpenter


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

* Re: [bug report] irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support.
  2022-01-19 13:37 [bug report] irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support Dan Carpenter
@ 2022-01-26 12:11 ` Sebastian Andrzej Siewior
  2022-01-26 13:24   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-01-26 12:11 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-perf-users, Peter Zijlstra, Thomas Gleixner

+peterz, tglx

On 2022-01-19 16:37:29 [+0300], Dan Carpenter wrote:
> Hello Sebastian Andrzej Siewior,
> 
> The patch 810979682ccc: "irq_work: Allow irq_work_sync() to sleep if
> irq_work() no IRQ support." from Oct 6, 2021, leads to the following
> Smatch static checker warning:
> 
> 	kernel/events/core.c:4955 _free_event()
> 	warn: sleeping in atomic context
> 
> There are two potential call trees where preemption is disabled.
> 
> perf_remove_from_context() <- disables preempt
 raw_spin_lock_irq(&ctx->lock)

> __perf_event_exit_context() <- disables preempt
don't see additional one.

> -> __perf_remove_from_context()
>    -> perf_group_detach()
>       -> perf_put_aux_event()
>          -> put_event()
>             -> _free_event()
> 
> _free_event() calls irq_work_sync() which can now sleep.

That is true. There is also 
|	if (event->rb) 
|		mutex_lock(&event->mmap_mutex);

Can we somehow delay the whole thing? There are also kfree() and
spinlock_t usage which are not very RT compatible with disabled
preemption.

> regards,
> dan carpenter

Sebastian

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

* Re: [bug report] irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support.
  2022-01-26 12:11 ` Sebastian Andrzej Siewior
@ 2022-01-26 13:24   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-01-26 13:24 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-perf-users, Peter Zijlstra, Thomas Gleixner

On Wed, Jan 26, 2022 at 01:11:13PM +0100, Sebastian Andrzej Siewior wrote:
> 
> > __perf_event_exit_context() <- disables preempt
> don't see additional one.
> 
> > -> __perf_remove_from_context()

In linux-next perf_remove_from_context() calls raw_spin_lock() which
disabled preemption.

kernel/events/core.c
 13343        static void __perf_event_exit_context(void *__info)
 13344        {
 13345                struct perf_event_context *ctx = __info;
 13346                struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
 13347                struct perf_event *event;
 13348
 13349                raw_spin_lock(&ctx->lock);
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
 13350                ctx_sched_out(ctx, cpuctx, EVENT_TIME);
 13351                list_for_each_entry(event, &ctx->event_list, event_entry)
 13352                        __perf_remove_from_context(event, cpuctx, ctx, (void *)DETACH_GROUP);
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 13353                raw_spin_unlock(&ctx->lock);
 13354        }

regards,
dan carpenter

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

end of thread, other threads:[~2022-01-26 13:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19 13:37 [bug report] irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support Dan Carpenter
2022-01-26 12:11 ` Sebastian Andrzej Siewior
2022-01-26 13:24   ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.