All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v2 0/3] Add missing xdp_do_flush() invocations.
@ 2023-09-18 15:36 Sebastian Andrzej Siewior
  2023-09-18 15:36 ` [PATCH net v2 1/3] net: ena: Flush XDP packets on error Sebastian Andrzej Siewior
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-09-18 15:36 UTC (permalink / raw)
  To: netdev, bpf
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Eric Dumazet, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, Paolo Abeni, Thomas Gleixner

Hi,

I've been looking at the drivers/ XDP users and noticed that some
XDP_REDIRECT user don't invoke xdp_do_flush() at the end.

v1…v2: https://lore.kernel.org/all/20230908135748.794163-1-bigeasy@linutronix.de
  - Collected tags.
  - Dropped the #4 patch which was touching cpu_map_bpf_prog_run()
    because it is not needed.

Sebastian



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net v2 1/3] net: ena: Flush XDP packets on error.
  2023-09-18 15:36 [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Sebastian Andrzej Siewior
@ 2023-09-18 15:36 ` Sebastian Andrzej Siewior
  2023-09-18 15:36 ` [PATCH net v2 2/3] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI Sebastian Andrzej Siewior
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-09-18 15:36 UTC (permalink / raw)
  To: netdev, bpf
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Eric Dumazet, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, Paolo Abeni, Thomas Gleixner,
	Sebastian Andrzej Siewior, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Shay Agroskin

xdp_do_flush() should be invoked before leaving the NAPI poll function
after a XDP-redirect. This is not the case if the driver leaves via
the error path (after having a redirect in one of its previous
iterations).

Invoke xdp_do_flush() also in the error path.

Cc: Arthur Kiyanovski <akiyano@amazon.com>
Cc: David Arinzon <darinzon@amazon.com>
Cc: Noam Dagan <ndagan@amazon.com>
Cc: Saeed Bishara <saeedb@amazon.com>
Cc: Shay Agroskin <shayagr@amazon.com>
Fixes: a318c70ad152b ("net: ena: introduce XDP redirect implementation")
Acked-by: Arthur Kiyanovski <akiyano@amazon.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index ad32ca81f7ef4..f955bde10cf90 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1833,6 +1833,9 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
 	return work_done;
 
 error:
+	if (xdp_flags & ENA_XDP_REDIRECT)
+		xdp_do_flush();
+
 	adapter = netdev_priv(rx_ring->netdev);
 
 	if (rc == -ENOSPC) {
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net v2 2/3] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI
  2023-09-18 15:36 [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Sebastian Andrzej Siewior
  2023-09-18 15:36 ` [PATCH net v2 1/3] net: ena: Flush XDP packets on error Sebastian Andrzej Siewior
