* [PATCH] emulated cmpxchg8b should be atomic on i386 @ 2007-12-10 20:31 Marcelo Tosatti 2007-12-10 21:30 ` Avi Kivity 0 siblings, 1 reply; 4+ messages in thread From: Marcelo Tosatti @ 2007-12-10 20:31 UTC (permalink / raw) To: Avi Kivity; +Cc: kvm-devel Emulate cmpxchg8b atomically on i386. This is required to avoid a guest pte walker from seeing a splitted write. Signed-off-by: Marcelo Tosatti <mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> 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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] emulated cmpxchg8b should be atomic on i386 2007-12-10 20:31 [PATCH] emulated cmpxchg8b should be atomic on i386 Marcelo Tosatti @ 2007-12-10 21:30 ` Avi Kivity [not found] ` <475DAFE3.30501-atKUWr5tajBWk0Htik3J/w@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Avi Kivity @ 2007-12-10 21:30 UTC (permalink / raw) To: Marcelo Tosatti; +Cc: kvm-devel Marcelo Tosatti wrote: > Emulate cmpxchg8b atomically on i386. This is required to avoid a guest > pte walker from seeing a splitted write. > > Signed-off-by: Marcelo Tosatti <mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> > > 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); > } > Won't the compiler complain when it sees an unreferenced label? Also, we should handle the page boundary crossing case (probably by just emulating as a write and crosssing fingers). -- Any sufficiently difficult bug is indistinguishable from a feature. ------------------------------------------------------------------------- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <475DAFE3.30501-atKUWr5tajBWk0Htik3J/w@public.gmane.org>]
* Re: [PATCH] emulated cmpxchg8b should be atomic on i386 [not found] ` <475DAFE3.30501-atKUWr5tajBWk0Htik3J/w@public.gmane.org> @ 2007-12-12 15:46 ` Marcelo Tosatti 2007-12-13 9:02 ` Avi Kivity 0 siblings, 1 reply; 4+ messages in thread From: Marcelo Tosatti @ 2007-12-12 15:46 UTC (permalink / raw) To: Avi Kivity; +Cc: kvm-devel On Mon, Dec 10, 2007 at 11:30:11PM +0200, Avi Kivity wrote: > Marcelo Tosatti wrote: > >Emulate cmpxchg8b atomically on i386. This is required to avoid a guest > >pte walker from seeing a splitted write. > > > >Signed-off-by: Marcelo Tosatti <mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> > > > >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); > > } > > > > Won't the compiler complain when it sees an unreferenced label? > > Also, we should handle the page boundary crossing case (probably by just > emulating as a write and crosssing fingers). Pagetable writes should not cross page boundaries, so that should be fine. ------------------ Emulate cmpxchg8b atomically on i386. This is required to avoid a guest pte walker from seeing a splitted write. Signed-off-by: Marcelo Tosatti <mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index 9db4e32..e37c19d 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; + + if (((addr + bytes - 1) & PAGE_MASK) != (addr & PAGE_MASK)) + 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); + } +emul_write: +#endif + 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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] emulated cmpxchg8b should be atomic on i386 2007-12-12 15:46 ` Marcelo Tosatti @ 2007-12-13 9:02 ` Avi Kivity 0 siblings, 0 replies; 4+ messages in thread From: Avi Kivity @ 2007-12-13 9:02 UTC (permalink / raw) To: Marcelo Tosatti; +Cc: kvm-devel Marcelo Tosatti wrote: > Emulate cmpxchg8b atomically on i386. This is required to avoid a guest > pte walker from seeing a splitted write. > Applied, thanks. -- error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- 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://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-12-13 9:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-10 20:31 [PATCH] emulated cmpxchg8b should be atomic on i386 Marcelo Tosatti
2007-12-10 21:30 ` Avi Kivity
[not found] ` <475DAFE3.30501-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-12 15:46 ` Marcelo Tosatti
2007-12-13 9:02 ` Avi Kivity
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox