Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp225071ybl; Tue, 20 Aug 2019 18:48:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgS6o/9hWChmKbuGL/ZvKSClvsSzBPGUFecfnkxggnj3M2CtCJY5NkKXtFUp3Zcx9PRZmX X-Received: by 2002:a17:902:1a7:: with SMTP id b36mr30571263plb.115.1566352107740; Tue, 20 Aug 2019 18:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566352107; cv=none; d=google.com; s=arc-20160816; b=I03nFOd8a1agOkMD4TIAsCqKZxBd32w9DlManNKc3tvspKi4Cc3J10D8LK6oBvh3Vi 8daEL5WQa8j9Ncnfv72B8Nw+FKH+eyCB2U20ycMcxEeeN/dMFxq1eHr9rDFdeRLrFcJK XArh4Fn0nXlBGBTk9P2snBT3zNAzR9ZLjHpRdwCzt8//J0c153SeCqvOC/CwKk++OiWR MC5itJ8ZJqI0Kp3C+5OqwMqs6yOcn7Iiur9XK+/pzGgqZ8H+xXswHEptEXAJLnvbVvwd JE3MqANnVZ8GMTDU93hiEPLoq5HEvZ49oWQD5gPlX+6qh3Q9bEMxhYq1LYaEMNHBOOAk 6yhg== 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=kZWHrTprV1/7KUdKW3G6OHYWGjOaGD0IoU996R//irc=; b=NwN+2F/4yZWheL7tecoZpMwaXg7UKirFEE2h3wiy6/sZNOcMIwTXqs4Fr1HS3a6wgD Y8/oWhRHtGsVt5XSVlcYbNYqNxYGrQdUPdKT4SQMbnSm6r4g0Ion1CJBgIll6vJKMID9 TJ+s5+9qo9KuCGCaXkoRagcvumYUCopFM02GBvDeKR94f3bVBE33EhLFiJAviydNSSU6 Vf8tQdqXqbbo4YZyYLma/UkfV3G0mBfqWP90zCqVnAy8naqnOrUw2zW1jdrILygPijI0 j7Dl+lB3YG5It87eDfLaS7KbWuOESUnRGlmeBE3PNyKhqjKJ7x1m/O52lmppWgflYpah tf5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="PW/FNmKO"; 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 i23si14194839pfa.196.2019.08.20.18.48.10; Tue, 20 Aug 2019 18:48:27 -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="PW/FNmKO"; 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 S1726753AbfHUBRN (ORCPT + 99 others); Tue, 20 Aug 2019 21:17:13 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:41486 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbfHUBRM (ORCPT ); Tue, 20 Aug 2019 21:17:12 -0400 Received: by mail-io1-f67.google.com with SMTP id j5so1246592ioj.8; Tue, 20 Aug 2019 18:17:12 -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=kZWHrTprV1/7KUdKW3G6OHYWGjOaGD0IoU996R//irc=; b=PW/FNmKOjoHqHBgeKuzcejPrWtquvNRR8hFw19cBinEnE7gl0RdKyYw2XhZFsMK5l8 jSWcbl+meQnv7sxj8jqKKU3UIX3V+6MXUy8oV7zb9opsXDeeAi4xDzQRHCGUp6E7iFrN 8bWY7qXYx+av2KfejCyBNsCYm3VxnL7YaA6eajUZ3RFxY6mAR/YLmt003MKqW0/tIbX1 qcLZKcc7MA7q9HnC9CmAv6ZQxtd3J9rVvcvNdIWPW4hm+wlvNikXZqVM4e7cOCiD4/vZ DnA2tCTB5rUV7i43BoOjjvGGEWYorK7nKtvSlDicQz7tL3nrLpg8pa1gaUgFwVF2TwCF nYdw== 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=kZWHrTprV1/7KUdKW3G6OHYWGjOaGD0IoU996R//irc=; b=P674LPmtp7bPIRbsWYBdCYFk6ZrCdQaHT9C9WYbqfixnUBC5T74jrTsqZGJjZgIj0j Ymi8bHtKkMBC/V8at5KpEVyGmURLN/PUZLd2gpFOwua+hxKRUiKhX0f5mQX3fsLCqzc2 YQnBnSylcPlkfmhzPLz/5cE4d/kTdt1KHOtFzqeWRaZWHgHQYaX/V6rirZbwNZRhzxsj 7vnuYjzyJy1AlvdSWo5mqoSxvuGcvrHtsM+kxorfnPvjw6ErIgON8ti0DUQhbzcFffIe L1XIhct+dRewCc1+V0c0TPUWFzIudBu5YFwn7MEnmnkXfrDtWwDXQCvuwviDU2K0p3KI mKkw== X-Gm-Message-State: APjAAAWs5CGHkozDZUE0HxvOoibumzZl7prYiM8mE5gdxT+pL9gm0D+8 OCs2exrBS+eOZgT1IDdQPFedDTGW4wGf9kPN7nA= X-Received: by 2002:a5d:8b47:: with SMTP id c7mr24228155iot.42.1566350231784; Tue, 20 Aug 2019 18:17:11 -0700 (PDT) MIME-Version: 1.0 References: <20190820151611.10727-1-i.maximets@samsung.com> <625791af-c656-1e42-b60e-b3a5cedcb4c4@samsung.com> In-Reply-To: <625791af-c656-1e42-b60e-b3a5cedcb4c4@samsung.com> From: Alexander Duyck Date: Tue, 20 Aug 2019 18:17:00 -0700 Message-ID: Subject: Re: [PATCH net] 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 Tue, Aug 20, 2019 at 8:58 AM Ilya Maximets wrote: > > On 20.08.2019 18:35, Alexander Duyck wrote: > > On Tue, Aug 20, 2019 at 8:18 AM Ilya Maximets wrote: > >> > >> 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 > > > > I'm not sure this is the best way to go. My preference would be to > > have something in the ring that would prevent us from racing which I > > don't think this really addresses. I am pretty sure this code is safe > > on x86 but I would be worried about weak ordered systems such as > > PowerPC. > > > > It might make sense to look at adding the eop_desc logic like we have > > in the regular path with a proper barrier before we write it and after > > we read it. So for example we could hold of on writing the bytecount > > value until the end of an iteration and call smp_wmb before we write > > it. Then on the cleanup we could read it and if it is non-zero we take > > an smp_rmb before proceeding further to process the Tx descriptor and > > clearing the value. Otherwise this code is going to just keep popping > > up with issues. > > But, unlike regular case, xdp zero-copy xmit and clean for particular > tx ring always happens in the same NAPI context and even on the same > CPU core. > > I saw the 'eop_desc' manipulations in regular case and yes, we could > use 'next_to_watch' field just as a flag of descriptor existence, > but it seems unnecessarily complicated. Am I missing something? > So is it always in the same NAPI context?. I forgot, I was thinking that somehow the socket could possibly make use of XDP for transmit. As far as the logic to use I would be good with just using a value you are already setting such as the bytecount value. All that would need to happen is to guarantee that the value is cleared in the Tx path. So if you clear the bytecount in ixgbe_clean_xdp_tx_irq you could theoretically just use that as well to flag that a descriptor has been populated and is ready to be cleaned. Assuming the logic about this all being in the same NAPI context anyway you wouldn't need to mess with the barrier stuff I mentioned before. - Alex