KVM: x86: hyper-v: Prepare to check access to Hyper-V MSRs
authorVitaly Kuznetsov <vkuznets@redhat.com>
Fri, 21 May 2021 09:51:38 +0000 (11:51 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 17 Jun 2021 17:09:39 +0000 (13:09 -0400)
Introduce hv_check_msr_access() to check if the particular MSR
should be accessible by guest, this will be used with
KVM_CAP_HYPERV_ENFORCE_CPUID mode.

No functional change intended.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210521095204.2161214-5-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/hyperv.c

index 7e7928fc77ef1e70d5c75e5a4e478bad7656dcb8..ab8dc23f05bf6e0b9ae4394f41072b02a8fddc87 100644 (file)
@@ -1202,12 +1202,21 @@ out_unlock:
        mutex_unlock(&hv->hv_lock);
 }
 
+
+static bool hv_check_msr_access(struct kvm_vcpu_hv *hv_vcpu, u32 msr)
+{
+       return true;
+}
+
 static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,
                             bool host)
 {
        struct kvm *kvm = vcpu->kvm;
        struct kvm_hv *hv = to_kvm_hv(kvm);
 
+       if (unlikely(!host && !hv_check_msr_access(to_hv_vcpu(vcpu), msr)))
+               return 1;
+
        switch (msr) {
        case HV_X64_MSR_GUEST_OS_ID:
                hv->hv_guest_os_id = data;
@@ -1336,6 +1345,9 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
 {
        struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
 
+       if (unlikely(!host && !hv_check_msr_access(hv_vcpu, msr)))
+               return 1;
+
        switch (msr) {
        case HV_X64_MSR_VP_INDEX: {
                struct kvm_hv *hv = to_kvm_hv(vcpu->kvm);
@@ -1450,6 +1462,9 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
        struct kvm *kvm = vcpu->kvm;
        struct kvm_hv *hv = to_kvm_hv(kvm);
 
+       if (unlikely(!host && !hv_check_msr_access(to_hv_vcpu(vcpu), msr)))
+               return 1;
+
        switch (msr) {
        case HV_X64_MSR_GUEST_OS_ID:
                data = hv->hv_guest_os_id;
@@ -1499,6 +1514,9 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
        u64 data = 0;
        struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
 
+       if (unlikely(!host && !hv_check_msr_access(hv_vcpu, msr)))
+               return 1;
+
        switch (msr) {
        case HV_X64_MSR_VP_INDEX:
                data = hv_vcpu->vp_index;