From patchwork Tue Feb 7 09:43:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9559629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD34D6047A for ; Tue, 7 Feb 2017 09:43:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA5B7281C3 for ; Tue, 7 Feb 2017 09:43:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DE3228305; Tue, 7 Feb 2017 09:43:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1757F281C3 for ; Tue, 7 Feb 2017 09:43:46 +0000 (UTC) Received: from localhost ([::1]:52900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cb2JN-0007Zv-9w for patchwork-qemu-devel@patchwork.kernel.org; Tue, 07 Feb 2017 04:43:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cb2J8-0007Zp-1L for qemu-devel@nongnu.org; Tue, 07 Feb 2017 04:43:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cb2J4-00044H-T1 for qemu-devel@nongnu.org; Tue, 07 Feb 2017 04:43:30 -0500 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:35822) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cb2J4-00043f-Lq for qemu-devel@nongnu.org; Tue, 07 Feb 2017 04:43:26 -0500 Received: by mail-lf0-x241.google.com with SMTP id v186so6159789lfa.2 for ; Tue, 07 Feb 2017 01:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:date; bh=8W+XKyignuCsN9r3In8g2YCNZwL1zkhkj/cOgD9AU3k=; b=mcSKxK69g5kVcLWNkJd1RXPw4De6iTU3M6qSNB4L8wM3pffD2ByYV/2sQVefKfMC57 2vHywcxoBkzJXMUCL4Pz1NYYvCLzjQGp7STcHxK72SqNQfNsIurjlZ5hiarGUOROkjkL i7nyM+J6QdHRgT5dEMQGU01gJGeLh48LXi9pikJdRtTmhRbyhMOQlCl0xh57xmzLva24 /UNCdhjB6LmKUpWpnex0/vju76Y1g0dMwbZmw3L9uk0F9xU11jGFerAPak+e6CcFOhPz oeumv+VdOi324X5jSVweDWDcHYuP+UudJwCBqTiQ6yv3s9AOsfpIEHGh1dMShx28Y8/X uaXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=8W+XKyignuCsN9r3In8g2YCNZwL1zkhkj/cOgD9AU3k=; b=nZ1vN8+VpCmoF3FMoG6yhyZiSThoeaH8ak3toojEKyYHHZMA/L0HeCSMxubmXAmFvd ZfnX0vSNz8/j7r5Z3Q/AvGpTyWANvCh3uvC98zo5e+69uKdQw26PTlQVSeNJG+5jzet1 bM7zjWjn89HdvFi9pr0vZ4sZLxQVTjtjUIgR5ylhC7BmBWba/nVoxiMZmX1DGYBuX3Df +UlWTQd8bA3GMcALxI6W2CI9+XM8yejl4FET6NWVtCLpNNr/H/SkNZMnslpDor1M5Agf qKJgCi8ddx0x6HhA5iewoiWl5uLQY0qc1w5U22gHtLMQu5FQG5qK+nhV//L1cAq16hSB v9sw== X-Gm-Message-State: AIkVDXI73/xrRtRE8UZO+V9IP1cAyr/rDHjS2T/HJd8uR3T5qr5+efxNN6OTDf9PtzzNAg== X-Received: by 10.46.9.20 with SMTP id 20mr5898400ljj.0.1486460603761; Tue, 07 Feb 2017 01:43:23 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id v2sm1108792lja.31.2017.02.07.01.43.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 01:43:23 -0800 (PST) Message-ID: <589996bb.02482e0a.10629.5b0e@mx.google.com> X-Google-Original-Message-ID: <1486460588-117125-1-git-send-email-Qiang(liqiang6-s@360.cn)> From: Li Qiang X-Google-Original-From: Li Qiang(liqiang6-s@360.cn) To: dmitry@daynix.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Tue, 7 Feb 2017 01:43:08 -0800 X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH] net: e1000e: fix an infinite loop issue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Li Qiang This issue is the same as e1000 network card in this commit: e1000: eliminate infinite loops on out-of-bounds transfer start. Signed-off-by: Li Qiang --- hw/net/e1000e_core.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 2b11499..53f2b1d 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -914,7 +914,8 @@ e1000e_start_xmit(E1000ECore *core, const E1000E_TxRing *txr) struct e1000_tx_desc desc; bool ide = false; const E1000E_RingInfo *txi = txr->i; - uint32_t cause = E1000_ICS_TXQE; + uint32_t tdh_start = core->mac[txi->dh], cause = E1000_ICS_TXQE; + if (!(core->mac[TCTL] & E1000_TCTL_EN)) { trace_e1000e_tx_disabled(); @@ -933,6 +934,14 @@ e1000e_start_xmit(E1000ECore *core, const E1000E_TxRing *txr) cause |= e1000e_txdesc_writeback(core, base, &desc, &ide, txi->idx); e1000e_ring_advance(core, txi, 1); + + /* + * The following avoid infinite loop, just as the e1000 + */ + if (core->mac[txi->dh] == tdh_start || + tdh_start >= core->mac[txi->dlen] / E1000_RING_DESC_LEN) { + break; + } } if (!ide || !e1000e_intrmgr_delay_tx_causes(core, &cause)) { @@ -1500,6 +1509,7 @@ e1000e_write_packet_to_guest(E1000ECore *core, struct NetRxPkt *pkt, size_t desc_size; size_t desc_offset = 0; size_t iov_ofs = 0; + uint32_t rdh_start; struct iovec *iov = net_rx_pkt_get_iovec(pkt); size_t size = net_rx_pkt_get_total_len(pkt); @@ -1509,6 +1519,7 @@ e1000e_write_packet_to_guest(E1000ECore *core, struct NetRxPkt *pkt, bool do_ps = e1000e_do_ps(core, pkt, &ps_hdr_len); rxi = rxr->i; + rdh_start = core->mac[rxi->dh]; do { hwaddr ba[MAX_PS_BUFFERS]; @@ -1605,6 +1616,10 @@ e1000e_write_packet_to_guest(E1000ECore *core, struct NetRxPkt *pkt, e1000e_ring_advance(core, rxi, core->rx_desc_len / E1000_MIN_RX_DESC_LEN); + if (core->mac[rxi->dh] == rdh_start || + rdh_start >= core->mac[rxi->dlen] / E1000_RING_DESC_LEN) { + break; + } } while (desc_offset < total_size); e1000e_update_rx_stats(core, size, total_size);