Skip to contentSkip to conversation

Fix lmsw handling

PATCH In review Trolle Selander 2 participants 2 messages Jun 27, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix lmsw handling

The lmsw instruction can be used to set CR0_PE, but can never clear it, once set. Currently, as far as I can see, there is no provision to keep lmsw from clearing CR0_PE, either in the vmx code or in x86_emulate code (which is used by SVM to emulate lmsw). This patch fixes this issue.

xen/arch/x86/hvm/vmx/vmx.c +2 -1
diff -uNr xen-unstable.hg/xen/arch/x86/hvm/vmx/vmx.c xen-unstable.hg-patched/xen/arch/x86/hvm/vmx/vmx.c
@@ -1523,7 +1523,8 @@
         break;
     case VMX_CONTROL_REG_ACCESS_TYPE_LMSW:
         value = v->arch.hvm_vcpu.guest_cr[0];
-        value = (value & ~0xFFFF) | ((exit_qualification >> 16) & 0xFFFF);
+        /* lsmw can set but never clear PE */
+        value = (value & 0xFFFF0001) | ((exit_qualification >> 16) & 0xFFFF);
         HVMTRACE_LONG_1D(LMSW, current, value);
         return !hvm_set_cr0(value);
     default:
xen/arch/x86/x86_emulate/x86_emulate.c +1 -1
diff -uNr xen-unstable.hg/xen/arch/x86/x86_emulate/x86_emulate.c xen-unstable.hg-patched/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -3284,7 +3284,7 @@
             else if ( (rc = ops->read(ea.mem.seg, ea.mem.off,
                                       &cr0w, 2, ctxt)) )
                 goto done;
-            cr0 &= 0xffff0000;
+            cr0 &= 0xffff0001; /* lmsw can set, but never clear, PE */
             cr0 |= (uint16_t)cr0w;
             if ( (rc = ops->write_cr(0, cr0, ctxt)) )
                 goto done;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

I applied it, but then realised that additionally LMSW can only affect bits 0-3 of CR0. Additionally SMSW emulation is wrong because it is only limited to 16-bit operation when the destination operand is memory. So I¹ve fixed up these things in a subsequent changeset.

-- Keir

Quoted 7 lines · Trolle Selander

The lmsw instruction can be used to set CR0_PE, but can never clear it, once set. Currently, as far as I can see, there is no provision to keep lmsw from clearing CR0_PE, either in the vmx code or in x86_emulate code (which is used by SVM to emulate lmsw). This patch fixes this issue.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel