diff mbox series

i386/kvm: fix setting up nested_state for SVM

Message ID 20201026020622.2890096-1-marmarek@invisiblethingslab.com
State New
Headers show
Series i386/kvm: fix setting up nested_state for SVM | expand

Commit Message

Marek Marczykowski-Górecki Oct. 26, 2020, 2:06 a.m. UTC
nested_state->format needs to ne set appropriately for VMX/SVM,
otherwise KVM_SET_NESTED_STATE ioctl will fail.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 target/i386/kvm.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index cf46259534..a002f0b4f1 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1816,16 +1816,22 @@  int kvm_arch_init_vcpu(CPUState *cs)
         assert(max_nested_state_len >= offsetof(struct kvm_nested_state, data));
 
         if (cpu_has_vmx(env) || cpu_has_svm(env)) {
-            struct kvm_vmx_nested_state_hdr *vmx_hdr;
-
             env->nested_state = g_malloc0(max_nested_state_len);
             env->nested_state->size = max_nested_state_len;
-            env->nested_state->format = KVM_STATE_NESTED_FORMAT_VMX;
 
             if (cpu_has_vmx(env)) {
-                    vmx_hdr = &env->nested_state->hdr.vmx;
-                    vmx_hdr->vmxon_pa = -1ull;
-                    vmx_hdr->vmcs12_pa = -1ull;
+                struct kvm_vmx_nested_state_hdr *vmx_hdr =
+                    &env->nested_state->hdr.vmx;
+
+                vmx_hdr->vmxon_pa = -1ull;
+                vmx_hdr->vmcs12_pa = -1ull;
+                env->nested_state->format = KVM_STATE_NESTED_FORMAT_VMX;
+            } else {
+                struct kvm_svm_nested_state_hdr *svm_hdr =
+                    &env->nested_state->hdr.svm;
+
+                svm_hdr->vmcb_pa = -1ull;
+                env->nested_state->format = KVM_STATE_NESTED_FORMAT_SVM;
             }
         }
     }