Skip to content

Commit aaecae7

Browse files
committed
KVM: x86: Rename KVM_MSR_RET_INVALID to KVM_MSR_RET_UNSUPPORTED
Rename the "INVALID" internal MSR error return code to "UNSUPPORTED" to try and make it more clear that access was denied because the MSR itself is unsupported/unknown. "INVALID" is too ambiguous, as it could just as easily mean the value for WRMSR as invalid. Avoid UNKNOWN and UNIMPLEMENTED, as the error code is used for MSRs that _are_ actually implemented by KVM, e.g. if the MSR is unsupported because an associated feature flag is not present in guest CPUID. Opportunistically beef up the comments for the internal MSR error codes. Link: https://lore.kernel.org/r/20240802181935.292540-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b58b808 commit aaecae7

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2835,7 +2835,7 @@ static int svm_get_msr_feature(struct kvm_msr_entry *msr)
28352835
msr->data |= MSR_AMD64_DE_CFG_LFENCE_SERIALIZE;
28362836
break;
28372837
default:
2838-
return KVM_MSR_RET_INVALID;
2838+
return KVM_MSR_RET_UNSUPPORTED;
28392839
}
28402840

28412841
return 0;

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ int vmx_get_msr_feature(struct kvm_msr_entry *msr)
20062006
return 1;
20072007
return vmx_get_vmx_msr(&vmcs_config.nested, msr->index, &msr->data);
20082008
default:
2009-
return KVM_MSR_RET_INVALID;
2009+
return KVM_MSR_RET_UNSUPPORTED;
20102010
}
20112011
}
20122012

arch/x86/kvm/x86.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
16871687
msr.index = index;
16881688
r = kvm_get_msr_feature(&msr);
16891689

1690-
if (r == KVM_MSR_RET_INVALID && kvm_msr_ignored_check(index, 0, false))
1690+
if (r == KVM_MSR_RET_UNSUPPORTED && kvm_msr_ignored_check(index, 0, false))
16911691
r = 0;
16921692

16931693
*data = msr.data;
@@ -1884,7 +1884,7 @@ static int kvm_set_msr_ignored_check(struct kvm_vcpu *vcpu,
18841884
{
18851885
int ret = __kvm_set_msr(vcpu, index, data, host_initiated);
18861886

1887-
if (ret == KVM_MSR_RET_INVALID)
1887+
if (ret == KVM_MSR_RET_UNSUPPORTED)
18881888
if (kvm_msr_ignored_check(index, data, true))
18891889
ret = 0;
18901890

@@ -1929,7 +1929,7 @@ static int kvm_get_msr_ignored_check(struct kvm_vcpu *vcpu,
19291929
{
19301930
int ret = __kvm_get_msr(vcpu, index, data, host_initiated);
19311931

1932-
if (ret == KVM_MSR_RET_INVALID) {
1932+
if (ret == KVM_MSR_RET_UNSUPPORTED) {
19331933
/* Unconditionally clear *data for simplicity */
19341934
*data = 0;
19351935
if (kvm_msr_ignored_check(index, 0, false))
@@ -1998,7 +1998,7 @@ static int complete_fast_rdmsr(struct kvm_vcpu *vcpu)
19981998
static u64 kvm_msr_reason(int r)
19991999
{
20002000
switch (r) {
2001-
case KVM_MSR_RET_INVALID:
2001+
case KVM_MSR_RET_UNSUPPORTED:
20022002
return KVM_MSR_EXIT_REASON_UNKNOWN;
20032003
case KVM_MSR_RET_FILTERED:
20042004
return KVM_MSR_EXIT_REASON_FILTER;
@@ -4146,7 +4146,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
41464146
kvm_is_msr_to_save(msr))
41474147
break;
41484148

4149-
return KVM_MSR_RET_INVALID;
4149+
return KVM_MSR_RET_UNSUPPORTED;
41504150
}
41514151
return 0;
41524152
}
@@ -4507,7 +4507,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
45074507
break;
45084508
}
45094509

4510-
return KVM_MSR_RET_INVALID;
4510+
return KVM_MSR_RET_UNSUPPORTED;
45114511
}
45124512
return 0;
45134513
}

arch/x86/kvm/x86.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,18 @@ enum kvm_msr_access {
512512

513513
/*
514514
* Internal error codes that are used to indicate that MSR emulation encountered
515-
* an error that should result in #GP in the guest, unless userspace
516-
* handles it.
515+
* an error that should result in #GP in the guest, unless userspace handles it.
516+
* Note, '1', '0', and negative numbers are off limits, as they are used by KVM
517+
* as part of KVM's lightly documented internal KVM_RUN return codes.
518+
*
519+
* UNSUPPORTED - The MSR isn't supported, either because it is completely
520+
* unknown to KVM, or because the MSR should not exist according
521+
* to the vCPU model.
522+
*
523+
* FILTERED - Access to the MSR is denied by a userspace MSR filter.
517524
*/
518-
#define KVM_MSR_RET_INVALID 2 /* in-kernel MSR emulation #GP condition */
519-
#define KVM_MSR_RET_FILTERED 3 /* #GP due to userspace MSR filter */
525+
#define KVM_MSR_RET_UNSUPPORTED 2
526+
#define KVM_MSR_RET_FILTERED 3
520527

521528
#define __cr4_reserved_bits(__cpu_has, __c) \
522529
({ \

0 commit comments

Comments
 (0)