]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
KVM: nVMX: fix guest CR4 loading when emulating L2 to L1 exit
authorHaozhong Zhang <haozhong.zhang@intel.com>
Tue, 10 Oct 2017 07:01:22 +0000 (15:01 +0800)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 19 Oct 2017 14:49:30 +0000 (09:49 -0500)
commit24c903738c524f71e755f6c0c2035af94a5db108
tree3e3fab0f2d348e650a0453cab258af9895e2daf3
parent7317f7a74500836636faece467e34e817f3fd1b9
KVM: nVMX: fix guest CR4 loading when emulating L2 to L1 exit

BugLink: http://bugs.launchpad.net/bugs/1724669
commit 8eb3f87d903168bdbd1222776a6b1e281f50513e upstream.

When KVM emulates an exit from L2 to L1, it loads L1 CR4 into the
guest CR4. Before this CR4 loading, the guest CR4 refers to L2
CR4. Because these two CR4's are in different levels of guest, we
should vmx_set_cr4() rather than kvm_set_cr4() here. The latter, which
is used to handle guest writes to its CR4, checks the guest change to
CR4 and may fail if the change is invalid.

The failure may cause trouble. Consider we start
  a L1 guest with non-zero L1 PCID in use,
     (i.e. L1 CR4.PCIDE == 1 && L1 CR3.PCID != 0)
and
  a L2 guest with L2 PCID disabled,
     (i.e. L2 CR4.PCIDE == 0)
and following events may happen:

1. If kvm_set_cr4() is used in load_vmcs12_host_state() to load L1 CR4
   into guest CR4 (in VMCS01) for L2 to L1 exit, it will fail because
   of PCID check. As a result, the guest CR4 recorded in L0 KVM (i.e.
   vcpu->arch.cr4) is left to the value of L2 CR4.

2. Later, if L1 attempts to change its CR4, e.g., clearing VMXE bit,
   kvm_set_cr4() in L0 KVM will think L1 also wants to enable PCID,
   because the wrong L2 CR4 is used by L0 KVM as L1 CR4. As L1
   CR3.PCID != 0, L0 KVM will inject GP to L1 guest.

Fixes: 4704d0befb072 ("KVM: nVMX: Exiting from L2 to L1")
Cc: qemu-stable@nongnu.org
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
arch/x86/kvm/vmx.c