netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: sameehj@amazon.com
Cc: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	netdev@vger.kernel.org, bpf@vger.kernel.org, zorik@amazon.com,
	akiyano@amazon.com, gtzalik@amazon.com,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Daniel Borkmann" <borkmann@iogearbox.net>,
	"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Alexander Duyck" <alexander.duyck@gmail.com>,
	"Jeff Kirsher" <jeffrey.t.kirsher@intel.com>,
	"David Ahern" <dsahern@gmail.com>,
	"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Saeed Mahameed" <saeedm@mellanox.com>,
	steffen.klassert@secunet.com
Subject: [PATCH net-next v2 05/33] net: netsec: Add support for XDP frame size
Date: Thu, 30 Apr 2020 13:20:46 +0200	[thread overview]
Message-ID: <158824564680.2172139.16626813600636822835.stgit@firesoul> (raw)
In-Reply-To: <158824557985.2172139.4173570969543904434.stgit@firesoul>

From: Ilias Apalodimas <ilias.apalodimas@linaro.org>

This driver takes advantage of page_pool PP_FLAG_DMA_SYNC_DEV that
can help reduce the number of cache-lines that need to be flushed
when doing DMA sync for_device. Due to xdp_adjust_tail can grow the
area accessible to the by the CPU (can possibly write into), then max
sync length *after* bpf_prog_run_xdp() needs to be taken into account.

For XDP_TX action the driver is smart and does DMA-sync. When growing
tail this is still safe, because page_pool have DMA-mapped the entire
page size.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/socionext/netsec.c |   30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c
index a5a0fb60193a..e1f4be4b3d69 100644
--- a/drivers/net/ethernet/socionext/netsec.c
+++ b/drivers/net/ethernet/socionext/netsec.c
@@ -884,23 +884,28 @@ static u32 netsec_run_xdp(struct netsec_priv *priv, struct bpf_prog *prog,
 			  struct xdp_buff *xdp)
 {
 	struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_RX];
-	unsigned int len = xdp->data_end - xdp->data;
+	unsigned int sync, len = xdp->data_end - xdp->data;
 	u32 ret = NETSEC_XDP_PASS;
+	struct page *page;
 	int err;
 	u32 act;
 
 	act = bpf_prog_run_xdp(prog, xdp);
 
