Skip to contentSkip to conversation

KVM: Don't allow lmsw to clear cr0.pe

PATCH Applied Avi Kivity 3 participants 4 messages May 11, 2010 – May 13, 2010

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 KVM: Don't allow lmsw to clear cr0.pe

The current lmsw implementation allows the guest to clear cr0.pe, contrary to the manual, which breaks EMM386.EXE.

Fix by ORing the old cr0.pe with lmsw's operand.

---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +1 -1
index cd8a606..a40170c 100644
@@ -462,7 +462,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cr0);
 
 void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw)
 {
-	kvm_set_cr0(vcpu, kvm_read_cr0_bits(vcpu, ~0x0ful) | (msw & 0x0f));
+	kvm_set_cr0(vcpu, kvm_read_cr0_bits(vcpu, ~0x0eul) | (msw & 0x0f));
 }
 EXPORT_SYMBOL_GPL(kvm_lmsw);
 
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 15 lines · Avi Kivity

The current lmsw implementation allows the guest to clear cr0.pe, contrary to the manual, which breaks EMM386.EXE.

Fix by ORing the old cr0.pe with lmsw's operand.

---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +0 -0
index cd8a606..a40170c 100644

arch/x86/kvm/x86.c EXPORT_SYMBOL_GPL(kvm_set_cr0); · line 468

Quoted 8 lines
arch/x86/kvm/x86.c +1 -1
@@ -462,7 +462,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cr0);
 
 void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw)
 {
-	kvm_set_cr0(vcpu, kvm_read_cr0_bits(vcpu, ~0x0ful) | (msw & 0x0f));
+	kvm_set_cr0(vcpu, kvm_read_cr0_bits(vcpu, ~0x0eul) | (msw & 0x0f));
 }
 EXPORT_SYMBOL_GPL(kvm_lmsw);
 

Cool. I will build a kernel and test tomorrow.

Regards,
Andy

#2 lore raw
In reply to Avi Kivity
Quoted 15 lines · Avi Kivity

The current lmsw implementation allows the guest to clear cr0.pe, contrary to the manual, which breaks EMM386.EXE.

Fix by ORing the old cr0.pe with lmsw's operand.

---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +0 -0
index cd8a606..a40170c 100644

arch/x86/kvm/x86.c EXPORT_SYMBOL_GPL(kvm_set_cr0); · line 468

Quoted 8 lines
arch/x86/kvm/x86.c +1 -1
@@ -462,7 +462,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cr0);
 
 void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw)
 {
-	kvm_set_cr0(vcpu, kvm_read_cr0_bits(vcpu, ~0x0ful) | (msw & 0x0f));
+	kvm_set_cr0(vcpu, kvm_read_cr0_bits(vcpu, ~0x0eul) | (msw & 0x0f));
 }
 EXPORT_SYMBOL_GPL(kvm_lmsw);
 

This patch works for me. The old programs I have that use the DOS/4GW extender (http://www.tenberry.com/) runtime no longer hanging the MS-DOS 6.22 guest when EMM386.EXE is loaded and the "set_cr0: #GP..." message is no longer filling the logs.

:)

Now I have a different problem. dmesg is filling with "skip_emulated_instruction: NOP" messages. As I investigate further, I unfortunately found that RHEL 5 has a somewhat dated kvm package:

ftp://ftp.redhat.com/redhat/linux/enterprise/5Client/en/os/SRPMS/kvm-83-164.el5.src.rpm

that looks to be based on a KVM snapshot from around May of last year. It appears to missing some recent patches in regard to skip_emulated_instruction(). :(

Oh well. I'll try qemu without KVM hardware acceleration.

Thanks for the fast response on the LMSW patch.

Regards,
Andy

#3 lore raw
In reply to Avi Kivity
Quoted 9 lines · Avi Kivity

The current lmsw implementation allows the guest to clear cr0.pe, contrary to the manual, which breaks EMM386.EXE.

Fix by ORing the old cr0.pe with lmsw's operand.

---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Applied, thanks.