[tip: perf/core] perf/x86/intel: Check only PMC bits in PEBS_ENABLED when detecting host PEBS usage
From: tip-bot2 for Sean Christopherson
Date: Fri Sep 25 2026 - 06:48:36 EST
The following commit has been merged into the perf/core branch of tip:
Commit-ID: ba29babd881e09a7bb8b01fcfeda3d637d8115c5
Gitweb: https://git.kernel.org/tip/ba29babd881e09a7bb8b01fcfeda3d637d8115c5
Author: Sean Christopherson <seanjc@xxxxxxxxxx>
AuthorDate: Mon, 21 Sep 2026 12:14:18 -07:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Fri, 25 Sep 2026 12:45:54 +02:00
perf/x86/intel: Check only PMC bits in PEBS_ENABLED when detecting host PEBS usage
When checking to see if guest PEBS usage should be disabled due to host
PEBS usage, filter out non-counter bits in PEBS_ENABLE to avoid getting
false positives in the unlikely scenario that "Enable Precise Store" is
enabled without PEBS actually being active for any PMCs.
Note, the other "hidden" usage of pebs_mask is already explicitly masked
with intel_ctrl:
.guest = intel_ctrl & ~cpuc->intel_ctrl_exclude_guest_mask & ~pebs_mask,
I.e. removing the non-counter bits from pebs_mask doesn't change the value
that is loaded into arr[global_ctrl].guest.
Fixes: 854250329c02 ("KVM: x86/pmu: Disable guest PEBS temporarily in two rare situations")
Closes: https://lore.kernel.org/all/20260508234018.F06AEC2BCB0@xxxxxxxxxxxxxxx
Reported-by: Sashiko Bot <sashiko-bot@xxxxxxxxxx>
Suggested-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
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-11-seanjc@xxxxxxxxxx
---
arch/x86/events/intel/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 1bc96b9..0a34d67 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5333,7 +5333,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr,
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
u64 intel_ctrl = hybrid(cpuc->pmu, intel_ctrl);
- u64 pebs_mask = cpuc->pebs_enabled & x86_pmu.pebs_capable;
+ u64 pebs_mask = intel_ctrl & cpuc->pebs_enabled & x86_pmu.pebs_capable;
u64 guest_pebs_mask;
int global_ctrl;
@@ -5385,7 +5385,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr,
* the guest wants to use for PEBS, (c) are not excluded from counting
* in the guest, and (d) _are_ excluded from counting in the host.
*/
- guest_pebs_mask = pebs_mask & intel_ctrl & guest_pebs->enable &
+ guest_pebs_mask = pebs_mask & guest_pebs->enable &
~cpuc->intel_ctrl_exclude_guest_mask &
cpuc->intel_ctrl_exclude_host_mask;