On Tue, Sep 22, 2026 at 09:54:51AM +0800, Ewan Hai-oc wrote: > On Fri, Sep 11, 2026 at 09:19:51AM -0700, Sean Christopherson wrote: > > On Thu, Sep 10, 2026, Ewan Hai-oc wrote: > > > From: Frank Zhu <[email protected]> > > > > > > KVM allows userspace to query MSR_IA32_PERF_CAPABILITIES through > > > KVM_GET_MSRS even when PDCM is not exposed in KVM_GET_SUPPORTED_CPUID. > > > However, vCPU accesses to the MSR fail without PDCM. > > > > Hrm, no, KVM is supposed to allow reads and drop writes of '0' for MSRs > > that are > > advertised to userspace, but ultimately unsupported. I'm pretty sure this > > is a > > KVM bug. I think MSR_IA32_ARCH_CAPABILITIES is also affected. > > > > Completely untested, but I think this? > > > > diff --git a/arch/x86/kvm/msrs.c b/arch/x86/kvm/msrs.c > > index dd3bb04878ca..fa77cfdbda7e 100644 > > --- a/arch/x86/kvm/msrs.c > > +++ b/arch/x86/kvm/msrs.c > > @@ -512,9 +512,15 @@ static int kvm_get_feature_msr(struct kvm_vcpu *vcpu, > > u32 index, u64 *data, > > > > switch (index) { > > case MSR_IA32_ARCH_CAPABILITIES: > > + if (!kvm_cpu_cap_has(X86_FEATURE_ARCH_CAPABILITIES)) > > + return KVM_MSR_RET_UNSUPPORTED; > > + > > *data = kvm_get_arch_capabilities(); > > break; > > case MSR_IA32_PERF_CAPABILITIES: > > + if (!kvm_cpu_cap_has(X86_FEATURE_PDCM)) > > + return KVM_MSR_RET_UNSUPPORTED; > > + > > *data = kvm_caps.supported_perf_cap; > > break; > > case MSR_PLATFORM_INFO: > > > > I saw that you applied eight patches from the series to the kvm-x86 > selftests branch and skipped patch 6 as a KVM bug. > > We are testing the change you suggested on Zhaoxin systems with and > without PDCM support. We expect to report the results within the next > few weeks. >
Hi Sean, Frank tested your suggested change on Zhaoxin systems **without** PDCM, using kvm_intel. The results support the fix. MSR_IA32_PERF_CAPABILITIES is no longer listed in KVM_GET_MSR_FEATURE_INDEX_LIST. A direct KVM_GET_MSRS query on the /dev/kvm fd still succeeds, with the MSR data changing from 0x2000 to 0 through the existing unsupported-MSR handling. The MSR remains in KVM_GET_MSR_INDEX_LIST, and the existing vCPU userspace behavior of allowing reads of zero and writes of zero is unchanged. We also checked the QEMU behavior. With the MSR absent from the feature list, QEMU's supported-feature query returns zero for PERF_CAPABILITIES. The PDCM bit in KVM_GET_SUPPORTED_CPUID is unchanged and was already clear on these systems. QEMU filters PDCM out of CPU models that request it, so this resolves our concern about the effect on CPU model selection. feature_msrs_test passes with the change. vmx_pmu_caps_test is skipped on these systems, and the other KVM selftests we ran showed no regressions. Our hardware testing covered systems without PDCM; we have not validated the change on PDCM-capable hardware. One observation about the ARCH_CAPABILITIES check: in the code we checked, EMULATED_F(ARCH_CAPABILITIES) already enables the capability unconditionally, so the new check does not change its behavior. Thanks, Ewan > Thanks for applying the patches and for looking into the patch 6 issue. >
