From: Marcelo Tosatti Date: Wed, 12 Dec 2007 15:46:12 +0000 (-0500) Subject: KVM: MMU: emulated cmpxchg8b should be atomic on i386 X-Git-Tag: v2.6.25-rc1~1138^2~37 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=2bacc55c7c3c61e356aef06b9a319b4cee90b519;p=karo-tx-linux.git KVM: MMU: emulated cmpxchg8b should be atomic on i386 Emulate cmpxchg8b atomically on i386. This is required to avoid a guest pte walker from seeing a splitted write. [avi: make it compile] Signed-off-by: Marcelo Tosatti Signed-off-by: Avi Kivity --- diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index 9db4e3242b62..3b79684a3c0c 100644 --- a/drivers/kvm/x86.c +++ b/drivers/kvm/x86.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -1674,6 +1675,31 @@ static int emulator_cmpxchg_emulated(unsigned long addr, reported = 1; printk(KERN_WARNING "kvm: emulating exchange as write\n"); } +#ifndef CONFIG_X86_64 + /* guests cmpxchg8b have to be emulated atomically */ + if (bytes == 8) { + gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, addr); + struct page *page; + char *addr; + u64 val; + + if (gpa == UNMAPPED_GVA || + (gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) + goto emul_write; + + if (((gpa + bytes - 1) & PAGE_MASK) != (gpa & PAGE_MASK)) + goto emul_write; + + val = *(u64 *)new; + page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT); + addr = kmap_atomic(page, KM_USER0); + set_64bit((u64 *)(addr + offset_in_page(gpa)), val); + kunmap_atomic(addr, KM_USER0); + kvm_release_page_dirty(page); + } +emul_write: +#endif + return emulator_write_emulated(addr, new, bytes, vcpu); }