Skip to content

Commit 0baa4b4

Browse files
vittyvkehabkost
authored andcommitted
KVM: fix CPU reset wrt HF2_GIF_MASK
HF2_GIF_MASK is set in env->hflags2 unconditionally on CPU reset (see x86_cpu_reset()) but when calling KVM_SET_NESTED_STATE, KVM_STATE_NESTED_GIF_SET is only valid for nSVM as e.g. nVMX code looks like if (kvm_state->hdr.vmx.vmxon_pa == -1ull) { if (kvm_state->flags & ~KVM_STATE_NESTED_EVMCS) return -EINVAL; } Also, when adjusting the environment after KVM_GET_NESTED_STATE we need not reset HF2_GIF_MASK on VMX as e.g. x86_cpu_pending_interrupt() expects it to be set. Alternatively, we could've made env->hflags2 SVM-only. Reported-by: Jan Kiszka <[email protected]> Fixes: b16c0e2 ("KVM: add support for AMD nested live migration") Signed-off-by: Vitaly Kuznetsov <[email protected]> Message-Id: <[email protected]> Tested-by: Jan Kiszka <[email protected]> Signed-off-by: Eduardo Habkost <[email protected]>
1 parent 8ffa52c commit 0baa4b4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

target/i386/kvm.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,7 +3877,9 @@ static int kvm_put_nested_state(X86CPU *cpu)
38773877
} else {
38783878
env->nested_state->flags &= ~KVM_STATE_NESTED_GUEST_MODE;
38793879
}
3880-
if (env->hflags2 & HF2_GIF_MASK) {
3880+
3881+
/* Don't set KVM_STATE_NESTED_GIF_SET on VMX as it is illegal */
3882+
if (cpu_has_svm(env) && (env->hflags2 & HF2_GIF_MASK)) {
38813883
env->nested_state->flags |= KVM_STATE_NESTED_GIF_SET;
38823884
} else {
38833885
env->nested_state->flags &= ~KVM_STATE_NESTED_GIF_SET;
@@ -3919,10 +3921,14 @@ static int kvm_get_nested_state(X86CPU *cpu)
39193921
} else {
39203922
env->hflags &= ~HF_GUEST_MASK;
39213923
}
3922-
if (env->nested_state->flags & KVM_STATE_NESTED_GIF_SET) {
3923-
env->hflags2 |= HF2_GIF_MASK;
3924-
} else {
3925-
env->hflags2 &= ~HF2_GIF_MASK;
3924+
3925+
/* Keep HF2_GIF_MASK set on !SVM as x86_cpu_pending_interrupt() needs it */
3926+
if (cpu_has_svm(env)) {
3927+
if (env->nested_state->flags & KVM_STATE_NESTED_GIF_SET) {
3928+
env->hflags2 |= HF2_GIF_MASK;
3929+
} else {
3930+
env->hflags2 &= ~HF2_GIF_MASK;
3931+
}
39263932
}
39273933

39283934
return ret;

0 commit comments

Comments
 (0)