@ 2023-09-18 15:36 ` Sebastian Andrzej Siewior
  2023-09-18 17:11   ` Michael Chan
  2023-09-18 15:36 ` [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects Sebastian Andrzej Siewior
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-09-18 15:36 UTC (permalink / raw)
  To: netdev, bpf
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Eric Dumazet, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, Paolo Abeni, Thomas Gleixner,
	Sebastian Andrzej Siewior, Michael Chan, Andy Gospodarek

bnxt_poll_nitroa0() invokes bnxt_rx_pkt() which can run a XDP program
which in turn can return XDP_REDIRECT. bnxt_rx_pkt() is also used by
__bnxt_poll_work() which flushes (xdp_do_flush()) the packets after each
round. bnxt_poll_nitroa0() lacks this feature.
xdp_do_flush() should be invoked before leaving the NAPI callback.

Invoke xdp_do_flush() after a redirect in bnxt_poll_nitroa0() NAPI.

Cc: Michael Chan <michael.chan@broadcom.com>
Fixes: f18c2b77b2e4e ("bnxt_en: optimized XDP_REDIRECT support")
Reviewed-by: Andy Gospodarek <gospo@broadcom.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 5cc0dbe121327..7551aa8068f8f 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -2614,6 +2614,7 @@ static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
 	struct rx_cmp_ext *rxcmp1;
 	u32 cp_cons, tmp_raw_cons;
 	u32 raw_cons = cpr->cp_raw_cons;
+	bool flush_xdp = false;
 	u32 rx_pkts = 0;
 	u8 event = 0;
 
@@ -2648,6 +2649,8 @@ static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
 				rx_pkts++;
 			else if (rc == -EBUSY)	/* partial completion */
 				break;
+			if (event & BNXT_REDIRECT_EVENT)
+				flush_xdp = true;
 		} else if (unlikely(TX_CMP_TYPE(txcmp) ==
 				    CMPL_BASE_TYPE_HWRM_DONE)) {
 			bnxt_hwrm_handler(bp, txcmp);
@@ -2667,6 +2670,8 @@ static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
 
 	if (event & BNXT_AGG_EVENT)
 		bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
+	if (flush_xdp)
+		xdp_do_flush();
 
 	if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
 		napi_complete_done(napi, rx_pkts);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects.
  2023-09-18 15:36 [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Sebastian Andrzej Siewior
  2023-09-18 15:36 ` [PATCH net v2 1/3] net: ena: Flush XDP packets on error Sebastian Andrzej Siewior
  2023-09-18 15:36 ` [PATCH net v2 2/3] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI Sebastian Andrzej Siewior
@ 2023-09-18 15:36 ` Sebastian Andrzej Siewior
  2023-09-18 17:58   ` Kui-Feng Lee
  2023-09-20  7:04 ` [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Jesper Dangaard Brouer
  2023-09-21  7:40 ` patchwork-bot+netdevbpf
  4 siblings, 1 reply; 11+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-09-18 15:36 UTC (permalink / raw)
  To: netdev, bpf
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Eric Dumazet, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, Paolo Abeni, Thomas Gleixner,
	Sebastian Andrzej Siewior, Geetha sowjanya, Subbaraya Sundeep,
	Sunil Goutham, hariprasad

xdp_do_flush() should be invoked before leaving the NAPI poll function
if XDP-redirect has been performed.

Invoke xdp_do_flush() before leaving NAPI.

Cc: Geetha sowjanya <gakula@marvell.com>
Cc: Subbaraya Sundeep <sbhatta@marvell.com>
Cc: Sunil Goutham <sgoutham@marvell.com>
Cc: hariprasad <hkelam@marvell.com>
Fixes: 06059a1a9a4a5 ("octeontx2-pf: Add XDP support to netdev PF")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Geethasowjanya Akula <gakula@marvell.com>
---
 .../marvell/octeontx2/nic/otx2_txrx.c         | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
index e77d438489557..53b2a4ef52985 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
@@ -29,7 +29,8 @@
 static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 				     struct bpf_prog *prog,
 				     struct nix_cqe_rx_s *cqe,
-				     struct otx2_cq_queue *cq);
+				     struct otx2_cq_queue *cq,
+				     bool *need_xdp_flush);
 
 static int otx2_nix_cq_op_status(struct otx2_nic *pfvf,
 				 struct otx2_cq_queue *cq)
@@ -337,7 +338,7 @@ static bool otx2_check_rcv_errors(struct otx2_nic *pfvf,
 static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
 				 struct napi_struct *napi,
 				 struct otx2_cq_queue *cq,
-				 struct nix_cqe_rx_s *cqe)
+				 struct nix_cqe_rx_s *cqe, bool *need_xdp_flush)
 {
 	struct nix_rx_parse_s *parse = &cqe->parse;
 	struct nix_rx_sg_s *sg = &cqe->sg;
@@ -353,7 +354,7 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
 	}
 
 	if (pfvf->xdp_prog)
-		if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq))
+		if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq, need_xdp_flush))
 			return;
 
 	skb = napi_get_frags(napi);
@@ -388,6 +389,7 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
 				struct napi_struct *napi,
 				struct otx2_cq_queue *cq, int budget)
 {
+	bool need_xdp_flush = false;
 	struct nix_cqe_rx_s *cqe;
 	int processed_cqe = 0;
 
@@ -409,13 +411,15 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
 		cq->cq_head++;
 		cq->cq_head &= (cq->cqe_cnt - 1);
 
-		otx2_rcv_pkt_handler(pfvf, napi, cq, cqe);
+		otx2_rcv_pkt_handler(pfvf, napi, cq, cqe, &need_xdp_flush);
 
 		cqe->hdr.cqe_type = NIX_XQE_TYPE_INVALID;
 		cqe->sg.seg_addr = 0x00;
 		processed_cqe++;
 		cq->pend_cqe--;
 	}
+	if (need_xdp_flush)
+		xdp_do_flush();
 
 	/* Free CQEs to HW */
 	otx2_write64(pfvf, NIX_LF_CQ_OP_DOOR,
@@ -1354,7 +1358,8 @@ bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len, u16 qidx)
 static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 				     struct bpf_prog *prog,
 				     struct nix_cqe_rx_s *cqe,
-				     struct otx2_cq_queue *cq)
+				     struct otx2_cq_queue *cq,
+				     bool *need_xdp_flush)
 {
 	unsigned char *hard_start, *data;
 	int qidx = cq->cq_idx;
@@ -1391,8 +1396,10 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
 
 		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize,
 				    DMA_FROM_DEVICE);
-		if (!err)
+		if (!err) {
+			*need_xdp_flush = true;
 			return true;
+		}
 		put_page(page);
 		break;
 	default:
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net v2 2/3] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI
  2023-09-18 15:36 ` [PATCH net v2 2/3] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI Sebastian Andrzej Siewior
@ 2023-09-18 17:11   ` Michael Chan
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Chan @ 2023-09-18 17:11 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: netdev, bpf, David S. Miller, Alexei Starovoitov,
	Daniel Borkmann, Eric Dumazet, Jakub Kicinski,
	Jesper Dangaard Brouer, John Fastabend, Paolo Abeni,
	Thomas Gleixner, Andy Gospodarek

On Mon, Sep 18, 2023 at 8:36 AM Sebastian Andrzej Siewior
<bigeasy@linutronix.de> wrote:
>
> bnxt_poll_nitroa0() invokes bnxt_rx_pkt() which can run a XDP program
> which in turn can return XDP_REDIRECT. bnxt_rx_pkt() is also used by
> __bnxt_poll_work() which flushes (xdp_do_flush()) the packets after each
> round. bnxt_poll_nitroa0() lacks this feature.
> xdp_do_flush() should be invoked before leaving the NAPI callback.
>
> Invoke xdp_do_flush() after a redirect in bnxt_poll_nitroa0() NAPI.
>
> Cc: Michael Chan <michael.chan@broadcom.com>
> Fixes: f18c2b77b2e4e ("bnxt_en: optimized XDP_REDIRECT support")
> Reviewed-by: Andy Gospodarek <gospo@broadcom.com>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Reviewed-by: Michael Chan <michael.chan@broadcom.com>

Thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects.
  2023-09-18 15:36 ` [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects Sebastian Andrzej Siewior
@ 2023-09-18 17:58   ` Kui-Feng Lee
  2023-09-19  6:36     ` Sebastian Andrzej Siewior
  2023-09-21  7:01     ` Paolo Abeni
  0 siblings, 2 replies; 11+ messages in thread
From: Kui-Feng Lee @ 2023-09-18 17:58 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, netdev, bpf
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Eric Dumazet, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, Paolo Abeni, Thomas Gleixner, Geetha sowjanya,
	Subbaraya Sundeep, Sunil Goutham, hariprasad



On 9/18/23 08:36, Sebastian Andrzej Siewior wrote:
> xdp_do_flush() should be invoked before leaving the NAPI poll function
> if XDP-redirect has been performed.
> 
> Invoke xdp_do_flush() before leaving NAPI.
> 
> Cc: Geetha sowjanya <gakula@marvell.com>
> Cc: Subbaraya Sundeep <sbhatta@marvell.com>
> Cc: Sunil Goutham <sgoutham@marvell.com>
> Cc: hariprasad <hkelam@marvell.com>
> Fixes: 06059a1a9a4a5 ("octeontx2-pf: Add XDP support to netdev PF")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Acked-by: Geethasowjanya Akula <gakula@marvell.com>
> ---
>   .../marvell/octeontx2/nic/otx2_txrx.c         | 19 +++++++++++++------
>   1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> index e77d438489557..53b2a4ef52985 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> @@ -29,7 +29,8 @@
>   static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
>   				     struct bpf_prog *prog,
>   				     struct nix_cqe_rx_s *cqe,
> -				     struct otx2_cq_queue *cq);
> +				     struct otx2_cq_queue *cq,
> +				     bool *need_xdp_flush);
>   
>   static int otx2_nix_cq_op_status(struct otx2_nic *pfvf,
>   				 struct otx2_cq_queue *cq)
> @@ -337,7 +338,7 @@ static bool otx2_check_rcv_errors(struct otx2_nic *pfvf,
>   static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
>   				 struct napi_struct *napi,
>   				 struct otx2_cq_queue *cq,
> -				 struct nix_cqe_rx_s *cqe)
> +				 struct nix_cqe_rx_s *cqe, bool *need_xdp_flush)
>   {
>   	struct nix_rx_parse_s *parse = &cqe->parse;
>   	struct nix_rx_sg_s *sg = &cqe->sg;
> @@ -353,7 +354,7 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
>   	}
>   
>   	if (pfvf->xdp_prog)
> -		if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq))
> +		if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq, need_xdp_flush))
>   			return;
>   
>   	skb = napi_get_frags(napi);
> @@ -388,6 +389,7 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
>   				struct napi_struct *napi,
>   				struct otx2_cq_queue *cq, int budget)
>   {
> +	bool need_xdp_flush = false;
>   	struct nix_cqe_rx_s *cqe;
>   	int processed_cqe = 0;
>   
> @@ -409,13 +411,15 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
>   		cq->cq_head++;
>   		cq->cq_head &= (cq->cqe_cnt - 1);
>   
> -		otx2_rcv_pkt_handler(pfvf, napi, cq, cqe);
> +		otx2_rcv_pkt_handler(pfvf, napi, cq, cqe, &need_xdp_flush);
>   
>   		cqe->hdr.cqe_type = NIX_XQE_TYPE_INVALID;
>   		cqe->sg.seg_addr = 0x00;
>   		processed_cqe++;
>   		cq->pend_cqe--;
>   	}
> +	if (need_xdp_flush)
> +		xdp_do_flush();
>   
>   	/* Free CQEs to HW */
>   	otx2_write64(pfvf, NIX_LF_CQ_OP_DOOR,
> @@ -1354,7 +1358,8 @@ bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len, u16 qidx)
>   static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
>   				     struct bpf_prog *prog,
>   				     struct nix_cqe_rx_s *cqe,
> -				     struct otx2_cq_queue *cq)
> +				     struct otx2_cq_queue *cq,
> +				     bool *need_xdp_flush)
>   {
>   	unsigned char *hard_start, *data;
>   	int qidx = cq->cq_idx;
> @@ -1391,8 +1396,10 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
>   
>   		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize,
>   				    DMA_FROM_DEVICE);
> -		if (!err)
> +		if (!err) {
> +			*need_xdp_flush = true;

Is it possible to call xdp_do_flush() at the first place (here)?

>   			return true;
> +		}
>   		put_page(page);
>   		break;
>   	default:

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects.
  2023-09-18 17:58   ` Kui-Feng Lee
@ 2023-09-19  6:36     ` Sebastian Andrzej Siewior
  2023-09-21  7:01     ` Paolo Abeni
  1 sibling, 0 replies; 11+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-09-19  6:36 UTC (permalink / raw)
  To: Kui-Feng Lee
  Cc: netdev, bpf, David S. Miller, Alexei Starovoitov,
	Daniel Borkmann, Eric Dumazet, Jakub Kicinski,
	Jesper Dangaard Brouer, John Fastabend, Paolo Abeni,
	Thomas Gleixner, Geetha sowjanya, Subbaraya Sundeep,
	Sunil Goutham, hariprasad

On 2023-09-18 10:58:39 [-0700], Kui-Feng Lee wrote:
> > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> > index e77d438489557..53b2a4ef52985 100644
> > --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> > @@ -1391,8 +1396,10 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
> >   		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize,
> >   				    DMA_FROM_DEVICE);
> > -		if (!err)
> > +		if (!err) {
> > +			*need_xdp_flush = true;
> 
> Is it possible to call xdp_do_flush() at the first place (here)?

It shouldn't be wrong. All drivers, except for cpsw, invoke
xdp_do_flush() after completing their NAPI loop and then flushing all
possible packets at once.

> >   			return true;
> > +		}
> >   		put_page(page);
> >   		break;
> >   	default:

Sebastian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net v2 0/3] Add missing xdp_do_flush() invocations.
  2023-09-18 15:36 [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Sebastian Andrzej Siewior
                   ` (2 preceding siblings ...)
  2023-09-18 15:36 ` [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects Sebastian Andrzej Siewior
@ 2023-09-20  7:04 ` Jesper Dangaard Brouer
  2023-09-20  7:54   ` Sebastian Andrzej Siewior
  2023-09-21  7:40 ` patchwork-bot+netdevbpf
  4 siblings, 1 reply; 11+ messages in thread
From: Jesper Dangaard Brouer @ 2023-09-20  7:04 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, netdev, bpf
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Eric Dumazet, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, Paolo Abeni, Thomas Gleixner

Hi Sebastian,


On 18/09/2023 17.36, Sebastian Andrzej Siewior wrote:
> Hi,
> 
> I've been looking at the drivers/ XDP users and noticed that some
> XDP_REDIRECT user don't invoke xdp_do_flush() at the end.

I'm wondering if we could detect (and WARN) in the net core e.g.
net_rx_action() that a driver is missing a flush?

The idea could be to check the per CPU (struct) bpf_redirect_info.
Or check (per CPU) dev_flush_list.

If some is worried about performance implications, then we can hide this
under CONFIG_DEBUG_NET.

> v1…v2: https://lore.kernel.org/all/20230908135748.794163-1-bigeasy@linutronix.de
>    - Collected tags.
>    - Dropped the #4 patch which was touching cpu_map_bpf_prog_run()
>      because it is not needed.
> 

For the fixes in this set:

Acked-by: Jesper Dangaard Brouer <hawk@kernel.org>

Thanks for fixing these! - at it can lead to strange to debug cases.
--Jesper

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net v2 0/3] Add missing xdp_do_flush() invocations.
  2023-09-20  7:04 ` [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Jesper Dangaard Brouer
@ 2023-09-20  7:54   ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 11+ messages in thread
From: Sebastian Andrzej Siewior @ 2023-09-20  7:54 UTC (permalink / raw)
  To: Jesper Dangaard Brouer
  Cc: netdev, bpf, David S. Miller, Alexei Starovoitov,
	Daniel Borkmann, Eric Dumazet, Jakub Kicinski, John Fastabend,
	Paolo Abeni, Thomas Gleixner

On 2023-09-20 09:04:27 [+0200], Jesper Dangaard Brouer wrote:
> Hi Sebastian,

Hi Jesper,

> On 18/09/2023 17.36, Sebastian Andrzej Siewior wrote:
> > Hi,
> > 
> > I've been looking at the drivers/ XDP users and noticed that some
> > XDP_REDIRECT user don't invoke xdp_do_flush() at the end.
> 
> I'm wondering if we could detect (and WARN) in the net core e.g.
> net_rx_action() that a driver is missing a flush?
> 
> The idea could be to check the per CPU (struct) bpf_redirect_info.
> Or check (per CPU) dev_flush_list.
> 
> If some is worried about performance implications, then we can hide this
> under CONFIG_DEBUG_NET.

I had a WARN_ON in mind since the list has to be empty after the
completion of a NAPI callback. Now that you are bringing it up let me
actually do something…

> --Jesper

Sebastian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects.
  2023-09-18 17:58   ` Kui-Feng Lee
  2023-09-19  6:36     ` Sebastian Andrzej Siewior
@ 2023-09-21  7:01     ` Paolo Abeni
  1 sibling, 0 replies; 11+ messages in thread
From: Paolo Abeni @ 2023-09-21  7:01 UTC (permalink / raw)
  To: Kui-Feng Lee, Sebastian Andrzej Siewior, netdev, bpf
  Cc: David S. Miller, Alexei Starovoitov, Daniel Borkmann,
	Eric Dumazet, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, Thomas Gleixner, Geetha sowjanya,
	Subbaraya Sundeep, Sunil Goutham, hariprasad

On Mon, 2023-09-18 at 10:58 -0700, Kui-Feng Lee wrote:
> 
> On 9/18/23 08:36, Sebastian Andrzej Siewior wrote:
> > xdp_do_flush() should be invoked before leaving the NAPI poll function
> > if XDP-redirect has been performed.
> > 
> > Invoke xdp_do_flush() before leaving NAPI.
> > 
> > Cc: Geetha sowjanya <gakula@marvell.com>
> > Cc: Subbaraya Sundeep <sbhatta@marvell.com>
> > Cc: Sunil Goutham <sgoutham@marvell.com>
> > Cc: hariprasad <hkelam@marvell.com>
> > Fixes: 06059a1a9a4a5 ("octeontx2-pf: Add XDP support to netdev PF")
> > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> > Acked-by: Geethasowjanya Akula <gakula@marvell.com>
> > ---
> >   .../marvell/octeontx2/nic/otx2_txrx.c         | 19 +++++++++++++------
> >   1 file changed, 13 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> > index e77d438489557..53b2a4ef52985 100644
> > --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> > @@ -29,7 +29,8 @@
> >   static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
> >   				     struct bpf_prog *prog,
> >   				     struct nix_cqe_rx_s *cqe,
> > -				     struct otx2_cq_queue *cq);
> > +				     struct otx2_cq_queue *cq,
> > +				     bool *need_xdp_flush);
> >   
> >   static int otx2_nix_cq_op_status(struct otx2_nic *pfvf,
> >   				 struct otx2_cq_queue *cq)
> > @@ -337,7 +338,7 @@ static bool otx2_check_rcv_errors(struct otx2_nic *pfvf,
> >   static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
> >   				 struct napi_struct *napi,
> >   				 struct otx2_cq_queue *cq,
> > -				 struct nix_cqe_rx_s *cqe)
> > +				 struct nix_cqe_rx_s *cqe, bool *need_xdp_flush)
> >   {
> >   	struct nix_rx_parse_s *parse = &cqe->parse;
> >   	struct nix_rx_sg_s *sg = &cqe->sg;
> > @@ -353,7 +354,7 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
> >   	}
> >   
> >   	if (pfvf->xdp_prog)
> > -		if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq))
> > +		if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq, need_xdp_flush))
> >   			return;
> >   
> >   	skb = napi_get_frags(napi);
> > @@ -388,6 +389,7 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
> >   				struct napi_struct *napi,
> >   				struct otx2_cq_queue *cq, int budget)
> >   {
> > +	bool need_xdp_flush = false;
> >   	struct nix_cqe_rx_s *cqe;
> >   	int processed_cqe = 0;
> >   
> > @@ -409,13 +411,15 @@ static int otx2_rx_napi_handler(struct otx2_nic *pfvf,
> >   		cq->cq_head++;
> >   		cq->cq_head &= (cq->cqe_cnt - 1);
> >   
> > -		otx2_rcv_pkt_handler(pfvf, napi, cq, cqe);
> > +		otx2_rcv_pkt_handler(pfvf, napi, cq, cqe, &need_xdp_flush);
> >   
> >   		cqe->hdr.cqe_type = NIX_XQE_TYPE_INVALID;
> >   		cqe->sg.seg_addr = 0x00;
> >   		processed_cqe++;
> >   		cq->pend_cqe--;
> >   	}
> > +	if (need_xdp_flush)
> > +		xdp_do_flush();
> >   
> >   	/* Free CQEs to HW */
> >   	otx2_write64(pfvf, NIX_LF_CQ_OP_DOOR,
> > @@ -1354,7 +1358,8 @@ bool otx2_xdp_sq_append_pkt(struct otx2_nic *pfvf, u64 iova, int len, u16 qidx)
> >   static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
> >   				     struct bpf_prog *prog,
> >   				     struct nix_cqe_rx_s *cqe,
> > -				     struct otx2_cq_queue *cq)
> > +				     struct otx2_cq_queue *cq,
> > +				     bool *need_xdp_flush)
> >   {
> >   	unsigned char *hard_start, *data;
> >   	int qidx = cq->cq_idx;
> > @@ -1391,8 +1396,10 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
> >   
> >   		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize,
> >   				    DMA_FROM_DEVICE);
> > -		if (!err)
> > +		if (!err) {
> > +			*need_xdp_flush = true;
> 
> Is it possible to call xdp_do_flush() at the first place (here)?

AFAICT that would kill much/all of the performance benefits of bulk
redirect.

I think the proposed solution is a better one.

Cheers,

Paolo


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net v2 0/3] Add missing xdp_do_flush() invocations.
  2023-09-18 15:36 [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Sebastian Andrzej Siewior
                   ` (3 preceding siblings ...)
  2023-09-20  7:04 ` [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Jesper Dangaard Brouer
@ 2023-09-21  7:40 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-21  7:40 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: netdev, bpf, davem, ast, daniel, edumazet, kuba, hawk,
	john.fastabend, pabeni, tglx

Hello:

This series was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 18 Sep 2023 17:36:08 +0200 you wrote:
> Hi,
> 
> I've been looking at the drivers/ XDP users and noticed that some
> XDP_REDIRECT user don't invoke xdp_do_flush() at the end.
> 
> v1…v2: https://lore.kernel.org/all/20230908135748.794163-1-bigeasy@linutronix.de
>   - Collected tags.
>   - Dropped the #4 patch which was touching cpu_map_bpf_prog_run()
>     because it is not needed.
> 
> [...]

Here is the summary with links:
  - [net,v2,1/3] net: ena: Flush XDP packets on error.
    https://git.kernel.org/netdev/net/c/6f411fb5ca94
  - [net,v2,2/3] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI
    https://git.kernel.org/netdev/net/c/edc0140cc3b7
  - [net,v2,3/3] octeontx2-pf: Do xdp_do_flush() after redirects.
    https://git.kernel.org/netdev/net/c/70b2b6892645

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-09-21 17:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-18 15:36 [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Sebastian Andrzej Siewior
2023-09-18 15:36 ` [PATCH net v2 1/3] net: ena: Flush XDP packets on error Sebastian Andrzej Siewior
2023-09-18 15:36 ` [PATCH net v2 2/3] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI Sebastian Andrzej Siewior
2023-09-18 17:11   ` Michael Chan
2023-09-18 15:36 ` [PATCH net v2 3/3] octeontx2-pf: Do xdp_do_flush() after redirects Sebastian Andrzej Siewior
2023-09-18 17:58   ` Kui-Feng Lee
2023-09-19  6:36     ` Sebastian Andrzej Siewior
2023-09-21  7:01     ` Paolo Abeni
2023-09-20  7:04 ` [PATCH net v2 0/3] Add missing xdp_do_flush() invocations Jesper Dangaard Brouer
2023-09-20  7:54   ` Sebastian Andrzej Siewior
2023-09-21  7:40 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.