Alex Williamson
2007-Jun-18 21:52 UTC
[Xen-devel] [PATCH] Re: [Xen-staging] [xen-unstable] [HVM] Prevent usb driver crashes in Windows
On Wed, 2007-06-06 at 20:26 +0100, Xen staging patchbot-unstable wrote:> +/* > + * Replace the standard byte memcpy with a word memcpy for appropriately sized > + * memory copy operations. Some users (USB-UHCI) can not tolerate the possible > + * word tearing that can result from a guest concurrently writing a memory > + * structure while the qemu device model is modifying the same location. > + * Forcing a word-sized read/write prevents the guest from seeing a partially > + * written word-sized atom. > + */ > +void memcpy_words(void *dst, void *src, size_t n) > +{ > + while (n >= sizeof(long)) { > + *((long *)dst)++ = *((long *)src)++; > + n -= sizeof(long); > + }The above requires 8-byte alignment on 64bit boxes, not the 4-byte alignment USB provides. This generates lots of unaligned accesses on ia64 and probably slows things down on x64 as well. How about the patch below? Thanks, Alex Signed-off-by: Alex Williamson <alex.williamson@hp.com> --- diff -r 7d4c40c21690 tools/ioemu/target-i386-dm/exec-dm.c --- a/tools/ioemu/target-i386-dm/exec-dm.c Mon Jun 18 13:50:42 2007 -0600 +++ b/tools/ioemu/target-i386-dm/exec-dm.c Mon Jun 18 15:43:27 2007 -0600 @@ -445,11 +445,11 @@ extern unsigned long logdirty_bitmap_siz */ void memcpy_words(void *dst, void *src, size_t n) { - while (n >= sizeof(long)) { - *((long *)dst) = *((long *)src); - dst = ((long *)dst) + 1; - src = ((long *)src) + 1; - n -= sizeof(long); + while (n > sizeof(int)) { + *((int *)dst) = *((int *)src); + dst = ((int *)dst) + 1; + src = ((int *)src) + 1; + n -= sizeof(int); } if (n & 4) { _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel