Re: [PATCH v4 2/6] perf: Enqueue SIGTRAP always via task_work.
From: Peter Zijlstra
Date: Tue Jul 02 2024 - 05:02:05 EST
On Mon, Jul 01, 2024 at 03:27:25PM +0200, Sebastian Andrzej Siewior wrote:
> On 2024-07-01 14:28:29 [+0200], Peter Zijlstra wrote:
> > On Mon, Jun 24, 2024 at 05:15:15PM +0200, Sebastian Andrzej Siewior wrote:
> > > @@ -9735,18 +9719,28 @@ static int __perf_event_overflow(struct perf_event *event,
> > >
> > > if (regs)
> > > pending_id = hash32_ptr((void *)instruction_pointer(regs)) ?: 1;
> > > - if (!event->pending_sigtrap) {
> > > - event->pending_sigtrap = pending_id;
> > > +
> > > + if (!event->pending_work &&
> > > + !task_work_add(current, &event->pending_task, TWA_RESUME)) {
> > > + event->pending_work = pending_id;
> > > local_inc(&event->ctx->nr_pending);
> >
> > task_work_add() isn't NMI safe, at the very least the
> > kasan_record_aux_stack() thing needs to go. But the whole
> > set_notify_resume() thing also needs an audit.
>
> oh. I just peeked and set_notify_resume() wouldn't survive the audit.
> Would you mind adding task_work_add_nmi() which is task_work_add(,
> TWA_NONE) without kasan_record_aux_stack()? The signal part would need
> to be moved the irq_work() below in the NMI case.
Perhaps add TWA_NMI_CURRENT or somesuch. That would be descriptive and
the value can be used to elide the call to kasan*() and possibly also
include that self-IPI for the NMI-from-user case where we don't have a
return-to-user path.
It can also verify task == current, which ensures people don't try and
use it for other things.