core2_intr() claims an NMI only when IA_GLOBAL_STATUS shows an
overflow. It re-enables the LAPIC PMC vector before acking the
status bits, so a PMI raised while the handler runs can latch a
second NMI that finds the status already clear. That NMI goes
unclaimed and, with the default machdep.panic_on_nmi, panics the
machine. hwpmc_amd.c already absorbs such NMIs with a per-CPU
nmi_counter.
Give core2_intr() one credit per serviced PMI and spend it on the
next NMI on that CPU that finds no overflow.
Reproduced on a Xeon D-1518 (Broadwell-DE) running system-wide
CPU_CYCLES sampling: the unpatched kernel panicked with "NMI" after
about 47k PMIs. With this change it ran 12.5 hours (485k PMIs),
absorbed 6 empty NMIs, and did not panic.
Sponsored by: Netflix