KVM: x86 emulator: fix xchg instruction emulation
authorWei Yongjun <yjwei@cn.fujitsu.com>
Thu, 15 Jul 2010 00:51:58 +0000 (08:51 +0800)
committerAvi Kivity <avi@redhat.com>
Mon, 2 Aug 2010 03:40:53 +0000 (06:40 +0300)
If the destination is a memory operand and the memory cannot
map to a valid page, the xchg instruction emulation and locked
instruction will not work on io regions and stuck in endless
loop. We should emulate exchange as write to fix it.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Acked-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/x86.c

index 689c2c3..97aab03 100644 (file)
@@ -3562,6 +3562,10 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
                goto emul_write;
 
        page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
+       if (is_error_page(page)) {
+               kvm_release_page_clean(page);
+               goto emul_write;
+       }
 
        kaddr = kmap_atomic(page, KM_USER0);
        kaddr += offset_in_page(gpa);