Re: [PATCH v3 15/18] KVM: x86/pmu: Mask only OS/USR bits when filtering fixed counters

From: Jim Mattson

Date: Fri Nov 06 2026 - 16:19:33 EST


On Thu, Nov 5, 2026 at 5:50 PM Zide Chen <zide.chen@xxxxxxxxx> wrote:
>
> In preparation for supporting AnyThread deprecation and Fixed Counter 3,
> 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 un-cleared, returning stale data.
>
> This gates hardware counting without clobbering other control bits,
> matching general-purpose counter filtering which only masks the event
> ENABLE bit.
>
> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>