Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1426824ybl; Thu, 22 Aug 2019 14:29:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTR96O7ZHSZN4sdJtWt2XVR871A46LAyj186dZ0eufS88OOQ4b78KIP9g3GbsY8BZT/sUw X-Received: by 2002:a17:90a:5884:: with SMTP id j4mr1856073pji.142.1566509383390; Thu, 22 Aug 2019 14:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566509383; cv=none; d=google.com; s=arc-20160816; b=Dx2wB+0J/QgJewgQyYhfN0m+8m99Z+KHCxtMtzPXNxdvnRot6XZegJudfhHdrm2Tgm CSAUmusc0yijrrmIU22fQngWq7xuhnsDojAt5XDEO5BlXROqTyhD1HI1uEFLcfLIyScK ctheSHfBqi0dxzMDdLPeRoluRJABZikHHnPH2FMabKAf4eC8NGpPvKbnalNee5ylT2gX yL4fkHZ1OdTDe9MmSu8qJ3d/CxnxcJmuqqRxzXB0JdP+8dG+9KuZMNgU06tPUkTR5sBa ngpK6c+M96vyR3kjuyFmIXtocWTYPrHKk1tRqcWIAkhDnwWfdq8/MRNuGNgvcDxAWc3b r6Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=K5QxQnSR1sLnNyiZrXphHKuKyO7cUdQ482SPnqH2Tkk=; b=dXZKNZXGa5fX6fn43JeUN/49fqPzje08tOkSBP+kGd7fQXsLXByAr5ONrNwWjtjvYR ys+o8KbglaDsKq4zeDXmgfJgFhROaQeoqXlHlgp9it+Qh3OYVuZL/yjBa65ZhkYtnK6O j8C+RNEGKHQ8/JDdHUNtDewjJZdUhOi++90692I4WZKs7B6r7az1hjja1Z7wThqtpVCf O6eZIMA/eyT80/3mZMcmdFt/rNCoc29Qcv1WyIk3mqK6fVdZfWiBDpAZ7CnSLAeZS/rJ lHuSBG8q8lF9g1F2Lo6zskyETfz2VrxP3dNqJVj8eUFGQBDlGXMDEK37ULqhEseItv60 wlVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="JZeE/ndS"; 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 97si574610pld.245.2019.08.22.14.29.28; Thu, 22 Aug 2019 14:29: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=@gmail.com header.s=20161025 header.b="JZeE/ndS"; 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 S2387625AbfHVRKP (ORCPT + 99 others); Thu, 22 Aug 2019 13:10:15 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:38122 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbfHVRKO (ORCPT ); Thu, 22 Aug 2019 13:10:14 -0400 Received: by mail-io1-f68.google.com with SMTP id p12so13402440iog.5; Thu, 22 Aug 2019 10:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K5QxQnSR1sLnNyiZrXphHKuKyO7cUdQ482SPnqH2Tkk=; b=JZeE/ndS1DDujsWeRS5HHIOitkPdDWwkdvUijQTRdl10J4ikvIGwKcnxTEeiPD/glP 8LNmLqcP32sXsX9C441KhzG+UbUW1rMLLN/J+Gl9QZMYun+cNyBouIl9LkyhucUbZiJU hkQt1brp14uFu+rFvfVUnXkHHSc+SX6ZADNiOz2mkVmglTPNTAYhFst+eREl/wsnPI4Z sdMPsgDdl9XBXRSCCXr64YinRK3h0ngVl/3Tk2xINqJr5dbUZ0s+CK5KhbF6Kp3KdAHs BlhhWb3VC+dtCno14FTjRi96i1hNhIJhhzfwuUlnVJZ5V1j3l6aOj+r9/phFZhDepJEn HRxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K5QxQnSR1sLnNyiZrXphHKuKyO7cUdQ482SPnqH2Tkk=; b=F2tEuqNGB0iOvS4bzA9CWmhWV/rF7vNLjZcVvxKjP/AIcndaQDAhj6OSFNXBBpCCyb Rh3TXBMI3jCfsJQ9Zlz5vL7sbFp9zNaGmUiVLUXS1o3w8A5C1n8D/8j+XRG1qPbyOhV7 YSGU9y2Xq+K5WCZMteySqTXMUoBgbvZMN7SmmAItJVCnGjLSGLFV+xDH1oRUjy1J8hB9 wvkmyc5qBUUIqz3dP4NZsvXNuIcFWpeyzE7QX3hRPvvCoGx6xI5GrOJGXREPwGiwgfJe n7OUgIH6V9ZBQlgiZfpLigZ4jZxNnnEn+CgiGrT0MGPUfxyNxY/LXWVZdEukNycFuAVX chYw== X-Gm-Message-State: APjAAAXl9IedxL0Svx8updOA28F0QgO5aoaBE7gNWMTLF0WKmyEycbDL PfXEm4Xuz8PMwhfIsT2GQ6vZz8tjFO+dBaZ60nE= X-Received: by 2002:a02:810:: with SMTP id 16mr521044jac.121.1566493812923; Thu, 22 Aug 2019 10:10:12 -0700 (PDT) MIME-Version: 1.0 References: <20190822123037.28068-1-i.maximets@samsung.com> <7e9e426c-92eb-ebf8-2447-6c804a0c7135@samsung.com> In-Reply-To: <7e9e426c-92eb-ebf8-2447-6c804a0c7135@samsung.com> From: Alexander Duyck Date: Thu, 22 Aug 2019 10:10:01 -0700 Message-ID: Subject: Re: [PATCH net v2] ixgbe: fix double clean of tx descriptors with xdp To: Ilya Maximets 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 22, 2019 at 9:58 AM Ilya Maximets wrote: > > 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); > } I'm not opposed to dropping the prefetch, but if you are going to do it you should do it in a separate patch.