Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1514384ybl; Thu, 22 Aug 2019 16:12:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqysUi7NOazJbG7eelvuzV1J2SEc8SK535DWOsPaBqX8N9la4z9IMFjIje2o0qF3yrQ4PeHm X-Received: by 2002:a17:902:248:: with SMTP id 66mr1383551plc.19.1566515536979; Thu, 22 Aug 2019 16:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566515536; cv=none; d=google.com; s=arc-20160816; b=GDnaIfPGLvp+LBCxnV3DX2WhJ88MNKAS2vlSO1WMbkP0uutqXX1kDb41hdr42Ikyta AXyQ39wlRyVCWU/EogwuXiKqPXF1Dsn9zZmBwPH/0F1YTmg1izvhHNMTr7hYV10ExSfq SuD8JyzUXOXijoPvMHCt5ZAqTE5GzMJjXGe8ehHf/0i//6YG863f5j4d6YPXbRwurt5Q O3jnKWEtXYSuVYmG14MD58ofiMYdUS/kA4yyMZFoqqE/m19wT+4BGtccs1E3yCBDkTbx h5BfowbpJuXpC/f9nqgyvzsjuv7Cq9B3PfHoHS27oyuDzjb3cDJ0Se7BkcFU/MF1ivI9 vy4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=UOkCLCh1WvbHpQZYwO8RvemaDSbUwqU6rhWFFCiDmsE=; b=wW7FZn8wG1ejPhWNk8kz9f1cQU26F2+4l3wJALNMlCdXP35Jh5lg31UzxQ1Bk74HNR VehxKjkTiREG1raHQGU46yDZYXuKd4EAckNr7HcjAhAFZ0TlUhw2KPPmIj8pAEArh++p RvSvJrNnthKlrTgFt1h9N0JKifdc2Nq5ruyqkdUEHYDh5EipqaMNb1EYIUvKvoWyrk+o 8Dba/IDpfVX+6zO8W+6QDSBE3sAUI8dRMbJdeDA/qG6X6JaMw+3dhA2jO8N3qpMc/TnN rwfRiO8GvoNTSB4eBhkP4qNWuLFXtwBybHELMgVFxMIiEH5k3AawDc6V90lFrKDY4y6m WWfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TPbQ2XJD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si873400pfr.97.2019.08.22.16.12.02; Thu, 22 Aug 2019 16:12:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TPbQ2XJD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390656AbfHVRM7 (ORCPT + 99 others); Thu, 22 Aug 2019 13:12:59 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:46402 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388521AbfHVRMs (ORCPT ); Thu, 22 Aug 2019 13:12:48 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20190822171246euoutp029f0af06a8e1618604c2ac7ccd61dc73c~9TfaN7uGl1897118971euoutp02h for ; Thu, 22 Aug 2019 17:12:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190822171246euoutp029f0af06a8e1618604c2ac7ccd61dc73c~9TfaN7uGl1897118971euoutp02h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1566493966; bh=UOkCLCh1WvbHpQZYwO8RvemaDSbUwqU6rhWFFCiDmsE=; h=From:To:Cc:Subject:Date:References:From; b=TPbQ2XJDJbuC8DG7na1TEViPhYVzfQuh1wa5MJXju7r1vw3m9zDcarWNF+fEC/s5Q XGybKQ1hnE5G/RihIQMbEf2kJBZ5887IxVbVln6mET5jPT00RJ+wA6xaWDsVUIWUqS sww8+vYYaQvbR1J72maXmf4HhoTMgt11UBMWvkQo= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190822171245eucas1p113b527ac20ca4f2ed2c842a3cf5cdfcc~9TfYuOA5y2704927049eucas1p1E; Thu, 22 Aug 2019 17:12:45 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id CB.76.04374.C0DCE5D5; Thu, 22 Aug 2019 18:12:44 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20190822171243eucas1p12213f2239d6c36be515dade41ed7470b~9TfXnJsX31493014930eucas1p1T; Thu, 22 Aug 2019 17:12:43 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20190822171243eusmtrp2d541b2dd599bc153d0eaa02062fc26b1~9TfXXgzaw1649316493eusmtrp2e; Thu, 22 Aug 2019 17:12:43 +0000 (GMT) X-AuditID: cbfec7f5-4f7ff70000001116-28-5d5ecd0cfc62 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 84.F8.04117.B0DCE5D5; Thu, 22 Aug 2019 18:12:43 +0100 (BST) Received: from imaximets.rnd.samsung.ru (unknown [106.109.129.180]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190822171242eusmtip15aebbf240f5ddf60e37aa801dea65411~9TfWNfopd1319413194eusmtip1T; Thu, 22 Aug 2019 17:12:42 +0000 (GMT) From: Ilya Maximets To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, "David S. Miller" , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jeff Kirsher , intel-wired-lan@lists.osuosl.org, Eelco Chaudron , William Tu , Alexander Duyck , Ilya Maximets Subject: [PATCH net v3] ixgbe: fix double clean of tx descriptors with xdp Date: Thu, 22 Aug 2019 20:12:37 +0300 Message-Id: <20190822171237.20798-1-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA0WSaUgUcRjG++/szoybq9N6/d3EYqkPiml28QelLM0GKYoIkUxr1PEoV2VH LTPIUFbTsDRKMDUPwgtUdPFKzRbZ9SrTNM/Y/GDqRuWVKYrmOkrfnvd5f+/zfHlJTFoukpER UbGsMoqJlONiYb12te+I6YfAgKOF7S5oM39ciJZWxwm0rqoBaLFDh6OSomUM5fWlCNHE4CqO BlNXCbQ5tiZC2pkUHHXW6QH63JyHozJNJ4G0hdZoeMDUw5xWl48K6KbcrwRd0jIroNNHBjC6 tuIxTnclx9E5GZMY/bttCKcz1RWAXqy1vyK+LnYPYSMj4lmly+lb4nBDkV4QU21771OeVRJY sEwHJiSkTsA1bbkoHYhJKVUGoEFr2BmWAFxe6RfwwyKA01PTwt2TKt1TjF+UAqjT9+H8sALg 29RXIiOFU06wu7IDGLUlJYPzjQ2EEcKoFiF83pm9HWVB+cClzPktiCSF1GFYXsAZpYRygxl1 TnzZAVhZ075dBqkqAmZlVW3jkPKCDS8v8YwFNOjUBK/t4GbTawGvH0J9yizgb9MAzNFs7CzO QPWPj4QxB6McYHWzC2+fhaOppQI+3gyO/NxntLEtmV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FINjFrxOWs9fWbsXJCoKfp6mn6dx12lZY7z/8Qf+V9o6Z03 KyF2svNe5dQLW1PPTcu7+k+jOfH+G3WbopW3pi2/8J/ncnXo9q1LKkVMwy+fFruwUTL9+Mu4 U+cDtyamXPRv9vXQynlgPH+PgYXYeabodQcMuVl33pKuFXUTtlz7Jrgy+crLUvH3j5RYijMS DbWYi4oTAU/1fI6UAgAA X-CMS-MailID: 20190822171243eucas1p12213f2239d6c36be515dade41ed7470b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190822171243eucas1p12213f2239d6c36be515dade41ed7470b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190822171243eucas1p12213f2239d6c36be515dade41ed7470b References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tx code doesn't clear the descriptors' status after cleaning. So, if the budget is larger than number of used elems in a ring, some descriptors will be accounted twice and xsk_umem_complete_tx will move prod_tail far beyond the prod_head breaking the completion queue ring. Fix that by limiting the number of descriptors to clean by the number of used descriptors in the tx ring. 'ixgbe_clean_xdp_tx_irq()' function refactored to look more like 'ixgbe_xsk_clean_tx_ring()' since we're allowed to directly use 'next_to_clean' and 'next_to_use' indexes. Fixes: 8221c5eba8c1 ("ixgbe: add AF_XDP zero-copy Tx support") Signed-off-by: Ilya Maximets --- Version 3: * Reverted some refactoring made for v2. * Eliminated 'budget' for tx clean. * prefetch returned. Version 2: * 'ixgbe_clean_xdp_tx_irq()' refactored to look more like 'ixgbe_xsk_clean_tx_ring()'. drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 29 ++++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c index 6b609553329f..a3b6d8c89127 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c @@ -633,19 +633,17 @@ static void ixgbe_clean_xdp_tx_buffer(struct ixgbe_ring *tx_ring, bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector, struct ixgbe_ring *tx_ring, int napi_budget) { + u16 ntc = tx_ring->next_to_clean, ntu = tx_ring->next_to_use; unsigned int total_packets = 0, total_bytes = 0; - u32 i = tx_ring->next_to_clean, xsk_frames = 0; - unsigned int budget = q_vector->tx.work_limit; struct xdp_umem *umem = tx_ring->xsk_umem; union ixgbe_adv_tx_desc *tx_desc; struct ixgbe_tx_buffer *tx_bi; - bool xmit_done; + u32 xsk_frames = 0; - tx_bi = &tx_ring->tx_buffer_info[i]; - tx_desc = IXGBE_TX_DESC(tx_ring, i); - i -= tx_ring->count; + tx_bi = &tx_ring->tx_buffer_info[ntc]; + tx_desc = IXGBE_TX_DESC(tx_ring, ntc); - do { + while (ntc != ntu) { if (!(tx_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) break; @@ -661,22 +659,18 @@ bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector, tx_bi++; tx_desc++; - i++; - if (unlikely(!i)) { - i -= tx_ring->count; + ntc++; + if (unlikely(ntc == tx_ring->count)) { + ntc = 0; tx_bi = tx_ring->tx_buffer_info; tx_desc = IXGBE_TX_DESC(tx_ring, 0); } /* issue prefetch for next Tx descriptor */ prefetch(tx_desc); + } - /* update budget accounting */ - budget--; - } while (likely(budget)); - - i += tx_ring->count; - tx_ring->next_to_clean = i; + tx_ring->next_to_clean = ntc; u64_stats_update_begin(&tx_ring->syncp); tx_ring->stats.bytes += total_bytes; @@ -688,8 +682,7 @@ bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector, if (xsk_frames) xsk_umem_complete_tx(umem, xsk_frames); - xmit_done = ixgbe_xmit_zc(tx_ring, q_vector->tx.work_limit); - return budget > 0 && xmit_done; + return ixgbe_xmit_zc(tx_ring, q_vector->tx.work_limit); } int ixgbe_xsk_async_xmit(struct net_device *dev, u32 qid) -- 2.17.1