Skip to content

Commit d75cac3

Browse files
committed
KVM: x86: Reject userspace attempts to access PERF_CAPABILITIES w/o PDCM
Reject userspace accesses to PERF_CAPABILITIES if PDCM isn't set in guest CPUID, i.e. if the vCPU doesn't actually have PERF_CAPABILITIES. But! Do so via KVM_MSR_RET_UNSUPPORTED, so that reads get '0' and writes of '0' are ignored if KVM advertised support PERF_CAPABILITIES. KVM's ABI is that userspace must set guest CPUID prior to setting MSRs, and that setting MSRs that aren't supposed exist is disallowed (modulo the '0' exemption). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent dcb988c commit d75cac3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

arch/x86/kvm/x86.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,8 +3800,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
38003800
vcpu->arch.arch_capabilities = data;
38013801
break;
38023802
case MSR_IA32_PERF_CAPABILITIES:
3803-
if (!msr_info->host_initiated)
3804-
return 1;
3803+
if (!msr_info->host_initiated ||
3804+
!guest_cpuid_has(vcpu, X86_FEATURE_PDCM))
3805+
return KVM_MSR_RET_UNSUPPORTED;
3806+
38053807
if (data & ~kvm_caps.supported_perf_cap)
38063808
return 1;
38073809

@@ -4260,9 +4262,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
42604262
msr_info->data = vcpu->arch.arch_capabilities;
42614263
break;
42624264
case MSR_IA32_PERF_CAPABILITIES:
4263-
if (!msr_info->host_initiated &&
4264-
!guest_cpuid_has(vcpu, X86_FEATURE_PDCM))
4265-
return 1;
4265+
if (!guest_cpuid_has(vcpu, X86_FEATURE_PDCM))
4266+
return KVM_MSR_RET_UNSUPPORTED;
42664267
msr_info->data = vcpu->arch.perf_capabilities;
42674268
break;
42684269
case MSR_IA32_POWER_CTL:

0 commit comments

Comments
 (0)