Add helpers to track when running in NMI handler context. This is
modeled after the in_irq helpers.
The SDM states that no NMI can be delivered while handling a NMI
until the processor has executed an iret instruction. It's possible
however that another fault is received while handling the NMI (a #MC
for example), and thus the iret from that fault would allow further
NMIs to be injected while still processing the previous one, and
hence an integer is needed in order to keep track of in service NMIs.
The added macros only track when the execution context is in the NMI
handler, but that doesn't mean NMIs are blocked for the reasons listed
above.
Note that there are no users of in_nmi_handler() introduced by the
change, further users will be added by followup changes.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
bool handle_unknown = false;
this_cpu(nmi_count)++;
+ nmi_enter();
if ( nmi_callback(regs, cpu) )
+ {
+ nmi_exit();
return;
+ }
/*
* Accessing port 0x61 may trap to SMM which has been actually
if ( !(reason & 0xc0) && handle_unknown )
unknown_nmi_error(regs, reason);
}
+
+ nmi_exit();
}
nmi_callback_t *set_nmi_callback(nmi_callback_t *callback)
typedef struct {
unsigned int __softirq_pending;
unsigned int __local_irq_count;
+ unsigned int nmi_count;
bool_t __mwait_wakeup;
} __cacheline_aligned irq_cpustat_t;
#define irq_enter() (local_irq_count(smp_processor_id())++)
#define irq_exit() (local_irq_count(smp_processor_id())--)
+#define nmi_count(cpu) __IRQ_STAT(cpu, nmi_count)
+#define in_nmi_handler() (nmi_count(smp_processor_id()) != 0)
+#define nmi_enter() (nmi_count(smp_processor_id())++)
+#define nmi_exit() (nmi_count(smp_processor_id())--)
+
void ack_bad_irq(unsigned int irq);
extern void apic_intr_init(void);