+	/* Due xdp_adjust_tail: DMA sync for_device cover max len CPU touch */
+	sync = xdp->data_end - xdp->data_hard_start - NETSEC_RXBUF_HEADROOM;
+	sync = max(sync, len);
+
 	switch (act) {
 	case XDP_PASS:
 		ret = NETSEC_XDP_PASS;
 		break;
 	case XDP_TX:
 		ret = netsec_xdp_xmit_back(priv, xdp);
-		if (ret != NETSEC_XDP_TX)
-			page_pool_put_page(dring->page_pool,
-					   virt_to_head_page(xdp->data), len,
-					   true);
+		if (ret != NETSEC_XDP_TX) {
+			page = virt_to_head_page(xdp->data);
+			page_pool_put_page(dring->page_pool, page, sync, true);
+		}
 		break;
 	case XDP_REDIRECT:
 		err = xdp_do_redirect(priv->ndev, xdp, prog);
@@ -908,9 +913,8 @@ static u32 netsec_run_xdp(struct netsec_priv *priv, struct bpf_prog *prog,
 			ret = NETSEC_XDP_REDIR;
 		} else {
 			ret = NETSEC_XDP_CONSUMED;
-			page_pool_put_page(dring->page_pool,
-					   virt_to_head_page(xdp->data), len,
-					   true);
+			page = virt_to_head_page(xdp->data);
+			page_pool_put_page(dring->page_pool, page, sync, true);
 		}
 		break;
 	default:
@@ -921,8 +925,8 @@ static u32 netsec_run_xdp(struct netsec_priv *priv, struct bpf_prog *prog,
 		/* fall through -- handle aborts by dropping packet */
 	case XDP_DROP:
 		ret = NETSEC_XDP_CONSUMED;
-		page_pool_put_page(dring->page_pool,
-				   virt_to_head_page(xdp->data), len, true);
+		page = virt_to_head_page(xdp->data);
+		page_pool_put_page(dring->page_pool, page, sync, true);
 		break;
 	}
 
@@ -936,10 +940,14 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
 	struct netsec_rx_pkt_info rx_info;
 	enum dma_data_direction dma_dir;
 	struct bpf_prog *xdp_prog;
+	struct xdp_buff xdp;
 	u16 xdp_xmit = 0;
 	u32 xdp_act = 0;
 	int done = 0;
 
+	xdp.rxq = &dring->xdp_rxq;
+	xdp.frame_sz = PAGE_SIZE;
+
 	rcu_read_lock();
 	xdp_prog = READ_ONCE(priv->xdp_prog);
 	dma_dir = page_pool_get_dma_dir(dring->page_pool);
@@ -953,7 +961,6 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
 		struct sk_buff *skb = NULL;
 		u16 pkt_len, desc_len;
 		dma_addr_t dma_handle;
-		struct xdp_buff xdp;
 		void *buf_addr;
 
 		if (de->attr & (1U << NETSEC_RX_PKT_OWN_FIELD)) {
@@ -1002,7 +1009,6 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget)
 		xdp.data = desc->addr + NETSEC_RXBUF_HEADROOM;
 		xdp_set_data_meta_invalid(&xdp);
 		xdp.data_end = xdp.data + pkt_len;
-		xdp.rxq = &dring->xdp_rxq;
 
 		if (xdp_prog) {
 			xdp_result = netsec_run_xdp(priv, xdp_prog, &xdp);



  parent reply	other threads:[~2020-04-30 11:21 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <158824557985.2172139.4173570969543904434.stgit@firesoul>
2020-04-30 11:20 ` [PATCH net-next v2 01/33] xdp: add frame size to xdp_buff Jesper Dangaard Brouer
2020-04-30 11:20 ` [PATCH net-next v2 02/33] bnxt: add XDP frame size to driver Jesper Dangaard Brouer
2020-04-30 11:20 ` [PATCH net-next v2 03/33] sfc: add XDP frame size Jesper Dangaard Brouer
2020-04-30 11:20 ` [PATCH net-next v2 04/33] mvneta: add XDP frame size to driver Jesper Dangaard Brouer
2020-04-30 11:20 ` Jesper Dangaard Brouer [this message]
2020-04-30 11:20 ` [PATCH net-next v2 06/33] net: XDP-generic determining XDP frame size Jesper Dangaard Brouer
2020-04-30 11:20 ` [PATCH net-next v2 07/33] xdp: xdp_frame add member frame_sz and handle in convert_to_xdp_frame Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 08/33] xdp: cpumap redirect use frame_sz and increase skb_tailroom Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 09/33] veth: adjust hard_start offset on redirect XDP frames Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 10/33] veth: xdp using frame_sz in veth driver Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 11/33] dpaa2-eth: add XDP frame size Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 12/33] hv_netvsc: add XDP frame size to driver Jesper Dangaard Brouer
2020-04-30 14:20   ` Haiyang Zhang
2020-05-01 14:47     ` Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 13/33] qlogic/qede: " Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 14/33] net: ethernet: ti: add XDP frame size to driver cpsw Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 15/33] ena: add XDP frame size to amazon NIC driver Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 16/33] mlx4: add XDP frame size and adjust max XDP MTU Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 17/33] net: thunderx: add XDP frame size Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 18/33] nfp: add XDP frame size to netronome driver Jesper Dangaard Brouer
2020-04-30 11:21 ` [PATCH net-next v2 19/33] tun: add XDP frame size Jesper Dangaard Brouer
2020-05-06 20:32   ` Michael S. Tsirkin
2020-04-30 11:22 ` [PATCH net-next v2 20/33] vhost_net: also populate " Jesper Dangaard Brouer
2020-05-06  6:41   ` Jason Wang
2020-05-06  6:49     ` Jason Wang
2020-05-06 20:33   ` Michael S. Tsirkin
2020-04-30 11:22 ` [PATCH net-next v2 21/33] virtio_net: add XDP frame size in two code paths Jesper Dangaard Brouer
2020-05-06 20:34   ` Michael S. Tsirkin
2020-05-08  2:05     ` Jason Wang
2020-05-08  7:21       ` Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 22/33] ixgbe: fix XDP redirect on archs with PAGE_SIZE above 4K Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 23/33] ixgbe: add XDP frame size to driver Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 24/33] ixgbevf: add XDP frame size to VF driver Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 25/33] i40e: add XDP frame size to driver Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 26/33] ice: " Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 27/33] xdp: for Intel AF_XDP drivers add XDP frame_sz Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 28/33] mlx5: rx queue setup time determine frame_sz for XDP Jesper Dangaard Brouer
2020-04-30 17:07   ` Tariq Toukan
2020-04-30 17:12     ` Tariq Toukan
2020-05-01 12:32       ` Jesper Dangaard Brouer
2020-05-08 10:49         ` Jesper Dangaard Brouer
2020-05-01 13:01     ` Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 29/33] xdp: allow bpf_xdp_adjust_tail() to grow packet size Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 30/33] xdp: clear grow memory in bpf_xdp_adjust_tail() Jesper Dangaard Brouer
2020-04-30 11:22 ` [PATCH net-next v2 31/33] bpf: add xdp.frame_sz in bpf_prog_test_run_xdp() Jesper Dangaard Brouer
2020-04-30 11:23 ` [PATCH net-next v2 32/33] selftests/bpf: adjust BPF selftest for xdp_adjust_tail Jesper Dangaard Brouer
2020-04-30 11:23 ` [PATCH net-next v2 33/33] selftests/bpf: xdp_adjust_tail add grow tail tests Jesper Dangaard Brouer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=158824564680.2172139.16626813600636822835.stgit@firesoul \
    --to=brouer@redhat.com \
    --cc=akiyano@amazon.com \
    --cc=alexander.duyck@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=borkmann@iogearbox.net \
    --cc=bpf@vger.kernel.org \
    --cc=dsahern@gmail.com \
    --cc=gtzalik@amazon.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=sameehj@amazon.com \
    --cc=steffen.klassert@secunet.com \
    --cc=toke@redhat.com \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=zorik@amazon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).