KVM: nVMX: list VMX MSRs in KVM_GET_MSR_INDEX_LIST
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 2 Jul 2019 12:45:24 +0000 (14:45 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 2 Jul 2019 15:36:18 +0000 (17:36 +0200)
This allows userspace to know which MSRs are supported by the hypervisor.
Unfortunately userspace must resort to tricks for everything except
MSR_IA32_VMX_VMFUNC (which was just added in the previous patch).
One possibility is to use the feature control MSR, which is tied to nested
VMX as well and is present on all KVM versions that support feature MSRs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c

index bbc31f7213ed81b2ffcb21c8f8d184a5559b1ee2..5db50c19d1c7227f2a58b3b63e00d4b7b39210aa 100644 (file)
@@ -5885,6 +5885,7 @@ static bool svm_has_emulated_msr(int index)
 {
        switch (index) {
        case MSR_IA32_MCG_EXT_CTL:
+       case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
                return false;
        default:
                break;
index a35459ce7e29b2d002a43a95eb5bf751ab482f67..c4363594269387c5992352756f11eae6c1501f71 100644 (file)
@@ -6223,6 +6223,8 @@ static bool vmx_has_emulated_msr(int index)
                 * real mode.
                 */
                return enable_unrestricted_guest || emulate_invalid_guest_state;
+       case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
+               return nested;
        case MSR_AMD64_VIRT_SPEC_CTRL:
                /* This is AMD only.  */
                return false;
index e536a2b2b0e81aacc87d63b82627e36603011e76..721af7b46b24f0ec2c2eeb9afa7917fd7400c857 100644 (file)
@@ -1176,6 +1176,26 @@ static u32 emulated_msrs[] = {
        MSR_AMD64_VIRT_SPEC_CTRL,
        MSR_IA32_POWER_CTL,
 
+       /*
+        * The following list leaves out MSRs whose values are determined
+        * by arch/x86/kvm/vmx/nested.c based on CPUID or other MSRs.
+        * We always support the "true" VMX control MSRs, even if the host
+        * processor does not, so I am putting these registers here rather
+        * than in msrs_to_save.
+        */
+       MSR_IA32_VMX_BASIC,
+       MSR_IA32_VMX_TRUE_PINBASED_CTLS,
+       MSR_IA32_VMX_TRUE_PROCBASED_CTLS,
+       MSR_IA32_VMX_TRUE_EXIT_CTLS,
+       MSR_IA32_VMX_TRUE_ENTRY_CTLS,
+       MSR_IA32_VMX_MISC,
+       MSR_IA32_VMX_CR0_FIXED0,
+       MSR_IA32_VMX_CR4_FIXED0,
+       MSR_IA32_VMX_VMCS_ENUM,
+       MSR_IA32_VMX_PROCBASED_CTLS2,
+       MSR_IA32_VMX_EPT_VPID_CAP,
+       MSR_IA32_VMX_VMFUNC,
+
        MSR_K7_HWCR,
        MSR_KVM_POLL_CONTROL,
 };