KVM: X86: Introduce kvm_get_msr_feature()
authorWanpeng Li <wanpengli@tencent.com>
Wed, 28 Feb 2018 06:03:30 +0000 (14:03 +0800)
committerRadim Krčmář <rkrcmar@redhat.com>
Thu, 1 Mar 2018 21:32:44 +0000 (22:32 +0100)
Introduce kvm_get_msr_feature() to handle the msrs which are supported
by different vendors and sharing the same emulation logic.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Liran Alon <liran.alon@oracle.com>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
arch/x86/kvm/x86.c

index 54b4ed55945b67c9bba61f73a368494b4bc975b2..d97620eeb394f5bc92885b9f4753ec5c5abbf83c 100644 (file)
@@ -1059,13 +1059,25 @@ static u32 msr_based_features[] = {
 
 static unsigned int num_msr_based_features;
 
+static int kvm_get_msr_feature(struct kvm_msr_entry *msr)
+{
+       switch (msr->index) {
+       default:
+               if (kvm_x86_ops->get_msr_feature(msr))
+                       return 1;
+       }
+       return 0;
+}
+
 static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
 {
        struct kvm_msr_entry msr;
+       int r;
 
        msr.index = index;
-       if (kvm_x86_ops->get_msr_feature(&msr))
-               return 1;
+       r = kvm_get_msr_feature(&msr);
+       if (r)
+               return r;
 
        *data = msr.data;
 
@@ -4522,7 +4534,7 @@ static void kvm_init_msr_list(void)
                struct kvm_msr_entry msr;
 
                msr.index = msr_based_features[i];
-               if (kvm_x86_ops->get_msr_feature(&msr))
+               if (kvm_get_msr_feature(&msr))
                        continue;
 
                if (j < i)