diff mbox series

[net,2/4] bnxt_en: Flush XDP for bnxt_poll_nitroa0()'s NAPI

Message ID 20230908135748.794163-3-bigeasy@linutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Add missing xdp_do_flush() invocations. | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1340 this patch: 1340
netdev/cc_maintainers fail 1 blamed authors not CCed: gospo@broadcom.com; 1 maintainers not CCed: gospo@broadcom.com
netdev/build_clang success Errors and warnings before: 1363 this patch: 1363
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1365 this patch: 1365
netdev/checkpatch warning WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: f18c2b77b2e4 ("bnxt_en: optimized XDP_REDIRECT support")'
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sebastian Andrzej Siewior Sept. 8, 2023, 1:57 p.m. UTC
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")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Pavan Chebbi Sept. 8, 2023, 4:30 p.m. UTC | #1
On Fri, Sep 8, 2023 at 7:29 PM 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")
> 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;

Michael can confirm but I don't think we need this additional variable.
Since the event is always ORed, we could directly check if (event &
BNXT_REDIRECT_EVENT) just like is done in __bnxt_poll_work().

>         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
>
>
Michael Chan Sept. 8, 2023, 5:57 p.m. UTC | #2
On Fri, Sep 8, 2023 at 9:30 AM Pavan Chebbi <pavan.chebbi@broadcom.com> wrote:
>
> On Fri, Sep 8, 2023 at 7:29 PM 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")
> > 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;
>
> Michael can confirm but I don't think we need this additional variable.
> Since the event is always ORed, we could directly check if (event &
> BNXT_REDIRECT_EVENT) just like is done in __bnxt_poll_work().

If we have a mix of XDP_TX and XDP_REDIRECT during NAPI, event can be
cleared by XDP_TX.  So this patch looks correct to me because of that.
Or we can make it consistent with __bnxt_poll_work() and assume that
XDP_TX won't mix with XDP_REDIRECT.

Handling a mix of XDP actions needs to be looked at separately.  The
driver currently won't work well when that happens.  I am working on
an internal patch to address that and will post it when it's ready.
Thanks.

>
> >         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
> >
> >
Andy Gospodarek Sept. 8, 2023, 6:18 p.m. UTC | #3
On Fri, Sep 08, 2023 at 10:57:13AM -0700, Michael Chan wrote:
> On Fri, Sep 8, 2023 at 9:30 AM Pavan Chebbi <pavan.chebbi@broadcom.com> wrote:
> >
> > On Fri, Sep 8, 2023 at 7:29 PM 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")
> > > 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;
> >
> > Michael can confirm but I don't think we need this additional variable.
> > Since the event is always ORed, we could directly check if (event &
> > BNXT_REDIRECT_EVENT) just like is done in __bnxt_poll_work().
> 
> If we have a mix of XDP_TX and XDP_REDIRECT during NAPI, event can be
> cleared by XDP_TX.  So this patch looks correct to me because of that.

Agreed

> Or we can make it consistent with __bnxt_poll_work() and assume that
> XDP_TX won't mix with XDP_REDIRECT.

Unfortunately we probably cannot guarantee that or maybe more to point
we do not want to guarantee that.

Thanks for this patch.

Reviewed-by: Andy Gospodarek <gospo@broadcom.com>


> Handling a mix of XDP actions needs to be looked at separately.  The
> driver currently won't work well when that happens.  I am working on
> an internal patch to address that and will post it when it's ready.
> Thanks.
> 
> >
> > >         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
> > >
> > >
diff mbox series

Patch

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);