From: Keir Fraser <keir@xensource.com>
To: Ben Guthro <bguthro@virtualiron.com>, xen-devel@lists.xensource.com
Subject: Re: [PATCH] [HVM] Prevent usb driver crashes in Windows
Date: Wed, 06 Jun 2007 17:40:38 +0100 [thread overview]
Message-ID: <C28CA216.10306%keir@xensource.com> (raw)
In-Reply-To: <4666DA1C.4010708@virtualiron.com>
What precisely is the race? Qemu-dm is single threaded. Memcpy() probably
ends up doing int copies anyway if things are appropriately aligned
(although we might not want to rely on that).
-- Keir
On 6/6/07 17:00, "Ben Guthro" <bguthro@virtualiron.com> wrote:
> qemu-word-tearing.patch:
> Use atomic updates to read/write usb controller data.
> This can be done because:
> a) word copies on x86 are atomic
> b) The USB spec requires word alignment
>
> This will need to be enhanced once USB 1.2 is supported.
>
> Signed-off-by: Steve Ofsthun <sofsthun@virtualiron.com>
>
> diff -r 86fa3e4277f6 tools/ioemu/target-i386-dm/exec-dm.c
> --- a/tools/ioemu/target-i386-dm/exec-dm.c Mon Jun 04 11:26:30 2007 -0400
> +++ b/tools/ioemu/target-i386-dm/exec-dm.c Mon Jun 04 11:29:03 2007 -0400
> @@ -434,6 +434,28 @@ extern unsigned long *logdirty_bitmap;
> extern unsigned long *logdirty_bitmap;
> extern unsigned long logdirty_bitmap_size;
>
> +/*
> + * Replace the standard byte memcpy with a int 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 int sized read/write prevents the guest from seeing a partially
> + * written int sized atom.
> + */
> +void memcpy32(void *dst, void *src, size_t n)
> +{
> + if ((n % sizeof(int)) != 0) {
> + memcpy(dst, src, n);
> + return;
> + }
> + n /= sizeof(int);
> + while(n--) {
> + *(int *)dst = *(int *)src;
> + dst += sizeof(int);
> + src += sizeof(int);
> + }
> +}
> +
> void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
> int len, int is_write)
> {
> @@ -470,7 +492,7 @@ void cpu_physical_memory_rw(target_phys_
> }
> } else if ((ptr = phys_ram_addr(addr)) != NULL) {
> /* Writing to RAM */
> - memcpy(ptr, buf, l);
> + memcpy32(ptr, buf, l);
> if (logdirty_bitmap != NULL) {
> /* Record that we have dirtied this frame */
> unsigned long pfn = addr >> TARGET_PAGE_BITS;
> @@ -506,7 +528,7 @@ void cpu_physical_memory_rw(target_phys_
> }
> } else if ((ptr = phys_ram_addr(addr)) != NULL) {
> /* Reading from RAM */
> - memcpy(buf, ptr, l);
> + memcpy32(buf, ptr, l);
> } else {
> /* Neither RAM nor known MMIO space */
> memset(buf, 0xff, len);
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2007-06-06 16:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-31 23:04 [RFC][PATCH 1/6] HVM PCI Passthrough (non-IOMMU) Guy Zana
2007-06-04 18:25 ` Muli Ben-Yehuda
2007-06-04 21:43 ` Guy Zana
2007-06-05 6:37 ` Muli Ben-Yehuda
2007-06-06 16:00 ` [PATCH] [HVM] Prevent usb driver crashes in Windows Ben Guthro
2007-06-06 16:05 ` [PATCH] Fix vnc port offset in xenstore Ben Guthro
2007-06-06 16:08 ` [PATCH] [HVM] Fix 64 bit PV-on-HVM driver builds Ben Guthro
2007-06-06 16:12 ` [PATCH] [HVM] Allow mkbuildtree to override XEN and XL Ben Guthro
2007-06-06 16:17 ` [PATCH] [HVM] Fix 64 bit PV-on-HVM driver builds Jan Beulich
2007-06-06 16:26 ` [PATCH] [QEMU] remove .depend file on clean build Ben Guthro
2007-06-06 16:38 ` [PATCH] [HVM] Fix 64 bit PV-on-HVM driver builds Keir Fraser
2007-06-06 18:42 ` Dave Lively
2007-06-06 18:57 ` Keir Fraser
2007-06-06 19:20 ` David Lively
2007-06-06 16:40 ` Keir Fraser [this message]
2007-06-06 17:03 ` [PATCH] [HVM] Prevent usb driver crashes in Windows Steve Ofsthun
2007-06-06 18:22 ` Keir Fraser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C28CA216.10306%keir@xensource.com \
--to=keir@xensource.com \
--cc=bguthro@virtualiron.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.