From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PULL 01/11] xhci: limit the number of link trbs we are willing to process
Date: Wed, 12 Oct 2016 14:58:08 +0200 [thread overview]
Message-ID: <1476277098-29570-2-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1476277098-29570-1-git-send-email-kraxel@redhat.com>
Needed to avoid we run in circles forever in case the guest builds
an endless loop with link trbs.
Reported-by: Li Qiang <liqiang6-s@360.cn>
Tested-by: P J P <ppandit@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1476096382-7981-1-git-send-email-kraxel@redhat.com
---
hw/usb/hcd-xhci.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 726435c..ee4fa48 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -54,6 +54,8 @@
* to the specs when it gets them */
#define ER_FULL_HACK
+#define TRB_LINK_LIMIT 4
+
#define LEN_CAP 0x40
#define LEN_OPER (0x400 + 0x10 * MAXPORTS)
#define LEN_RUNTIME ((MAXINTRS + 1) * 0x20)
@@ -1000,6 +1002,7 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
dma_addr_t *addr)
{
PCIDevice *pci_dev = PCI_DEVICE(xhci);
+ uint32_t link_cnt = 0;
while (1) {
TRBType type;
@@ -1026,6 +1029,9 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
ring->dequeue += TRB_SIZE;
return type;
} else {
+ if (++link_cnt > TRB_LINK_LIMIT) {
+ return 0;
+ }
ring->dequeue = xhci_mask64(trb->parameter);
if (trb->control & TRB_LK_TC) {
ring->ccs = !ring->ccs;
@@ -1043,6 +1049,7 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)
bool ccs = ring->ccs;
/* hack to bundle together the two/three TDs that make a setup transfer */
bool control_td_set = 0;
+ uint32_t link_cnt = 0;
while (1) {
TRBType type;
@@ -1058,6 +1065,9 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)
type = TRB_TYPE(trb);
if (type == TR_LINK) {
+ if (++link_cnt > TRB_LINK_LIMIT) {
+ return -length;
+ }
dequeue = xhci_mask64(trb.parameter);
if (trb.control & TRB_LK_TC) {
ccs = !ccs;
--
1.8.3.1
next prev parent reply other threads:[~2016-10-12 12:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-12 12:58 [Qemu-devel] [PULL 00/11] usb patch queue Gerd Hoffmann
2016-10-12 12:58 ` Gerd Hoffmann [this message]
2016-10-12 12:58 ` [Qemu-devel] [PULL 02/11] xhci: decouple EV_QUEUE from TD_QUEUE Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 03/11] xhci: drop unused comp_xfer field Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 04/11] xhci: use linked list for transfers Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 05/11] xhci: drop XHCITransfer->xhci Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 06/11] xhci: add & use xhci_kick_epctx() Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 07/11] xhci: drop XHCITransfer->{slotid,epid} Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 08/11] xhci: make xhci_epid_to_usbep accept XHCIEPContext Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 09/11] usb: fix serial generator Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 10/11] usb: Fix incorrect default DMA offset Gerd Hoffmann
2016-10-12 12:58 ` [Qemu-devel] [PULL 11/11] usb-redir: allocate buffers before waking up the host adapter Gerd Hoffmann
2016-10-12 14:12 ` [Qemu-devel] [PULL 00/11] usb patch queue Peter Maydell
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=1476277098-29570-2-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).