From patchwork Fri Feb 10 02:19:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9565915 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 DA3B960572 for ; Fri, 10 Feb 2017 02:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C09CE28538 for ; Fri, 10 Feb 2017 02:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2A072854A; Fri, 10 Feb 2017 02:20:01 +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 3C2F928538 for ; Fri, 10 Feb 2017 02:20:01 +0000 (UTC) Received: from localhost ([::1]:41301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cc0oa-00047k-As for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Feb 2017 21:20:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cc0oA-00046M-Ou for qemu-devel@nongnu.org; Thu, 09 Feb 2017 21:19:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cc0o7-0001FB-LC for qemu-devel@nongnu.org; Thu, 09 Feb 2017 21:19:34 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:36715) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cc0o7-0001F3-DX for qemu-devel@nongnu.org; Thu, 09 Feb 2017 21:19:31 -0500 Received: by mail-wr0-x241.google.com with SMTP id k90so13672784wrc.3 for ; Thu, 09 Feb 2017 18:19:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=7YFdiWLEebphuKWMoaES0BmalxU77Sr+bWTrPPuoUjQ=; b=KlYC4Pr8otAZrpKZN6yRiRpZ2Al4mIFEEEZ5tl1rfNnLrUEGscVrc8thJ20GGo/GxS DWxKcyOjwtQ2yRMIu1kigi3HYAelxh92N4OltEI3u7qX1PynZywQ2DSM00wmnU73j3OI p0C5qXIAs3v4+9e1IfoszwJ+lZYL7vSEoR3ROA7dBQ851SNMhA7eygSQSFpmLXsKTBuB rBMum0CEPLO+rREzD/Zfb17hGRQTbi1h6UNVyUimghE87QUhzFD247jTTdGixCwdzGcE ofuBCUOD7vVEzCtiPS2Lafw7CsK4y+ZEMwBuPeLESH2RWIeQHJIwz3vg2XkaEIVZMN7J xiIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7YFdiWLEebphuKWMoaES0BmalxU77Sr+bWTrPPuoUjQ=; b=AF03ZNsLgaUFliWHFTkSfUVr2WJ9y9I+JQwxldltIhvJEI2+SpaxBXKCEQ1NTmLsmI TGVCF8I772iGs4yCAutFgX5QU1kQx4C05l/l0aoXB4URNhCKuFTwSa6HSKyNqnXhWhdG rVmG1AA23uxvkQpPcSpmUKFMe0xwP+jULAcS49AF4At3dlE+bPm0VUFgzW8iKCloWMaQ HYvrYh+jgJPYoE/2aAIGGcswinv8g9FHQhxBMuwO8Otiyu4sZ8cdOvPGAwrg6gTjxDWn mL/v1rYNExfA7CwpBZPzBOsRBc5s4mrXMR/jEFCzvFKyDs6wJyic5iRG1bSI0ijXi6wc H3tA== X-Gm-Message-State: AMke39nPPsETad0Basm05jjHXdvE2P3n7HPf48ChPjkq1N58wMk2xseQiYX2ZsxV22CaQw== X-Received: by 10.223.163.75 with SMTP id d11mr5317554wrb.87.1486693170233; Thu, 09 Feb 2017 18:19:30 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id i29sm287970wrc.25.2017.02.09.18.19.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Feb 2017 18:19:29 -0800 (PST) From: Li Qiang X-Google-Original-From: Li Qiang To: dmitry@daynix.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Thu, 9 Feb 2017 18:19:19 -0800 Message-Id: <1486693159-29029-1-git-send-email-liqiang6-s@360.cn> 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:400c:c0c::241 Subject: [Qemu-devel] [PATCH v3] 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 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 Reviewed-by: Dmitry Fleytman --- Change since v2: fix error in e1000e_ring_empty eliminate unnecessory detect code in loop Changes since v1: make wraparound detect in e1000e_ring_empty hw/net/e1000e_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 2b11499..dc94188 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] / E1000_RING_DESC_LEN; } static inline uint64_t @@ -1522,6 +1523,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);