[net-next,v3,4/7] net: lan966x: Update rxq memory model

Message ID 20221121212850.3212649-5-horatiu.vultur@microchip.com
State New
Headers
Series net: lan966x: Extend xdp support |

Commit Message

Horatiu Vultur Nov. 21, 2022, 9:28 p.m. UTC
  By default the rxq memory model is MEM_TYPE_PAGE_SHARED but to be able
to reuse pages on the TX side, when the XDP action XDP_TX it is required
to update the memory model to PAGE_POOL.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 .../net/ethernet/microchip/lan966x/lan966x_fdma.c  | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

Alexander Lobakin Nov. 22, 2022, 11:38 a.m. UTC | #1
From: Horatiu Vultur <horatiu.vultur@microchip.com>
Date: Mon, 21 Nov 2022 22:28:47 +0100

> By default the rxq memory model is MEM_TYPE_PAGE_SHARED but to be able
> to reuse pages on the TX side, when the XDP action XDP_TX it is required
> to update the memory model to PAGE_POOL.
> 
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
>  .../net/ethernet/microchip/lan966x/lan966x_fdma.c  | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> index 384ed34197d58..483d1470c8362 100644
> --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> @@ -78,8 +78,22 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx)
>  		.max_len = rx->max_mtu -
>  			   SKB_DATA_ALIGN(sizeof(struct skb_shared_info)),
>  	};
> +	struct lan966x_port *port;
> +	int i;
>  
>  	rx->page_pool = page_pool_create(&pp_params);
> +
> +	for (i = 0; i < lan966x->num_phys_ports; ++i) {
> +		if (!lan966x->ports[i])
> +			continue;
> +
> +		port = lan966x->ports[i];
> +
> +		xdp_rxq_info_unreg_mem_model(&port->xdp_rxq);

xdp_rxq_info_unreg_mem_model() can emit a splat if currently the
corresponding xdp_rxq_info is not registered[0]. Can't we face it
here if called from lan966x_fdma_init()?

> +		xdp_rxq_info_reg_mem_model(&port->xdp_rxq, MEM_TYPE_PAGE_POOL,
> +					   rx->page_pool);
> +	}
> +
>  	return PTR_ERR_OR_ZERO(rx->page_pool);
>  }
>  
> -- 
> 2.38.0

Thanks,
Olek
  
Horatiu Vultur Nov. 22, 2022, 9:23 p.m. UTC | #2
The 11/22/2022 12:38, Alexander Lobakin wrote:
> 
> From: Horatiu Vultur <horatiu.vultur@microchip.com>
> Date: Mon, 21 Nov 2022 22:28:47 +0100
> 
> > By default the rxq memory model is MEM_TYPE_PAGE_SHARED but to be able
> > to reuse pages on the TX side, when the XDP action XDP_TX it is required
> > to update the memory model to PAGE_POOL.
> >
> > Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> > ---
> >  .../net/ethernet/microchip/lan966x/lan966x_fdma.c  | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> > index 384ed34197d58..483d1470c8362 100644
> > --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> > +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> > @@ -78,8 +78,22 @@ static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx)
> >               .max_len = rx->max_mtu -
> >                          SKB_DATA_ALIGN(sizeof(struct skb_shared_info)),
> >       };
> > +     struct lan966x_port *port;
> > +     int i;
> >
> >       rx->page_pool = page_pool_create(&pp_params);
> > +
> > +     for (i = 0; i < lan966x->num_phys_ports; ++i) {
> > +             if (!lan966x->ports[i])
> > +                     continue;
> > +
> > +             port = lan966x->ports[i];
> > +
> > +             xdp_rxq_info_unreg_mem_model(&port->xdp_rxq);
> 
> xdp_rxq_info_unreg_mem_model() can emit a splat if currently the
> corresponding xdp_rxq_info is not registered[0]. Can't we face it
> here if called from lan966x_fdma_init()?

We will not face that issue here because before lan966x_fdma_init is
called, we call lan966x_xdp_port_init which registers xdp_rxq_info.

> 
> > +             xdp_rxq_info_reg_mem_model(&port->xdp_rxq, MEM_TYPE_PAGE_POOL,
> > +                                        rx->page_pool);
> > +     }
> > +
> >       return PTR_ERR_OR_ZERO(rx->page_pool);
> >  }
> >
> > --
> > 2.38.0
> 
> Thanks,
> Olek
  

Patch

diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
index 384ed34197d58..483d1470c8362 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
@@ -78,8 +78,22 @@  static int lan966x_fdma_rx_alloc_page_pool(struct lan966x_rx *rx)
 		.max_len = rx->max_mtu -
 			   SKB_DATA_ALIGN(sizeof(struct skb_shared_info)),
 	};
+	struct lan966x_port *port;
+	int i;
 
 	rx->page_pool = page_pool_create(&pp_params);
+
+	for (i = 0; i < lan966x->num_phys_ports; ++i) {
+		if (!lan966x->ports[i])
+			continue;
+
+		port = lan966x->ports[i];
+
+		xdp_rxq_info_unreg_mem_model(&port->xdp_rxq);
+		xdp_rxq_info_reg_mem_model(&port->xdp_rxq, MEM_TYPE_PAGE_POOL,
+					   rx->page_pool);
+	}
+
 	return PTR_ERR_OR_ZERO(rx->page_pool);
 }