Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4178229ybl; Mon, 26 Aug 2019 06:42:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZ9shS+0WBPmdc1xCjiN/VJY/uScncOS4QsWmtOWR3//mTend4r+nufx+pMZAIvddju5X/ X-Received: by 2002:a65:6401:: with SMTP id a1mr16498603pgv.42.1566826956860; Mon, 26 Aug 2019 06:42:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566826956; cv=none; d=google.com; s=arc-20160816; b=h0rsRf0hSGFl7hEpdYqqw8tVk9vQbtD+zy2jlORdn6RY4us7noB9JpPaEDAKlLcgGy mwgod1tJ9afRHGIbtRDJrbt20YlJ+rUu4gwL6nrrQ8OMYGzOt2bI7neUTwD3j1npL7u3 oN7fIRjB4eL7B11IskmFFQ6I8SFQzYiDQ4lP30VWOSCtsZx7h6dkOiPxOJ5CQPwFUwj8 m4JD4DhMst1hgGVGZTp5mtVDFk+WBrPtrwQnfkPR+krhk5/vP5q74Q4pu87QgEHdv78Z lMy6Iv9u4GrKRXZmrZZpjFnkMpGoy/wxgR7fKjvT2rNK7/tuGXgIF1QmJv/pOu3tDbRq yJCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=rBGgnC50tEqUQpJ+f65Q91HGdjIjtC+5DlqiDSMP1/Q=; b=My+aeqhTqFWfaTP/+yYJW8mNWcGMzsKlf5AFYEjwWb3ntWYkDV2/o6VQc7Jyq8LnbB cjSfc72CxpJHCKuTqJQNYDBVE1clO3mp+pSiaR3x0cGvuMv8ZmbAPOqyO+iuAo73BpGz rAdhpopSw4uGpXeaYGqLEYgHAwOfWx60o1NwN8x0sNuWvqp90DZ6PiQEZq3oMyyrl1/w 7lmSo9H6m8W9n9yii4LXJFyiMuHL1j4xbOsV6DiaSioQov1uDWAPR7UfpC8ssyWd2OBI MAmRjHUyUZoIsW4yGXrRffGe2oAEDS4UgzuyuWuarM31xbvrsOrGTDVMFVeP4IEm17nI o/4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=afRo5XfL; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si10479809pfp.255.2019.08.26.06.42.20; Mon, 26 Aug 2019 06:42:36 -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=@gmail.com header.s=20161025 header.b=afRo5XfL; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731505AbfHZNk7 (ORCPT + 99 others); Mon, 26 Aug 2019 09:40:59 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44439 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728295AbfHZNk7 (ORCPT ); Mon, 26 Aug 2019 09:40:59 -0400 Received: by mail-pl1-f195.google.com with SMTP id t14so10044530plr.11; Mon, 26 Aug 2019 06:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rBGgnC50tEqUQpJ+f65Q91HGdjIjtC+5DlqiDSMP1/Q=; b=afRo5XfL1dnaButfIoJqTh3HWsWdfH0C/Pa8CA105hesfqqeFTx293NH2E4Cz/6fM7 TNs8KLbLJ8TuBk6JUzLt22sAoN0iEg65D/pjLsW7lC2HLvTFaNZD9WE/deeC2oXMFnd9 SS+xPJB1Q4cX2atWlPzTYPWdz478+1oaXD//7C57jtEPABMbU/XcR1iZr2iWD6HcOdEH KK6i/QHOcBuR2/bFt+v9+WcqZYbttAaoTy3hA0NV/J9Di4IjKIxGiVJkQ2UsMdh1y5Ch gTCxuVWYECdBGgmp7O5++TYOVTjO+dge+5Afttr5iBBpIlcNN04QKMRJztev0B8rIOzY PBpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rBGgnC50tEqUQpJ+f65Q91HGdjIjtC+5DlqiDSMP1/Q=; b=SzuZjg0Yqqilj0UKaeWh/bDMX61qCXZNZTXb8aO7muzAptmG8wEjaEMc7MDj/pvyF8 OvUvfC1pOwkI2YHVDzakGpoZwaBBud8/bMS2EDUfgFLNhCy2SSEeDnz/ZiAod2jf/T0v g8gSgc5AzzrH4zTllkJFczvHEQ3VwcgHq2dVo/lEcVm/LYP1eRFPxN6cLfQpr2r7WUtL CiRa+5OXc4b0OXeqrmqpe6baO4YC6lfcqSgz4M2cDr623g/8dnePh9Qc0ExNamLX7XDY pihmeJSI8TjiXHp4lDjvSmW2h+9mYIwOjePKsyKCmYEBoQE6ALi4YF+0M7CzQJWuiMZd oMxQ== X-Gm-Message-State: APjAAAWUm7JmxIy1n4kAz9kyIUiiHUOq1lGJg1Go61DRrrD9We44K9R9 iKlL76o0hLouFu7Ift+ZL0c= X-Received: by 2002:a17:902:43:: with SMTP id 61mr19425725pla.145.1566826857867; Mon, 26 Aug 2019 06:40:57 -0700 (PDT) Received: from localhost ([192.55.54.44]) by smtp.gmail.com with ESMTPSA id p5sm13565558pfg.184.2019.08.26.06.40.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Aug 2019 06:40:57 -0700 (PDT) Date: Mon, 26 Aug 2019 15:40:42 +0200 From: Maciej Fijalkowski To: Ilya Maximets Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, "David S. Miller" , =?ISO-8859-1?Q?Bj=F6rn_T=F6pel?= , Magnus Karlsson , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jeff Kirsher , intel-wired-lan@lists.osuosl.org, Eelco Chaudron , William Tu , Alexander Duyck Subject: Re: [PATCH net v3] ixgbe: fix double clean of tx descriptors with xdp Message-ID: <20190826154042.00004bfc@gmail.com> In-Reply-To: <20190822171237.20798-1-i.maximets@samsung.com> References: <20190822171237.20798-1-i.maximets@samsung.com> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 22 Aug 2019 20:12:37 +0300 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 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) While you're at it, can you please as well remove the 'napi_budget' argument? It wasn't used at all even before your patch. I'm jumping late in, but I was really wondering and hesitated with taking part in discussion since the v1 of this patch - can you elaborate why simply clearing the DD bit wasn't sufficient? Maciej > { > + 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)