When the old value and new one are the same the emulator skips the
write; this is undesiderable when the destination is a MMIO area and the
write shall be performed regardless of the previous value. This
optimization breaks e.g. a Linux guest APIC compiled without
X86_GOOD_APIC.

Remove the check and always perform the writeback stage in the
emulation.

Signed-Off-By: Luca Tettamanti <[EMAIL PROTECTED]>

---
 drivers/kvm/x86_emulate.c |   60 +++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index a4a8481..cea9f3a 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -1057,40 +1057,38 @@ done_prefixes:
        }
 
 writeback:
-       if ((d & Mov) || (dst.orig_val != dst.val)) {
-               switch (dst.type) {
-               case OP_REG:
-                       /* The 4-byte case *is* correct: in 64-bit mode we 
zero-extend. */
-                       switch (dst.bytes) {
-                       case 1:
-                               *(u8 *)dst.ptr = (u8)dst.val;
-                               break;
-                       case 2:
-                               *(u16 *)dst.ptr = (u16)dst.val;
-                               break;
-                       case 4:
-                               *dst.ptr = (u32)dst.val;
-                               break;  /* 64b: zero-ext */
-                       case 8:
-                               *dst.ptr = dst.val;
-                               break;
-                       }
+       switch (dst.type) {
+       case OP_REG:
+               /* The 4-byte case *is* correct: in 64-bit mode we zero-extend. 
*/
+               switch (dst.bytes) {
+               case 1:
+                       *(u8 *)dst.ptr = (u8)dst.val;
                        break;
-               case OP_MEM:
-                       if (lock_prefix)
-                               rc = ops->cmpxchg_emulated((unsigned long)dst.
-                                                          ptr, &dst.orig_val,
-                                                          &dst.val, dst.bytes,
-                                                          ctxt);
-                       else
-                               rc = ops->write_emulated((unsigned long)dst.ptr,
-                                                        &dst.val, dst.bytes,
-                                                        ctxt);
-                       if (rc != 0)
-                               goto done;
-               default:
+               case 2:
+                       *(u16 *)dst.ptr = (u16)dst.val;
+                       break;
+               case 4:
+                       *dst.ptr = (u32)dst.val;
+                       break;  /* 64b: zero-ext */
+               case 8:
+                       *dst.ptr = dst.val;
                        break;
                }
+               break;
+       case OP_MEM:
+               if (lock_prefix)
+                       rc = ops->cmpxchg_emulated((unsigned long)dst.
+                                                  ptr, &dst.orig_val,
+                                                  &dst.val, dst.bytes,
+                                                  ctxt);
+               else
+                       rc = ops->write_emulated((unsigned long)dst.ptr,
+                                                &dst.val, dst.bytes,
+                                                ctxt);
+               if (rc != 0)
+                       goto done;
+       default:
+               break;
        }
 
        /* Commit shadow register state. */

Luca
-- 
Software is like sex; it's better when it's free.
Linus Torvalds
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to