@@ -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;
}
}
}
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(-)