Re: [PATCH v4 13/21] KVM: x86/pmu: Emulate IA32_PERF_GLOBAL_STATUS_SET MSR

From: Yosry Ahmed

Date: Wed Nov 18 2026 - 11:13:06 EST


On Thu, Nov 12, 2026 at 01:32:19PM -0700, Zide Chen wrote:
> Intel PerfMon v4 introduces IA32_PERF_GLOBAL_STATUS_SET (0x391) to
> allow software to set individual bits in the global status MSR. Reads
> of IA32_PERF_GLOBAL_STATUS_SET always return zero.
>
> IA32_PERF_GLOBAL_STATUS_SET is not part of the VM state, so it doesn't
> need to be advertised to userspace, nor saved and restored during live
> migration.
>
> Always intercept IA32_PERF_GLOBAL_STATUS_SET to prevent the guest from
> modifying status bits that are not virtualized by KVM.
>
> Bit 63 (CondChgd) is architecturally reserved in STATUS_SET per the SDM.
> Reject writes to bit 63, injecting #GP for guest writes. While older
> processors had silicon errata that accepted writes without #GP (e.g.
> SKX95), strictly enforce the architectural specification for
> deterministic behavior across migrations.
>
> Originally-by: Yang Weijiang <weijiang.yang@xxxxxxxxx>
> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
> ---
> v4:
> - Split out CondChgd specific handling into a separate patch since it
> impacts MSR 0x38e and 0x390 as well.
> - Move the defensive filtering code in pmu load to the new patch.
> - Do not carry over Jim's Reviewed-by due to above changes.
>
> v3:
> - Split from combined v2 patch into standalone GLOBAL_STATUS_SET patch.
> - Always intercept IA32_PERF_GLOBAL_STATUS_SET to prevent passthrough of
> unvirtualized status bits. (Jim)
> - Reject writing bit 63 (CondChgd) to IA32_PERF_GLOBAL_STATUS_SET. (Jim)
> - Filter out bit 63 before writing to hardware in
> intel_mediated_pmu_load().
> - Store status set bits in a local variable in
> intel_mediated_pmu_load(). (Yosry)
> - Move validation for MSR_CORE_PERF_GLOBAL_STATUS_SET to pmu_intel.c
> rather than common pmu.c to avoid exposing the Intel MSR on AMD.
> ---
> arch/x86/kvm/pmu.c | 7 +++++++
> arch/x86/kvm/vmx/pmu_intel.c | 2 ++
> 2 files changed, 9 insertions(+)
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index 7ba1a3b38184..bd5954e62080 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -855,6 +855,7 @@ int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> case MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR:
> case MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_SET:
> case MSR_CORE_PERF_GLOBAL_OVF_CTRL:
> + case MSR_CORE_PERF_GLOBAL_STATUS_SET:
> msr_info->data = 0;
> break;
> default:
> @@ -923,6 +924,12 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> if (!msr_info->host_initiated)
> pmu->global_status &= ~data;
> break;
> + case MSR_CORE_PERF_GLOBAL_STATUS_SET:
> + if (data & pmu->global_status_rsvd)
> + return 1;
> + if (!msr_info->host_initiated)
> + pmu->global_status |= data;
> + break;

Nit: Perhaps we should follow what MSR_CORE_PERF_GLOBAL_OVF_CTRL does
and fallthrough, leaving the pmu->global_status update shared with
MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_SET.

> case MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_SET:
> if (!msr_info->host_initiated)
> pmu->global_status |= data & ~pmu->global_status_rsvd;
> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> index 4d05ec50f24f..c18d24b5c385 100644
> --- a/arch/x86/kvm/vmx/pmu_intel.c
> +++ b/arch/x86/kvm/vmx/pmu_intel.c
> @@ -196,6 +196,8 @@ static bool intel_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr)
> case MSR_CORE_PERF_GLOBAL_OVF_CTRL:
> case MSR_CORE_PERF_FIXED_CTR_CTRL:
> return kvm_pmu_has_perf_global_ctrl(pmu);
> + case MSR_CORE_PERF_GLOBAL_STATUS_SET:
> + return pmu->version >= 4;
> case MSR_IA32_PEBS_ENABLE:
> ret = vcpu_get_perf_capabilities(vcpu) & PERF_CAP_PEBS_FORMAT;
> break;
> --
> 2.56.1
>