Message ID | 20241015125841.1075560-12-wei.fang@nxp.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | add basic support for i.MX95 NETC | expand |
> -----Original Message----- > From: Wei Fang <wei.fang@nxp.com> > Sent: Tuesday, October 15, 2024 3:59 PM [...] > Subject: [PATCH v2 net-next 11/13] net: enetc: optimize the allocation of > tx_bdr > > From: Clark Wang <xiaoning.wang@nxp.com> > > There is a situation where num_tx_rings cannot be divided by bdr_int_num. > For example, num_tx_rings is 8 and bdr_int_num is 3. According to the > previous logic, this results in two tx_bdr corresponding memories not > being allocated, so when sending packets to tx ring 6 or 7, wild pointers > will be accessed. Of course, this issue doesn't exist on LS1028A, because > its num_tx_rings is 8, and bdr_int_num is either 1 or 2. However, there > is a risk for the upcoming i.MX95. Therefore, it is necessary to ensure > that each tx_bdr can be allocated to the corresponding memory. > > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> > Signed-off-by: Wei Fang <wei.fang@nxp.com> > --- > v2 changes: > This patch is separated from v1 patch 9 ("net: enetc: optimize the > allocation of tx_bdr"). Only the optimized part is kept. > --- Reviewed-by: Claudiu Manoil <claudiu.manoil@nxp.com>
On Tue, Oct 15, 2024 at 08:58:39PM +0800, Wei Fang wrote: > From: Clark Wang <xiaoning.wang@nxp.com> > > There is a situation where num_tx_rings cannot be divided by bdr_int_num. > For example, num_tx_rings is 8 and bdr_int_num is 3. According to the > previous logic, this results in two tx_bdr corresponding memories not > being allocated, so when sending packets to tx ring 6 or 7, wild pointers > will be accessed. Of course, this issue doesn't exist on LS1028A, because > its num_tx_rings is 8, and bdr_int_num is either 1 or 2. However, there > is a risk for the upcoming i.MX95. Therefore, it is necessary to ensure > that each tx_bdr can be allocated to the corresponding memory. > > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> > Signed-off-by: Wei Fang <wei.fang@nxp.com> > --- > v2 changes: > This patch is separated from v1 patch 9 ("net: enetc: optimize the > allocation of tx_bdr"). Only the optimized part is kept. > --- > drivers/net/ethernet/freescale/enetc/enetc.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c > index d36af3f8ba31..72ddf8b16271 100644 > --- a/drivers/net/ethernet/freescale/enetc/enetc.c > +++ b/drivers/net/ethernet/freescale/enetc/enetc.c > @@ -3049,10 +3049,10 @@ static void enetc_int_vector_destroy(struct enetc_ndev_priv *priv, int i) > int enetc_alloc_msix(struct enetc_ndev_priv *priv) > { > struct pci_dev *pdev = priv->si->pdev; > + int v_tx_rings, v_remainder; > int num_stack_tx_queues; > int first_xdp_tx_ring; > int i, n, err, nvec; > - int v_tx_rings; Nit: Needn't move v_tx_rings. Reviewed-by: Frank Li <Frank.Li@nxp.com> > > nvec = ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num; > /* allocate MSIX for both messaging and Rx/Tx interrupts */ > @@ -3066,10 +3066,14 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv) > > /* # of tx rings per int vector */ > v_tx_rings = priv->num_tx_rings / priv->bdr_int_num; > + v_remainder = priv->num_tx_rings % priv->bdr_int_num; > > - for (i = 0; i < priv->bdr_int_num; i++) > - if (enetc_int_vector_init(priv, i, v_tx_rings)) > + for (i = 0; i < priv->bdr_int_num; i++) { > + int num_tx_rings = i < v_remainder ? v_tx_rings + 1 : v_tx_rings; > + > + if (enetc_int_vector_init(priv, i, num_tx_rings)) > goto fail; > + } > > num_stack_tx_queues = enetc_num_stack_tx_queues(priv); > > -- > 2.34.1 >
> -----Original Message----- > From: Frank Li <frank.li@nxp.com> > Sent: 2024年10月16日 0:58 > To: Wei Fang <wei.fang@nxp.com> > Cc: davem@davemloft.net; edumazet@google.com; kuba@kernel.org; > pabeni@redhat.com; robh@kernel.org; krzk+dt@kernel.org; > conor+dt@kernel.org; Vladimir Oltean <vladimir.oltean@nxp.com>; Claudiu > Manoil <claudiu.manoil@nxp.com>; Clark Wang <xiaoning.wang@nxp.com>; > christophe.leroy@csgroup.eu; linux@armlinux.org.uk; bhelgaas@google.com; > horms@kernel.org; imx@lists.linux.dev; netdev@vger.kernel.org; > devicetree@vger.kernel.org; linux-kernel@vger.kernel.org; > linux-pci@vger.kernel.org > Subject: Re: [PATCH v2 net-next 11/13] net: enetc: optimize the allocation of > tx_bdr > > On Tue, Oct 15, 2024 at 08:58:39PM +0800, Wei Fang wrote: > > From: Clark Wang <xiaoning.wang@nxp.com> > > > > There is a situation where num_tx_rings cannot be divided by bdr_int_num. > > For example, num_tx_rings is 8 and bdr_int_num is 3. According to the > > previous logic, this results in two tx_bdr corresponding memories not > > being allocated, so when sending packets to tx ring 6 or 7, wild > > pointers will be accessed. Of course, this issue doesn't exist on > > LS1028A, because its num_tx_rings is 8, and bdr_int_num is either 1 or > > 2. However, there is a risk for the upcoming i.MX95. Therefore, it is > > necessary to ensure that each tx_bdr can be allocated to the corresponding > memory. > > > > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> > > Signed-off-by: Wei Fang <wei.fang@nxp.com> > > --- > > v2 changes: > > This patch is separated from v1 patch 9 ("net: enetc: optimize the > > allocation of tx_bdr"). Only the optimized part is kept. > > --- > > drivers/net/ethernet/freescale/enetc/enetc.c | 10 +++++++--- > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c > > b/drivers/net/ethernet/freescale/enetc/enetc.c > > index d36af3f8ba31..72ddf8b16271 100644 > > --- a/drivers/net/ethernet/freescale/enetc/enetc.c > > +++ b/drivers/net/ethernet/freescale/enetc/enetc.c > > @@ -3049,10 +3049,10 @@ static void enetc_int_vector_destroy(struct > > enetc_ndev_priv *priv, int i) int enetc_alloc_msix(struct > > enetc_ndev_priv *priv) { > > struct pci_dev *pdev = priv->si->pdev; > > + int v_tx_rings, v_remainder; > > int num_stack_tx_queues; > > int first_xdp_tx_ring; > > int i, n, err, nvec; > > - int v_tx_rings; > > Nit: Needn't move v_tx_rings. Just to keep the reverse xmas tree style, of course I could add a new line to define v_remainder, but these two variables are related, so I think it is more appropriate to define them together. > > Reviewed-by: Frank Li <Frank.Li@nxp.com> > > > > > nvec = ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num; > > /* allocate MSIX for both messaging and Rx/Tx interrupts */ @@ > > -3066,10 +3066,14 @@ int enetc_alloc_msix(struct enetc_ndev_priv > > *priv) > > > > /* # of tx rings per int vector */ > > v_tx_rings = priv->num_tx_rings / priv->bdr_int_num; > > + v_remainder = priv->num_tx_rings % priv->bdr_int_num; > > > > - for (i = 0; i < priv->bdr_int_num; i++) > > - if (enetc_int_vector_init(priv, i, v_tx_rings)) > > + for (i = 0; i < priv->bdr_int_num; i++) { > > + int num_tx_rings = i < v_remainder ? v_tx_rings + 1 : v_tx_rings; > > + > > + if (enetc_int_vector_init(priv, i, num_tx_rings)) > > goto fail; > > + } > > > > num_stack_tx_queues = enetc_num_stack_tx_queues(priv); > > > > -- > > 2.34.1 > >
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index d36af3f8ba31..72ddf8b16271 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -3049,10 +3049,10 @@ static void enetc_int_vector_destroy(struct enetc_ndev_priv *priv, int i) int enetc_alloc_msix(struct enetc_ndev_priv *priv) { struct pci_dev *pdev = priv->si->pdev; + int v_tx_rings, v_remainder; int num_stack_tx_queues; int first_xdp_tx_ring; int i, n, err, nvec; - int v_tx_rings; nvec = ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num; /* allocate MSIX for both messaging and Rx/Tx interrupts */ @@ -3066,10 +3066,14 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv) /* # of tx rings per int vector */ v_tx_rings = priv->num_tx_rings / priv->bdr_int_num; + v_remainder = priv->num_tx_rings % priv->bdr_int_num; - for (i = 0; i < priv->bdr_int_num; i++) - if (enetc_int_vector_init(priv, i, v_tx_rings)) + for (i = 0; i < priv->bdr_int_num; i++) { + int num_tx_rings = i < v_remainder ? v_tx_rings + 1 : v_tx_rings; + + if (enetc_int_vector_init(priv, i, num_tx_rings)) goto fail; + } num_stack_tx_queues = enetc_num_stack_tx_queues(priv);