Re: [PATCH v4 01/39] task_work: Fix TWA_NMI_CURRENT error handling

Peter Zijlstra
2025-01-22T12:28:34Z

On Tue, Jan 21, 2025 at 06:30:53PM -0800, Josh Poimboeuf wrote:
> It's possible for irq_work_queue() to fail if the work has already been
> claimed. That can happen if a TWA_NMI_CURRENT task work is requested
> before a previous TWA_NMI_CURRENT IRQ work on the same CPU has gotten a
> chance to run.

I'm confused, if it fails then it's already pending, and we'll get the
notification already. You can still add the work.

> The error has to be checked before the write to task->task_works. Also
> the try_cmpxchg() loop isn't needed in NMI context. The TWA_NMI_CURRENT
> case really is special, keep things simple by keeping its code all
> together in one place.

NMIs can nest, consider #DB (which is NMI like) doing task_work_add()
and getting interrupted with NMI doing the same.

Might all this be fallout from trying to fix that schedule() bug from
the next patch, because as is, I don't see it.