From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [PATCH] emulated cmpxchg8b should be atomic on i386 Date: Mon, 10 Dec 2007 15:31:15 -0500 Message-ID: <20071210203115.GA16617@dmt> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel To: Avi Kivity Return-path: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org Emulate cmpxchg8b atomically on i386. This is required to avoid a guest pte walker from seeing a splitted write. Signed-off-by: Marcelo Tosatti diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index 9db4e32..d58d795 100644 --- a/drivers/kvm/x86.c +++ b/drivers/kvm/x86.c @@ -1674,6 +1674,33 @@ static int emulator_cmpxchg_emulated(uns 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; + + val = (u64 *)new; + page = gfn_to_page(page, gpa >> PAGE_SHIFT); + addr = kmap_atomic(page, KM_USER0); + addr += offset_in_page(gpa); + + set_64bit((unsigned long long *)addr, val); + + kunmap_atomic(page, KM_USER0); + kvm_release_page_dirty(page); + + return X86EMUL_CONTINUE; + } +#endif + +emul_write: return emulator_write_emulated(addr, new, bytes, vcpu); } ------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php