Re: [PATCH v13 01/17] preempt: Track NMI nesting to separate per-CPU counter

Peter Zijlstra
2025-10-14T10:48:58Z

On Mon, Oct 13, 2025 at 11:48:03AM -0400, Lyude Paul wrote:

> #define __nmi_enter() \
> do { \
> lockdep_off(); \
> arch_nmi_enter(); \
> - BUG_ON(in_nmi() == NMI_MASK); \
> - __preempt_count_add(NMI_OFFSET + HARDIRQ_OFFSET); \
> + BUG_ON(__this_cpu_read(nmi_nesting) == UINT_MAX); \
> + __this_cpu_inc(nmi_nesting); \

An NMI that nests from here..

> + __preempt_count_add(HARDIRQ_OFFSET); \
> + if (__this_cpu_read(nmi_nesting) == 1) \

.. until here, will see nmi_nesting > 1 and not set NMI_OFFSET.

> + __preempt_count_add(NMI_OFFSET); \