Re: [PATCH 1/2] KVM: X86: Move ignore_msrs handling upper the stack
From: Sean Christopherson
Date: Thu Jun 25 2020 - 02:15:51 EST
On Mon, Jun 22, 2020 at 06:04:41PM -0400, Peter Xu wrote:
> MSR accesses can be one of:
>
> (1) KVM internal access,
> (2) userspace access (e.g., via KVM_SET_MSRS ioctl),
> (3) guest access.
>
> The ignore_msrs was previously handled by kvm_get_msr_common() and
> kvm_set_msr_common(), which is the bottom of the msr access stack. It's
> working in most cases, however it could dump unwanted warning messages to dmesg
> even if kvm get/set the msrs internally when calling __kvm_set_msr() or
> __kvm_get_msr() (e.g. kvm_cpuid()). Ideally we only want to trap cases (2)
> or (3), but not (1) above.
>
> To achieve this, move the ignore_msrs handling upper until the callers of
> __kvm_get_msr() and __kvm_set_msr(). To identify the "msr missing" event, a
> new return value (KVM_MSR_RET_INVALID==2) is used for that.
IMO, kvm_cpuid() is simply buggy. If KVM attempts to access a non-existent
MSR then it darn well should warn.
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 8a294f9747aa..7ef7283011d6 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1013,7 +1013,8 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
*ebx = entry->ebx;
*ecx = entry->ecx;
*edx = entry->edx;
- if (function == 7 && index == 0) {
+ if (function == 7 && index == 0 && (*ebx | (F(RTM) | F(HLE))) &&
+ (vcpu->arch.arch_capabilities & ARCH_CAP_TSX_CTRL_MSR)) {
u64 data;
if (!__kvm_get_msr(vcpu, MSR_IA32_TSX_CTRL, &data, true) &&
(data & TSX_CTRL_CPUID_CLEAR))