Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4196593ybl; Tue, 20 Aug 2019 08:19:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzp38CllxtbEamEFc2ryaUpCzUzEXnBI6aWPJDZiFd/Pfj9RsEYh//gLiPkrZUx/K6mJEVb X-Received: by 2002:aa7:939c:: with SMTP id t28mr21535467pfe.111.1566314368363; Tue, 20 Aug 2019 08:19:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566314368; cv=none; d=google.com; s=arc-20160816; b=Iu6eSWpCXtsXawQHEbMtUrBJAO0cQ0zmwHubGtSvTR/XaC/4ibmjQXcrSmiBjI515y lMTkPolO8ggAI9OaRnyKR8knTmkGS6Il445S/U0SIhnMUub238FnoNjvmar0IcJQdCWA eyxhm3vAGU1qqMd3H3B6a0VzT6YTPXgGxJEwZfPWObl8otOZSsxkVKT+zEwipwss7Xgh eyPwfzvX0/hTMwCxZjs42PZEXi0wJInTJjgbL18n6+GRW415vPlPbHjvdHkS/FUIYRTb F5cx0m6Jn2rIcGBl0/8mDSgzV4oNWmPECgPVXPyqdD+GQfipJGmoG6K5j2Xdd8k+VHyU Izhw== 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=u6FQ7hQL4erTGneWwI1MFa2IOEl01CEEf2XpifqS9nc=; b=r2f/y6CKIdjzDMJyb1xqo3eOSVSW1WqogvViEgksLTuRmm2J7vJZebXVHx/bBV8kSu aBCSh2aJxGpwAAERQA6M2vmBk2JYcvW4Al7VTPlT0I2BGny5/F9l1Ah5zohSz4uJQlgZ uKo0by5qJ3/iSWKqsvFW+E7dPQGC+WlSS9QgY1Mz3sDPhA1o97hhFfew7/KnDLejFYWn MO3W1AeFBUSCwzXKV/HhZ6wm6hKhkv+3PQE9qx/hmNm2aUvmH5mK/uzfEftOjFqQj5Fa /+wan7PdJHPuPp/Fm169frLQop5FpALU9oBCFf9piXqru95Gyi0ColDGvCvmxoMyrTnf /Lhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=ka6rveMe; 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 g13si12284623pgp.405.2019.08.20.08.19.12; Tue, 20 Aug 2019 08:19:28 -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=ka6rveMe; 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 S1729999AbfHTPQs (ORCPT + 99 others); Tue, 20 Aug 2019 11:16:48 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:59613 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728277AbfHTPQs (ORCPT ); Tue, 20 Aug 2019 11:16:48 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20190820151646euoutp022156ff76cc8d84c95acaabf7c2e8833d~8qnjVB2e80068400684euoutp02X for ; Tue, 20 Aug 2019 15:16:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190820151646euoutp022156ff76cc8d84c95acaabf7c2e8833d~8qnjVB2e80068400684euoutp02X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1566314206; bh=u6FQ7hQL4erTGneWwI1MFa2IOEl01CEEf2XpifqS9nc=; h=From:To:Cc:Subject:Date:References:From; b=ka6rveMen+i6dv2KNqvaMPeW1SdX/QssqbFpi3ovKlBgdRSvPc26PO8trOnrstlzq 8o2ZOgAQvLVzI3kQ5jj3tU5eJh7+7g6pGnMew3SwLSY+9UP5tosw+GW1LwL6Q2KYms AUP0JhPHlITowwn/TvbuGh4Zl+ixy3+JuIuDMENE= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190820151645eucas1p1c7b02f5c537ff321d72b4dfc2bec7a96~8qnigAiVb3120631206eucas1p18; Tue, 20 Aug 2019 15:16:45 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 78.6C.04374.DDE0C5D5; Tue, 20 Aug 2019 16:16:45 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20190820151644eucas1p179d6d1da42bb6be0aad8f58ac46624ce~8qnhyLR5k3121031210eucas1p1t; Tue, 20 Aug 2019 15:16:44 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20190820151644eusmtrp1343cb6d503ed2154d0b4334385104263~8qnhjrOdg0975009750eusmtrp1R; Tue, 20 Aug 2019 15:16:44 +0000 (GMT) X-AuditID: cbfec7f5-4f7ff70000001116-d1-5d5c0eddc77c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 5B.54.04117.CDE0C5D5; Tue, 20 Aug 2019 16:16:44 +0100 (BST) Received: from localhost.localdomain (unknown [106.109.129.180]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190820151643eusmtip187a1a770159210ae5299335530e59ebb~8qngrwYhZ0740207402eusmtip10; Tue, 20 Aug 2019 15:16:43 +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 , Ilya Maximets Subject: [PATCH net] ixgbe: fix double clean of tx descriptors with xdp Date: Tue, 20 Aug 2019 18:16:11 +0300 Message-Id: <20190820151611.10727-1-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA0WSa0hTcRjG/e/sXDacHafmm0rBtKDINPLDsdKKos6XoAyKtFGrDia5KTvN NKmslpWVhV1GNUKZoc1E0ZEXKtaU2VIUTfFSy1YRqV0YunBMLLcz6dvv/T/P8z7vhz+FyWvw GCpHc4rTalS5CkIqfm739iU6ww4pk792SJgZ73uSmSttRMx0ZxfBmKr+YIyxTy9mPgx6CWbw ipdk/o75cMb+XU8wb5rHEfOu3UgwtbY3JGOvXMoMD4RuDWMtT0dFbNtDJ8maXkyI2LKRAYxt Ml8jWMclHWu47sLY36+GCLbcYkbsdNPyPdJM6ebjXG5OAadNSj8iPVHn+Ibn2+MKXW2TZAkq gTIkoYBOgXGXCStDUkpO1yLwDU+JhGEGQdv7n6QwTCMwG0fFi5HP9qqgqwbB4/LhYN6DwNrR h/ldBL0W3tZ1Ij9H0jHgbm0JrMLoW2Ko/+EOCBH0Lpiv9uJ+FtMrYcphXzBRlIzeBCMGXGhb AXWN1kAB0GYSZrsfIEHYASXX/ooEjoDJLgspcBx037kRPPU8jOsnkBC+isBgmw8GtoBlqjdQ htGroaE9yY9AbwPP5dUChsHIz3C/GVvAiucGTHiWwdVSubAjAXyvazCBY2D013TwABYae02B I+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Vq2+L6ZuiCo9 GbNCLnFX6zWuB1MW5K5fs/7C132dkydqy9mv2rpDyyh/o8BK1QJWsX6r4AcSguqBxaJ8wj17 392pMAjMli4tWn2+QPLS8eO/6r1WGFya+yzcwE799wzrwAnrliuuu/5llu1uJZbijERDLeai 4kQApQXTW5ECAAA= X-CMS-MailID: 20190820151644eucas1p179d6d1da42bb6be0aad8f58ac46624ce X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190820151644eucas1p179d6d1da42bb6be0aad8f58ac46624ce X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190820151644eucas1p179d6d1da42bb6be0aad8f58ac46624ce 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 descriptor 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 comletion queue ring. Fix that by limiting the number of descriptors to clean by the number of used descriptors in the tx ring. Fixes: 8221c5eba8c1 ("ixgbe: add AF_XDP zero-copy Tx support") Signed-off-by: Ilya Maximets --- Not tested yet because of lack of available hardware. So, testing is very welcome. drivers/net/ethernet/intel/ixgbe/ixgbe.h | 10 ++++++++++ drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 12 +----------- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 6 ++++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/ethernet/intel/ixgbe/ixgbe.h index 39e73ad60352..0befcef46e80 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h @@ -512,6 +512,16 @@ static inline u16 ixgbe_desc_unused(struct ixgbe_ring *ring) return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; } +static inline u64 ixgbe_desc_used(struct ixgbe_ring *ring) +{ + unsigned int head, tail; + + head = ring->next_to_clean; + tail = ring->next_to_use; + + return ((head <= tail) ? tail : tail + ring->count) - head; +} + #define IXGBE_RX_DESC(R, i) \ (&(((union ixgbe_adv_rx_desc *)((R)->desc))[i])) #define IXGBE_TX_DESC(R, i) \ diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index 7882148abb43..d417237857d8 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -1012,21 +1012,11 @@ static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) return ring->stats.packets; } -static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) -{ - unsigned int head, tail; - - head = ring->next_to_clean; - tail = ring->next_to_use; - - return ((head <= tail) ? tail : tail + ring->count) - head; -} - static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) { u32 tx_done = ixgbe_get_tx_completed(tx_ring); u32 tx_done_old = tx_ring->tx_stats.tx_done_old; - u32 tx_pending = ixgbe_get_tx_pending(tx_ring); + u32 tx_pending = ixgbe_desc_used(tx_ring); clear_check_for_tx_hang(tx_ring); diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c index 6b609553329f..7702efed356a 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c @@ -637,6 +637,7 @@ bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector, 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; + u32 used_descs = ixgbe_desc_used(tx_ring); union ixgbe_adv_tx_desc *tx_desc; struct ixgbe_tx_buffer *tx_bi; bool xmit_done; @@ -645,7 +646,7 @@ bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector, tx_desc = IXGBE_TX_DESC(tx_ring, i); i -= tx_ring->count; - do { + while (likely(budget && used_descs)) { if (!(tx_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) break; @@ -673,7 +674,8 @@ bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector, /* update budget accounting */ budget--; - } while (likely(budget)); + used_descs--; + } i += tx_ring->count; tx_ring->next_to_clean = i; -- 2.17.1