[tip: perf/core] perf/x86/intel: KVM: Handle cross-mapped PEBS PMCs entirely within KVM

From: tip-bot2 for Sean Christopherson

Date: Fri Sep 25 2026 - 06:48:44 EST


The following commit has been merged into the perf/core branch of tip:

Commit-ID: 31f7cf337ce717666ce29fbd793f06435eb48408
Gitweb: https://git.kernel.org/tip/31f7cf337ce717666ce29fbd793f06435eb48408
Author: Sean Christopherson <seanjc@xxxxxxxxxx>
AuthorDate: Mon, 21 Sep 2026 12:14:15 -07:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Fri, 25 Sep 2026 12:45:53 +02:00

perf/x86/intel: KVM: Handle cross-mapped PEBS PMCs entirely within KVM

Now that perf operates on a KVM-provided snapshot of PMU state, handled
cross-mapped PEBS counters entirely in KVM by clearing unusable counters
from the to-be-enabled mask instead of foisting the work on perf.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260921191418.950933-8-seanjc@xxxxxxxxxx
---
arch/x86/events/intel/core.c | 8 --------
arch/x86/include/asm/perf_event.h | 1 -
arch/x86/kvm/vmx/vmx.c | 10 ++++++++--
3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 87274b3..1bc96b9 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5390,14 +5390,6 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr,
cpuc->intel_ctrl_exclude_host_mask;

/*
- * Disable counters where the guest PMC is different than the host PMC
- * being used on behalf of the guest, as the PEBS record includes
- * PERF_GLOBAL_STATUS, i.e. the guest will see overflow status for the
- * wrong counter(s).
- */
- guest_pebs_mask &= ~guest_pebs->cross_mapped_mask;
-
- /*
* FIXME: Allow guest and host usage of PEBS events to co-exist instead
* of disabling guest PEBS entirely if the host is using PEBS.
* What exactly goes wrong if guest and host are using PEBS is
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
index 27f9c5b..5c92d43 100644
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -823,7 +823,6 @@ struct x86_guest_pebs {
u64 enable;
u64 ds_area;
u64 data_cfg;
- u64 cross_mapped_mask;
};
#if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr,
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index b097db2..8f7d062 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -7369,8 +7369,14 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
.data_cfg = pmu->pebs_data_cfg,
};

- if (pmu->pebs_enable & pmu->global_ctrl)
- guest_pebs.cross_mapped_mask = intel_pmu_get_cross_mapped_mask(pmu);
+ /*
+ * Disable counters where the guest PMC is different than the host PMC
+ * being used on behalf of the guest, as the PEBS record includes
+ * PERF_GLOBAL_STATUS, i.e. the guest will see overflow status for the
+ * wrong counter(s).
+ */
+ if (guest_pebs.enable & pmu->global_ctrl)
+ guest_pebs.enable &= ~intel_pmu_get_cross_mapped_mask(pmu);

/* Note, nr_msrs may be garbage if perf_guest_get_msrs() returns NULL. */
msrs = perf_guest_get_msrs(&nr_msrs, &guest_pebs);