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

Josh Poimboeuf
2025-01-23T17:15:12Z

On Thu, Jan 23, 2025 at 09:14:03AM +0100, Peter Zijlstra wrote:
> On Wed, Jan 22, 2025 at 12:47:20PM -0800, Josh Poimboeuf wrote:
> > What exactly do you mean by "NMI like"? Is it because a #DB might be
> > basically running in NMI context, if the NMI hit a breakpoint?
>
> No, #DB, #BP and such are considered NMI (and will have in_nmi() true)
> because they can trigger anywhere, including sections where IRQs are
> disabled.

So:

- while exceptions are technically not NMI, they're "NMI" because they
can occur in NMI or IRQ-disabled regions

- such "NMI" exceptions can be preempted by NMIs and "NMIs"

- NMIs can be preempted by "NMIs" but not NMIs (except in entry code!)

... did I get all that right? Not subtle at all!

I feel like in_nmi() needs a comment explaining all that nonobviousness.

--
Josh