From patchwork Thu Feb 9 02:11:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9563885 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 B7340601EA for ; Thu, 9 Feb 2017 02:12:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 019E9284CE for ; Thu, 9 Feb 2017 02:12:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7FBD28517; Thu, 9 Feb 2017 02:12:32 +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 402D4284CE for ; Thu, 9 Feb 2017 02:12:31 +0000 (UTC) Received: from localhost ([::1]:35017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbeDl-0006qm-N1 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Feb 2017 21:12:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbeDS-0006mD-OS for qemu-devel@nongnu.org; Wed, 08 Feb 2017 21:12:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbeDN-0004o2-R7 for qemu-devel@nongnu.org; Wed, 08 Feb 2017 21:12:10 -0500 Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]:33009) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cbeDN-0004nu-LJ for qemu-devel@nongnu.org; Wed, 08 Feb 2017 21:12:05 -0500 Received: by mail-io0-x242.google.com with SMTP id 101so851263iom.0 for ; Wed, 08 Feb 2017 18:12:05 -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=To0fNCXvBtwAZdXDW9W1XotxjOqbFbwxdCNcnHvVv1c=; b=IWLkestTqMLQ4diTUyEHEYp76QqegB38GtENVdgJvRASzJaATAIX70hxu6GC9EQwTc iYOtlIG7Uc6moVlabAExNAqGDb8bxJUY9eI9cpdalmxRXchfsnW7hSElsp1ZDbMA2ahJ YDzMpPNmb9vO/FHeulRPIeTMKXARR+bUew1/ihzD0AJa9bNN5FehEr1WF0vMp6Kb1kSd P+eXcwpGs/GbLB0W687wo+mv5bKrdual8ecLftKS4aMniNcMo4CxOS7a+MGxoSCRexSZ h9keCXs7VQzQEL+44kRMBjDtEGFoZ2d9yDiIuEG71xVoFov23n+xAtnInSIVOvGH4esF Fg4w== 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=To0fNCXvBtwAZdXDW9W1XotxjOqbFbwxdCNcnHvVv1c=; b=HVWNGlDzqRW4geGSYZ+0Juu5nNGiGFEIgszmRjUeT+oe3OeuUlBwWmYwzyYFLiGhGP 80Els9BqB7vfEmQChzwJDVo3ibil3s2W7INNGr8IGQ0P87NFqtSqAhj0yqfl6P1/peVV YSntKk4xPfP3GnhrlEmSGiOg6MPy2OCEdzp7hUO/PbUOz9pjtVRqBQ5Dpn/pvCYocFQp fMbVN6/FO2GBIZ5VHCp8lVxXIh+4Mx+KysyVCYKl9ovERnH6nFODls3grECMjmVU49YG gLUT1fRkFibx2Y7nukqtS2O0iqIWbhdxfH+AfWY3N4BYi83aHgFEZPocFhaTO1biv1Z0 ARKg== X-Gm-Message-State: AMke39l0O+ocESX/2V+Awx3MXNMlJ+p18c3jrvWukqtmPWBQZAMjB1jNLqCykzsNS4WZ9A== X-Received: by 10.107.84.2 with SMTP id i2mr1321610iob.176.1486606325050; Wed, 08 Feb 2017 18:12:05 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id m127sm2122648itc.10.2017.02.08.18.12.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2017 18:12:04 -0800 (PST) Message-ID: <589bcff4.856d240a.3dcfb.a4be@mx.google.com> X-Google-Original-Message-ID: <1486606284-40933-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: Wed, 8 Feb 2017 18:11:24 -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: 2607:f8b0:4001:c06::242 Subject: [Qemu-devel] [PATCH v2] 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 like the issue in e1000 network card addressed in this commit: e1000: eliminate infinite loops on out-of-bounds transfer start. Signed-off-by: Li Qiang --- Changes since v1: make wraparound detect in e1000e_ring_empty hw/net/e1000e_core.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 2b11499..d4c56c3 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -806,7 +806,8 @@ typedef struct E1000E_RingInfo_st { static inline bool e1000e_ring_empty(E1000ECore *core, const E1000E_RingInfo *r) { - return core->mac[r->dh] == core->mac[r->dt]; + return core->mac[r->dh] == core->mac[r->dt] || + core->mac[r->dt] >= core->mac[r->dlen]; } static inline uint64_t @@ -914,7 +915,7 @@ 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]; @@ -1522,6 +1533,10 @@ e1000e_write_packet_to_guest(E1000ECore *core, struct NetRxPkt *pkt, desc_size = core->rx_desc_buf_size; } + if (e1000e_ring_empty(core, rxi)) { + return; + } + base = e1000e_ring_head_descr(core, rxi); pci_dma_read(d, base, &desc, core->rx_desc_len); @@ -1605,6 +1620,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);