Skip to content

Commit 68339a1

Browse files
schnhrrfranciscofranco
authored andcommitted
KVM: nVMX: Fix handling of lmsw instruction
[ Upstream commit e1d39b1 ] The decision whether or not to exit from L2 to L1 on an lmsw instruction is based on bogus values: instead of using the information encoded within the exit qualification, it uses the data also used for the mov-to-cr instruction, which boils down to using whatever is in %eax at that point. Use the correct values instead. Without this fix, an L1 may not get notified when a 32-bit Linux L2 switches its secondary CPUs to protected mode; the L1 is only notified on the next modification of CR0. This short time window poses a problem, when there is some other reason to exit to L1 in between. Then, L2 will be resumed in real mode and chaos ensues. Signed-off-by: Jan H. Schönherr <jschoenh@amazon.de> Reviewed-by: Wanpeng Li <wanpeng.li@hotmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fc0f7a3 commit 68339a1

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

arch/x86/kvm/vmx.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6935,11 +6935,13 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu,
69356935
{
69366936
unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
69376937
int cr = exit_qualification & 15;
6938-
int reg = (exit_qualification >> 8) & 15;
6939-
unsigned long val = kvm_register_readl(vcpu, reg);
6938+
int reg;
6939+
unsigned long val;
69406940

69416941
switch ((exit_qualification >> 4) & 3) {
69426942
case 0: /* mov to cr */
6943+
reg = (exit_qualification >> 8) & 15;
6944+
val = kvm_register_readl(vcpu, reg);
69436945
switch (cr) {
69446946
case 0:
69456947
if (vmcs12->cr0_guest_host_mask &
@@ -6994,6 +6996,7 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu,
69946996
* lmsw can change bits 1..3 of cr0, and only set bit 0 of
69956997
* cr0. Other attempted changes are ignored, with no exit.
69966998
*/
6999+
val = (exit_qualification >> LMSW_SOURCE_DATA_SHIFT) & 0x0f;
69977000
if (vmcs12->cr0_guest_host_mask & 0xe &
69987001
(val ^ vmcs12->cr0_read_shadow))
69997002
return 1;

0 commit comments

Comments
 (0)