In preparation for supporting AnyThread deprecation and RDPMC Metrics Clear Mode, mask only INTEL_FIXED_0_KERNEL and INTEL_FIXED_0_USER when updating fixed_ctr_ctrl_hw in kvm_mediated_pmu_refresh_event_filter(). Masking the full 0xf nibble would cause two issues: 1. AnyThread for fixed counters 0-2: When a counter is allowed, copying the full nibble from guest-visible pmu->fixed_ctr_ctrl back into hardware-visible pmu->fixed_ctr_ctrl_hw would resurrect AnyThread in hardware, defeating SMT cross-VM isolation. 2. Metrics Clear for fixed counter 3: If an event filter denies fixed counter 3, clearing 0xf inadvertently strips METRICS_CLEAR_EN from hardware. If the guest sets METRICS_CLEAR_EN and executes native RDPMC, metrics will remain uncleared, returning stale data. Masking only the OS/USR bits gates hardware counting without clobbering other control bits, matching general-purpose counter filtering which only masks the event ENABLE bit. Suggested-by: Dapeng Mi Signed-off-by: Zide Chen Reviewed-by: Jim Mattson --- v10: - New patch split from "KVM: x86/pmu: Support RDPMC Metrics Clear Mode". --- arch/x86/kvm/pmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index eef2f792dc9e..dba651d4e449 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -557,7 +557,10 @@ static void kvm_mediated_pmu_refresh_event_filter(struct kvm_pmc *pmc) pmc->eventsel_hw |= pmc->eventsel & ARCH_PERFMON_EVENTSEL_ENABLE; } else { - u64 mask = intel_fixed_bits_by_idx(pmc->idx - KVM_FIXED_PMC_BASE_IDX, 0xf); + u64 mask; + + mask = intel_fixed_bits_by_idx(pmc->idx - KVM_FIXED_PMC_BASE_IDX, + INTEL_FIXED_0_KERNEL | INTEL_FIXED_0_USER); pmu->fixed_ctr_ctrl_hw &= ~mask; if (allowed) -- 2.56.1