Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1936378ybi; Thu, 4 Jul 2019 02:20:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyN8BDkXFGeDySLCVQObcAr/eSW5KtMZ/TiKV11/DRtmAMXDpL0ybXeFD07+8wSv3caYUVm X-Received: by 2002:a63:c508:: with SMTP id f8mr11733242pgd.48.1562232058714; Thu, 04 Jul 2019 02:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562232058; cv=none; d=google.com; s=arc-20160816; b=Xwak0ivMmhBtOPjk2F+dyPzzO3kh+d7G8xY9Qg2f8Xc5PC29vNb7ZMSWP4U74tiG8V 8SMrvkYQDH3nOYOmBK0ekAzA7rftoeJfLdMLvbaqv9iUlJdpgohv3lQPcuWbenOqxNvA XGDTjUUaIEi3WlDaGrgAfH6g6wJHem+3j+lGMaLRo/sb28hiufzRF59KKCOa0G1eFLBZ sA3QihjQVNr8wc08w61NsMNPowDMSscadLkhaF7z4x3/bjbYnS28JdY8z7ny3xqjuUBG nkQP7Mbv6oBomgDJ3K/VHm91Cy5et/3MWowrTQ0DIZcZeBMpLfpHHG+LEFT/p+IzO4Ks FbwA== 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; bh=K1irUDo4rZqvYtkv1geDd9pMZ/QauTgM3TBzce8aRHo=; b=ydjrP7WYnvSpJDN1daWt231ZQ7UjH3fO2keBtnPLDl5g+OxdUvgUJzdZl2/vJtZoPN pacv0Y07l4tAn3lsjRn15miocJspE9JRckJvRVERVG1JsIq8//Eki3kNzcQcrqNu09Zn wrUmii+NYcZy3+8WhVYlzOtBLh3mhbGtP9cGSkXhlAXPV4iE7UjC1xsCT7QWZdX6DIah nyqGmZk2fHLO7FUVj9d52YEwvXSTV9giD1iT9gCVvdDlIjdlIhXtNsrkKpp1o/BSTn/3 sZyISx4gy8bLretfwkEc2Bsoxt2JSTcycRi/ccMJc2+c1NQxt7cS/A5YXhJrAaOozxQU HY7w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 21si5018147pfo.138.2019.07.04.02.20.43; Thu, 04 Jul 2019 02:20:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbfGDJTu (ORCPT + 99 others); Thu, 4 Jul 2019 05:19:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42448 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727147AbfGDJTu (ORCPT ); Thu, 4 Jul 2019 05:19:50 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AFED3082129; Thu, 4 Jul 2019 09:19:49 +0000 (UTC) Received: from carbon (ovpn-200-17.brq.redhat.com [10.40.200.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AF2D1001B1B; Thu, 4 Jul 2019 09:19:41 +0000 (UTC) Date: Thu, 4 Jul 2019 11:19:39 +0200 From: Jesper Dangaard Brouer To: Ivan Khoronzhuk Cc: grygorii.strashko@ti.com, hawk@kernel.org, davem@davemloft.net, ast@kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, xdp-newbies@vger.kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, john.fastabend@gmail.com, brouer@redhat.com Subject: Re: [PATCH v6 net-next 5/5] net: ethernet: ti: cpsw: add XDP support Message-ID: <20190704111939.5d845071@carbon> In-Reply-To: <20190703101903.8411-6-ivan.khoronzhuk@linaro.org> References: <20190703101903.8411-1-ivan.khoronzhuk@linaro.org> <20190703101903.8411-6-ivan.khoronzhuk@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 04 Jul 2019 09:19:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 3 Jul 2019 13:19:03 +0300 Ivan Khoronzhuk wrote: > Add XDP support based on rx page_pool allocator, one frame per page. > Page pool allocator is used with assumption that only one rx_handler > is running simultaneously. DMA map/unmap is reused from page pool > despite there is no need to map whole page. > > Due to specific of cpsw, the same TX/RX handler can be used by 2 > network devices, so special fields in buffer are added to identify > an interface the frame is destined to. Thus XDP works for both > interfaces, that allows to test xdp redirect between two interfaces > easily. Aslo, each rx queue have own page pools, but common for both > netdevs. > > XDP prog is common for all channels till appropriate changes are added > in XDP infrastructure. Also, once page_pool recycling becomes part of > skb netstack some simplifications can be added, like removing > page_pool_release_page() before skb receive. > > In order to keep rx_dev while redirect, that can be somehow used in > future, do flush in rx_handler, that allows to keep rx dev the same > while reidrect. It allows to conform with tracing rx_dev pointed > by Jesper. So, you simply call xdp_do_flush_map() after each xdp_do_redirect(). It will kill RX-bulk and performance, but I guess it will work. I guess, we can optimized it later, by e.g. in function calling cpsw_run_xdp() have a variable that detect if net_device changed (priv->ndev) and then call xdp_do_flush_map() when needed. > Signed-off-by: Ivan Khoronzhuk > --- > drivers/net/ethernet/ti/Kconfig | 1 + > drivers/net/ethernet/ti/cpsw.c | 485 ++++++++++++++++++++++--- > drivers/net/ethernet/ti/cpsw_ethtool.c | 66 +++- > drivers/net/ethernet/ti/cpsw_priv.h | 7 + > 4 files changed, 502 insertions(+), 57 deletions(-) > [...] > +static int cpsw_run_xdp(struct cpsw_priv *priv, int ch, struct xdp_buff *xdp, > + struct page *page) > +{ > + struct cpsw_common *cpsw = priv->cpsw; > + struct net_device *ndev = priv->ndev; > + int ret = CPSW_XDP_CONSUMED; > + struct xdp_frame *xdpf; > + struct bpf_prog *prog; > + u32 act; > + > + rcu_read_lock(); > + > + prog = READ_ONCE(priv->xdp_prog); > + if (!prog) { > + ret = CPSW_XDP_PASS; > + goto out; > + } > + > + act = bpf_prog_run_xdp(prog, xdp); > + switch (act) { > + case XDP_PASS: > + ret = CPSW_XDP_PASS; > + break; > + case XDP_TX: > + xdpf = convert_to_xdp_frame(xdp); > + if (unlikely(!xdpf)) > + goto drop; > + > + cpsw_xdp_tx_frame(priv, xdpf, page); > + break; > + case XDP_REDIRECT: > + if (xdp_do_redirect(ndev, xdp, prog)) > + goto drop; > + > + /* as flush requires rx_dev to be per NAPI handle and there > + * is can be two devices putting packets on bulk queue, > + * do flush here avoid this just for sure. > + */ > + xdp_do_flush_map(); > + break; > + default: > + bpf_warn_invalid_xdp_action(act); > + /* fall through */ > + case XDP_ABORTED: > + trace_xdp_exception(ndev, prog, act); > + /* fall through -- handle aborts by dropping packet */ > + case XDP_DROP: > + goto drop; > + } > +out: > + rcu_read_unlock(); > + return ret; > +drop: > + rcu_read_unlock(); > + page_pool_recycle_direct(cpsw->page_pool[ch], page); > + return ret; > +} -- Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer