Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1448931ybl; Thu, 22 Aug 2019 14:58:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+y6TVpBZx9v/XOlDHdxhy5U7QGUAjJr2WBR4pa/p2vUiVPn1iatwYAxFHmnewFQuNePF+ X-Received: by 2002:a17:90a:77c9:: with SMTP id e9mr1740185pjs.141.1566511123485; Thu, 22 Aug 2019 14:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566511123; cv=none; d=google.com; s=arc-20160816; b=LG8gnVhL2e8uL9t1bA89LJ7nrxjvOXsfu3dVk+LTFkOeSdXpwvn+ljH8OcAZ+rksP7 UEP/dsddbRJuvzK1//pvbi87acCdGrXeNWrf7WCoKGgrTiqBSiqxhc852F2xCGQoFIcw NyzbRpU5bMhJaxqFlOHM8yoD8cswgEAiIY/8HdxlOINrH3C0pdCAJ4aExweZVLPRz4gk 8lUJBNUkWbrnk9o5yp2ZBCveqI1th7Ky/KBAMtuHE/DqFmjEWdeLpKHK9sPQPykSYb7Y dD7xS7xL4MIMjrksr1DdbFPRWxE2dD3kbKSe15NMJfwBAVzYsPH7ZX36Us5jq07On12+ Qkig== 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 :content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:cc:to:subject:dkim-signature :dkim-filter; bh=DWPKQlMQ+jod8joLVtkfrQK2+7Pe98yfIoE7LabdUfw=; b=AcwVD6Rz51mnyRmt/zYGVNY8Duwmm6WgrhsuFZFDphFcS+oFixx7EnUc9Qmv+cI+tE hvPZJGb+AmciD/eBa1q2EiZevLGp/E2qGBEoAzkggq8gyqjcGD0g7YyOin9sjq8i90HU UzIm+8Oot6GzldCmiC+PlGuDtHbKd1OS54t33YlUZk1+8JuuUiv+dtnTohrA3m4kgiGl JgOwhEkYwt+32ms3lz5et6Z/opY8EkHc+bbIB+55AglQQmz5yycR2WECgCbEcsJOcFB5 PI0+aZ55ShGjTQSPpWjplsvwbZUFLK602eVpSzNepX4l1w/m7kcrKo0bK5dyLB2Ea2Gr ztbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=pYohBkSk; 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 24si372151pgu.501.2019.08.22.14.58.28; Thu, 22 Aug 2019 14:58:43 -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=pYohBkSk; 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 S2387547AbfHVQ6p (ORCPT + 99 others); Thu, 22 Aug 2019 12:58:45 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:33621 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730411AbfHVQ6p (ORCPT ); Thu, 22 Aug 2019 12:58:45 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20190822165842euoutp0187c9c86e8835a67f1c97259446dabcff~9TTIXK-d10573305733euoutp01s for ; Thu, 22 Aug 2019 16:58:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20190822165842euoutp0187c9c86e8835a67f1c97259446dabcff~9TTIXK-d10573305733euoutp01s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1566493122; bh=DWPKQlMQ+jod8joLVtkfrQK2+7Pe98yfIoE7LabdUfw=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=pYohBkSkfcz3xzvqjT4VGiEUB5h3t8Y7mNAKaODUD5rfy4kMzVbikk37beuYZfPMk tofcRg1yEUstxssMFeiV9zGcdtID+FTn3kYdIH12xWZ/ZmtABxpZ3ptbJZbv8Jh4GA RHVZIkDvIXdQtFCmJLqt0cX5rHpD/II2gG6DqsmI= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190822165841eucas1p18126854da97c39f2a0fb6396e752b460~9TTHcjYbs2955929559eucas1p1R; Thu, 22 Aug 2019 16:58:41 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id E0.16.04374.1C9CE5D5; Thu, 22 Aug 2019 17:58:41 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20190822165840eucas1p254f3d07b75967a06651083ff270df922~9TTGaVhgQ2366923669eucas1p21; Thu, 22 Aug 2019 16:58:40 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20190822165840eusmtrp16ac4849f6016c6e144f5720048783ca6~9TTGKT7LF0979109791eusmtrp12; Thu, 22 Aug 2019 16:58:40 +0000 (GMT) X-AuditID: cbfec7f5-4ddff70000001116-7d-5d5ec9c16b69 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F2.98.04117.0C9CE5D5; Thu, 22 Aug 2019 17:58:40 +0100 (BST) Received: from [106.109.129.180] (unknown [106.109.129.180]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20190822165839eusmtip2a1b3ad3fffae3823ff4dacc29e1c2c20~9TTFPfojm1207312073eusmtip2M; Thu, 22 Aug 2019 16:58:39 +0000 (GMT) Subject: Re: [PATCH net v2] ixgbe: fix double clean of tx descriptors with xdp To: Alexander Duyck Cc: Netdev , LKML , bpf@vger.kernel.org, "David S. Miller" , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jeff Kirsher , intel-wired-lan , Eelco Chaudron , William Tu From: Ilya Maximets Message-ID: <7e9e426c-92eb-ebf8-2447-6c804a0c7135@samsung.com> Date: Thu, 22 Aug 2019 19:58:38 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0hTcRTH++3e3V2Hs5/T8mQvWBlopUYRNxAriLgQgv0TpfmYdTPTWeym vYhEV+o0H0Vpy9LQfBLpFEszoWl7ZCiZYvZAg8JH2UPXY222nFfJ/77nc76H7zlwaEI+Jval E5JPcupkZZKCkpLNRlvPxieW6Kjg0sw1jPPWG5Kx2t5IGMelesRMdZoopvzOT4Ip6dGQzNs+ G8X0ZdokjPO1XcwYRzUUY24cQszL1hKKqTaYJYyxbCkz0Ou+YzHbVDMoYlt07yRseduYiNW+ 6iVYfW02xVoyUtiinPcE+7W9n2LzmmoRO6VfFS6NkIYc5pISUjl1UGis9Ohd20XRidGA0/mW CjINaVZrkRsNeAvYHW1Ii6S0HFcjGMyrkAiFFYEz20m4XHI8haCgdeX8hLEjnRJMVQi6v9nn iu8IKidaSJfLC4dD4eRL5NLeOAi6GnJJl4nAt0kozv0tcjUovAGe1XXOmmQ4FB5+HJnlJPaD Py/0lEsvwfthcrhDLHg8wXLjw2yAG94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kv03aDbWYWUJf4M+8SM4QtLtH0ZSVUXF5i+9s5zBMYhWYhaZ+FpGUWkpZZSFoW MLKsYhRJLS3OTc8tNtIrTswtLs1L10vOz93ECIz6bcd+btnB2PUu+BCjAAejEg/via64WCHW xLLiytxDjBIczEoivGUTgUK8KYmVValF+fFFpTmpxYcYTYGem8gsJZqcD0xIeSXxhqaG5haW hubG5sZmFkrivB0CB2OEBNITS1KzU1MLUotg+pg4OKUaGHvXBytJHbxx+qgtq5fsRtY/GpmM Cww0FXS/bz14PmORP4NlfbeCWFnBi6f6/1ZZptf4PVEpuPr41JGqmVai124xhbKvdeU5c/bM 1U2nIro10uOClHlU+HR79hkeUWp9XeYQ/3vj+ynaeWcuLOo7et/p+2LfY6+2GB8V6T00rTa8 RNdtmYfbLCWW4oxEQy3mouJEAC8+QPMQAwAA X-CMS-MailID: 20190822165840eucas1p254f3d07b75967a06651083ff270df922 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190822123045eucas1p125b6e106f0310bdb50e759ef41993a91 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190822123045eucas1p125b6e106f0310bdb50e759ef41993a91 References: <20190822123037.28068-1-i.maximets@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22.08.2019 19:38, Alexander Duyck wrote: > On Thu, Aug 22, 2019 at 5:30 AM Ilya Maximets wrote: >> >> 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 comletion 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 don't need most of the >> complications implemented in the regular 'ixgbe_clean_tx_irq()' >> and 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 2: >> * 'ixgbe_clean_xdp_tx_irq()' refactored to look more like >> 'ixgbe_xsk_clean_tx_ring()'. >> >> drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 34 ++++++++------------ >> 1 file changed, 13 insertions(+), 21 deletions(-) >> >> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c >> index 6b609553329f..d1297660e14a 100644 >> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c >> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c >> @@ -633,22 +633,23 @@ 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; >> + u32 xsk_frames = 0; >> bool xmit_done; >> >> - tx_bi = &tx_ring->tx_buffer_info[i]; >> - tx_desc = IXGBE_TX_DESC(tx_ring, i); >> - i -= tx_ring->count; >> + while (likely(ntc != ntu && budget)) { > > I would say you can get rid of budget entirely. It was only really > needed for the regular Tx case where you can have multiple CPUs > feeding a single Tx queue and causing a stall. Since we have a 1:1 > mapping we should never have more than the Rx budget worth of packets > to really process. In addition we can only make one pass through the > ring since the ntu value is not updated while running the loop. OK. Will remove. > >> + union ixgbe_adv_tx_desc *tx_desc; >> + struct ixgbe_tx_buffer *tx_bi; >> + >> + tx_desc = IXGBE_TX_DESC(tx_ring, ntc); >> >> - do { >> if (!(tx_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) >> break; >> >> + tx_bi = &tx_ring->tx_buffer_info[ntc]; > > Please don't move this logic into the loop. We were intentionally > processing this outside of the loop once and then just doing the > increments because it is faster that way. It takes several operations > to compute tx_bi based on ntc, whereas just incrementing is a single > operation. OK. > >> total_bytes += tx_bi->bytecount; >> total_packets += tx_bi->gso_segs; >> >> @@ -659,24 +660,15 @@ bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector, >> >> tx_bi->xdpf = NULL; >> >> - tx_bi++; >> - tx_desc++; >> - i++; >> - if (unlikely(!i)) { >> - i -= tx_ring->count; > > So these two lines can probably just be replaced by: > if (unlikely(ntc == tx_ring->count)) { > ntc = 0; Sure. > >> - tx_bi = tx_ring->tx_buffer_info; >> - tx_desc = IXGBE_TX_DESC(tx_ring, 0); >> - } >> - >> - /* issue prefetch for next Tx descriptor */ >> - prefetch(tx_desc); > > Did you just drop the prefetch? I'll keep the prefetch in v3 because, as you fairly mentioned, it's not related to this patch. However, I'm not sure if this prefetch makes any sense here, because there is only one comparison operation between the prefetch and the data usage: while (ntc != ntu) { if (!(tx_desc->wb.status ... <...> prefetch(tx_desc); } > You are changing way too much with > this patch. All you should need to do is replace i with ntc, replace > the "do {" with "while (ntc != ntu) {", and remove the while at the > end. > >> + ntc++; >> + if (unlikely(ntc == tx_ring->count)) >> + ntc = 0; >> >> /* update budget accounting */ >> budget--; >> - } while (likely(budget)); > > As I stated earlier, budget can be removed entirely. Sure. > >> + } >> >> - 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; >> -- >> 2.17.1