Skip to content

Commit 2967094

Browse files
schnhrrgregkh
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 <[email protected]> Reviewed-by: Wanpeng Li <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9e1aa8a commit 2967094

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/x86/kvm/vmx.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7657,11 +7657,13 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu,
76577657
{
76587658
unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
76597659
int cr = exit_qualification & 15;
7660-
int reg = (exit_qualification >> 8) & 15;
7661-
unsigned long val = kvm_register_readl(vcpu, reg);
7660+
int reg;
7661+
unsigned long val;
76627662

76637663
switch ((exit_qualification >> 4) & 3) {
76647664
case 0: /* mov to cr */
7665+
reg = (exit_qualification >> 8) & 15;
7666+
val = kvm_register_readl(vcpu, reg);
76657667
switch (cr) {
76667668
case 0:
76677669
if (vmcs12->cr0_guest_host_mask &
@@ -7716,6 +7718,7 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu,
77167718
* lmsw can change bits 1..3 of cr0, and only set bit 0 of
77177719
* cr0. Other attempted changes are ignored, with no exit.
77187720
*/
7721+
val = (exit_qualification >> LMSW_SOURCE_DATA_SHIFT) & 0x0f;
77197722
if (vmcs12->cr0_guest_host_mask & 0xe &
77207723
(val ^ vmcs12->cr0_read_shadow))
77217724
return true;

0 commit comments

Comments
 (0)