[PATCH RFC 09/22] KVM: x86: hyper-v: Honor HV_MSR_SYNIC_AVAILABLE privilege bit

From: Vitaly Kuznetsov
Date: Tue Apr 13 2021 - 08:27:53 EST


SynIC MSRs (HV_X64_MSR_SCONTROL, HV_X64_MSR_SVERSION, HV_X64_MSR_SIEFP,
HV_X64_MSR_SIMP, HV_X64_MSR_EOM, HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15)
are only available to guest when HV_MSR_SYNIC_AVAILABLE bit is exposed.

Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>
---
arch/x86/kvm/hyperv.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 48215ad72b6c..d85c441011c4 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -211,7 +211,9 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic);
int ret;

- if (!synic->active && !host)
+ if (unlikely(!host &&
+ (!synic->active || !(to_hv_vcpu(vcpu)->cpuid_cache.features_eax &
+ HV_MSR_SYNIC_AVAILABLE))))
return 1;

trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host);
@@ -383,9 +385,12 @@ static int syndbg_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host)
static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata,
bool host)
{
+ struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic);
int ret;

- if (!synic->active && !host)
+ if (unlikely(!host &&
+ (!synic->active || !(to_hv_vcpu(vcpu)->cpuid_cache.features_eax &
+ HV_MSR_SYNIC_AVAILABLE))))
return 1;

ret = 0;
--
2.30.2