Re: [PATCH v4 2/6] perf: Enqueue SIGTRAP always via task_work.

From: Sebastian Andrzej Siewior
Date: Mon Jul 01 2024 - 09:27:46 EST


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.

Sebastian