From: "Denis V. Lunev" <den@openvz.org>
To: Roman Kagan <rkagan@virtuozzo.com>,
Gerd Hoffmann <kraxel@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] usb:xhci: no DMA on HC reset
Date: Tue, 10 May 2016 11:14:48 +0300 [thread overview]
Message-ID: <57319878.6060507@openvz.org> (raw)
In-Reply-To: <1462384435-1034-1-git-send-email-rkagan@virtuozzo.com>
On 05/04/2016 08:53 PM, Roman Kagan wrote:
> This patch is a rough fix to a memory corruption we are observing when
> running VMs with xhci USB controller and OVMF firmware.
>
> Specifically, on the following call chain
>
> xhci_reset
> xhci_disable_slot
> xhci_disable_ep
> xhci_set_ep_state
>
> QEMU overwrites guest memory using stale guest addresses.
>
> This doesn't happen when the guest (firmware) driver sets up xhci for
> the first time as there are no slots configured yet. However when the
> firmware hands over the control to the OS some slots and endpoints are
> already set up with their context in the guest RAM. Now the OS' driver
> resets the controller again and xhci_set_ep_state then reads and writes
> that memory which is now owned by the OS.
>
> As a quick fix, skip calling xhci_set_ep_state in xhci_disable_ep if the
> device context base address array pointer is zero (indicating we're in
> the HC reset and no DMA is possible).
>
> Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> ---
> hw/usb/hcd-xhci.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
> index bcde8a2..43ba615 100644
> --- a/hw/usb/hcd-xhci.c
> +++ b/hw/usb/hcd-xhci.c
> @@ -1531,7 +1531,10 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
> usb_packet_cleanup(&epctx->transfers[i].packet);
> }
>
> - xhci_set_ep_state(xhci, epctx, NULL, EP_DISABLED);
> + /* only touch guest RAM if we're not resetting the HC */
> + if (xhci->dcbaap_low || xhci->dcbaap_high) {
> + xhci_set_ep_state(xhci, epctx, NULL, EP_DISABLED);
> + }
>
> timer_free(epctx->kick_timer);
> g_free(epctx);
ping
next prev parent reply other threads:[~2016-05-10 9:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-04 17:53 [Qemu-devel] [PATCH] usb:xhci: no DMA on HC reset Roman Kagan
2016-05-04 18:12 ` [Qemu-devel] (for 2.6?) " Denis V. Lunev
2016-05-10 8:14 ` Denis V. Lunev [this message]
2016-05-11 8:30 ` [Qemu-devel] " Gerd Hoffmann
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=57319878.6060507@openvz.org \
--to=den@openvz.org \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rkagan@virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).