[PATCH] target/i386: disable VMX features if nested=0

Yang Zhong posted 1 patch 4 years, 4 months ago
Test asan passed
Test checkpatch passed
Test FreeBSD passed
Test docker-mingw@fedora passed
Test docker-clang@ubuntu passed
Test docker-quick@centos7 passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20191206071111.12128-1-yang.zhong@intel.com
Maintainers: Eduardo Habkost <ehabkost@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>, Marcelo Tosatti <mtosatti@redhat.com>
target/i386/kvm.c | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH] target/i386: disable VMX features if nested=0
Posted by Yang Zhong 4 years, 4 months ago
If kvm does not support VMX feature by nested=0, the kvm_vmx_basic
can't get the right value from MSR_IA32_VMX_BASIC register, which
make qemu coredump when qemu do KVM_SET_MSRS.

The coredump info:
error: failed to set MSR 0x480 to 0x0
kvm_put_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
---
 target/i386/kvm.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index bf1655645b..e8841dcdb9 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -2572,6 +2572,14 @@ static void kvm_msr_entry_add_vmx(X86CPU *cpu, FeatureWordArray f)
     uint64_t kvm_vmx_basic =
         kvm_arch_get_supported_msr_feature(kvm_state,
                                            MSR_IA32_VMX_BASIC);
+    if (!kvm_vmx_basic) {
+        /* If the kernel does't support VMX feature(nested=0 in kvm)
+         * and kvm_vmx_basic will be 0. This will set 0 value to
+         * MSR_IA32_VMX_BASIC MSR.
+         */
+        return;
+    }
+
     uint64_t kvm_vmx_misc =
         kvm_arch_get_supported_msr_feature(kvm_state,
                                            MSR_IA32_VMX_MISC);
-- 
2.17.1


Re: [PATCH] target/i386: disable VMX features if nested=0
Posted by Paolo Bonzini 4 years, 4 months ago
On 06/12/19 08:11, Yang Zhong wrote:
> If kvm does not support VMX feature by nested=0, the kvm_vmx_basic
> can't get the right value from MSR_IA32_VMX_BASIC register, which
> make qemu coredump when qemu do KVM_SET_MSRS.
> 
> The coredump info:
> error: failed to set MSR 0x480 to 0x0
> kvm_put_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed.
> 
> Signed-off-by: Yang Zhong <yang.zhong@intel.com>
> ---
>  target/i386/kvm.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index bf1655645b..e8841dcdb9 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -2572,6 +2572,14 @@ static void kvm_msr_entry_add_vmx(X86CPU *cpu, FeatureWordArray f)
>      uint64_t kvm_vmx_basic =
>          kvm_arch_get_supported_msr_feature(kvm_state,
>                                             MSR_IA32_VMX_BASIC);
> +    if (!kvm_vmx_basic) {
> +        /* If the kernel does't support VMX feature(nested=0 in kvm)
> +         * and kvm_vmx_basic will be 0. This will set 0 value to
> +         * MSR_IA32_VMX_BASIC MSR.
> +         */
> +        return;
> +    }
> +
>      uint64_t kvm_vmx_misc =
>          kvm_arch_get_supported_msr_feature(kvm_state,
>                                             MSR_IA32_VMX_MISC);
> 

Queued, thanks.

Paolo