]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf/x86/core: Register a new vector for handling mediated guest PMIs
authorSean Christopherson <seanjc@google.com>
Sat, 6 Dec 2025 00:16:44 +0000 (16:16 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 17 Dec 2025 12:31:05 +0000 (13:31 +0100)
commita05385d84b2af64600fc84b027bea481e8f6261d
tree0789f4c72d46f3fbba96b30c07a2a31341196885
parent42457a7fb6cacca83be4deaf202ac3e45830daf2
perf/x86/core: Register a new vector for handling mediated guest PMIs

Wire up system vector 0xf5 for handling PMIs (i.e. interrupts delivered
through the LVTPC) while running KVM guests with a mediated PMU.  Perf
currently delivers all PMIs as NMIs, e.g. so that events that trigger while
IRQs are disabled aren't delayed and generate useless records, but due to
the multiplexing of NMIs throughout the system, correctly identifying NMIs
for a mediated PMU is practically infeasible.

To (greatly) simplify identifying guest mediated PMU PMIs, perf will
switch the CPU's LVTPC between PERF_GUEST_MEDIATED_PMI_VECTOR and NMI when
guest PMU context is loaded/put.  I.e. PMIs that are generated by the CPU
while the guest is active will be identified purely based on the IRQ
vector.

Route the vector through perf, e.g. as opposed to letting KVM attach a
handler directly a la posted interrupt notification vectors, as perf owns
the LVTPC and thus is the rightful owner of PERF_GUEST_MEDIATED_PMI_VECTOR.
Functionally, having KVM directly own the vector would be fine (both KVM
and perf will be completely aware of when a mediated PMU is active), but
would lead to an undesirable split in ownership: perf would be responsible
for installing the vector, but not handling the resulting IRQs.

Add a new perf_guest_info_callbacks hook (and static call) to allow KVM to
register its handler with perf when running guests with mediated PMUs.

Note, because KVM always runs guests with host IRQs enabled, there is no
danger of a PMI being delayed from the guest's perspective due to using a
regular IRQ instead of an NMI.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Xudong Hao <xudong.hao@intel.com>
Link: https://patch.msgid.link/20251206001720.468579-9-seanjc@google.com
arch/x86/entry/entry_fred.c
arch/x86/include/asm/hardirq.h
arch/x86/include/asm/idtentry.h
arch/x86/include/asm/irq_vectors.h
arch/x86/kernel/idt.c
arch/x86/kernel/irq.c
include/linux/perf_event.h
kernel/events/core.c
tools/perf/trace/beauty/arch/x86/include/asm/irq_vectors.h
virt/kvm/kvm_main.c