]> git.proxmox.com Git - mirror_qemu.git/commit
target/i386: kvm: Demand nested migration kernel capabilities only when vCPU may...
authorLiran Alon <liran.alon@oracle.com>
Fri, 5 Jul 2019 21:06:36 +0000 (00:06 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 19 Jul 2019 16:01:47 +0000 (18:01 +0200)
commit79a197ab180e75838523c58973b1221ad7bf51eb
treeb16547ef3bc84876aef6ed1bc5ac8efe301809ba
parente2b47666fe1544959c89bd3ed159e9e37cc9fc73
target/i386: kvm: Demand nested migration kernel capabilities only when vCPU may have enabled VMX

Previous to this change, a vCPU exposed with VMX running on a kernel
without KVM_CAP_NESTED_STATE or KVM_CAP_EXCEPTION_PAYLOAD resulted in
adding a migration blocker. This was because when the code was written
it was thought there is no way to reliably know if a vCPU is utilising
VMX or not at runtime. However, it turns out that this can be known to
some extent:

In order for a vCPU to enter VMX operation it must have CR4.VMXE set.
Since it was set, CR4.VMXE must remain set as long as the vCPU is in
VMX operation. This is because CR4.VMXE is one of the bits set
in MSR_IA32_VMX_CR4_FIXED1.
There is one exception to the above statement when vCPU enters SMM mode.
When a vCPU enters SMM mode, it temporarily exits VMX operation and
may also reset CR4.VMXE during execution in SMM mode.
When the vCPU exits SMM mode, vCPU state is restored to be in VMX operation
and CR4.VMXE is restored to its original state of being set.
Therefore, when the vCPU is not in SMM mode, we can infer whether
VMX is being used by examining CR4.VMXE. Otherwise, we cannot
know for certain but assume the worse that vCPU may utilise VMX.

Summaring all the above, a vCPU may have enabled VMX in case
CR4.VMXE is set or vCPU is in SMM mode.

Therefore, remove migration blocker and check before migration
(cpu_pre_save()) if the vCPU may have enabled VMX. If true, only then
require relevant kernel capabilities.

While at it, demand KVM_CAP_EXCEPTION_PAYLOAD only when the vCPU is in
guest-mode and there is a pending/injected exception. Otherwise, this
kernel capability is not required for proper migration.

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Reviewed-by: Maran Wilson <maran.wilson@oracle.com>
Tested-by: Maran Wilson <maran.wilson@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
target/i386/cpu.h
target/i386/kvm.c
target/i386/kvm_i386.h
target/i386/machine.c