diff mbox series

[net-next,v3,4/4] crypto: caam: Unembed net_dev structure in dpaa2

Message ID 20240702185557.3699991-5-leitao@debian.org (mailing list archive)
State Accepted
Commit 0e1a4d427f58b843864d835ccb79c32a118c6a77
Delegated to: Netdev Maintainers
Headers show
Series crypto: caam: Unembed net_dev | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 839 this patch: 839
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 846 this patch: 846
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 846 this patch: 846
netdev/checkpatch warning WARNING: line length of 87 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 5 this patch: 5
netdev/source_inline success Was 0 now: 0

Commit Message

Breno Leitao July 2, 2024, 6:55 p.m. UTC
Embedding net_device into structures prohibits the usage of flexible
arrays in the net_device structure. For more details, see the discussion
at [1].

Un-embed the net_devices from struct dpaa2_caam_priv_per_cpu by
converting them into pointers, and allocating them dynamically. Use the
leverage alloc_netdev_dummy() to allocate the net_device object at
dpaa2_dpseci_setup().

The free of the device occurs at dpaa2_dpseci_disable().

Link: https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ [1]
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/crypto/caam/caamalg_qi2.c | 28 +++++++++++++++++++++++++---
 drivers/crypto/caam/caamalg_qi2.h |  2 +-
 2 files changed, 26 insertions(+), 4 deletions(-)

Comments

Gaurav Jain July 3, 2024, 5:45 a.m. UTC | #1
Hi Breno

> -----Original Message-----
> From: Breno Leitao <leitao@debian.org>
> Sent: Wednesday, July 3, 2024 12:26 AM
> To: kuba@kernel.org; Horia Geanta <horia.geanta@nxp.com>; Pankaj Gupta
> <pankaj.gupta@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>; linux-
> crypto@vger.kernel.org; Herbert Xu <herbert@gondor.apana.org.au>; David S.
> Miller <davem@davemloft.net>
> Cc: horms@kernel.org; netdev@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [EXT] [PATCH net-next v3 4/4] crypto: caam: Unembed net_dev
> structure in dpaa2
>
> Caution: This is an external email. Please take care when clicking links or opening
> attachments. When in doubt, report the message using the 'Report this email'
> button
>
>
> Embedding net_device into structures prohibits the usage of flexible arrays in the
> net_device structure. For more details, see the discussion at [1].
>
> Un-embed the net_devices from struct dpaa2_caam_priv_per_cpu by converting
> them into pointers, and allocating them dynamically. Use the leverage
> alloc_netdev_dummy() to allocate the net_device object at
> dpaa2_dpseci_setup().
>
> The free of the device occurs at dpaa2_dpseci_disable().
>
> Link:
> https://lore.kernel/
> .org%2Fall%2F20240229225910.79e224cf%40kernel.org%2F&data=05%7C02%7
> Cgaurav.jain%40nxp.com%7C5748b86d20dc4be03e0b08dc9ac8bfae%7C686ea1d
> 3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638555434196331223%7CUnknow
> n%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWw
> iLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=LtDEO2Ko6WFFfip9iyj%2BQycgsBE
> LG3barb9byRSxQCg%3D&reserved=0 [1]
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  drivers/crypto/caam/caamalg_qi2.c | 28 +++++++++++++++++++++++++---
> drivers/crypto/caam/caamalg_qi2.h |  2 +-
>  2 files changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/crypto/caam/caamalg_qi2.c
> b/drivers/crypto/caam/caamalg_qi2.c
> index a4f6884416a0..207dc422785a 100644
> --- a/drivers/crypto/caam/caamalg_qi2.c
> +++ b/drivers/crypto/caam/caamalg_qi2.c
> @@ -4990,11 +4990,23 @@ static int dpaa2_dpseci_congestion_setup(struct
> dpaa2_caam_priv *priv,
>         return err;
>  }
>
> +static void free_dpaa2_pcpu_netdev(struct dpaa2_caam_priv *priv, const
> +cpumask_t *cpus) {
> +       struct dpaa2_caam_priv_per_cpu *ppriv;
> +       int i;
> +
> +       for_each_cpu(i, cpus) {
> +               ppriv = per_cpu_ptr(priv->ppriv, i);
> +               free_netdev(ppriv->net_dev);
> +       }
> +}
> +
>  static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)  {
>         struct device *dev = &ls_dev->dev;
>         struct dpaa2_caam_priv *priv;
>         struct dpaa2_caam_priv_per_cpu *ppriv;
> +       cpumask_t clean_mask;
>         int err, cpu;
>         u8 i;
>
> @@ -5073,6 +5085,7 @@ static int __cold dpaa2_dpseci_setup(struct
> fsl_mc_device *ls_dev)
>                 }
>         }
>
> +       cpumask_clear(&clean_mask);
>         i = 0;
>         for_each_online_cpu(cpu) {
>                 u8 j;
> @@ -5096,15 +5109,23 @@ static int __cold dpaa2_dpseci_setup(struct
> fsl_mc_device *ls_dev)
>                         priv->rx_queue_attr[j].fqid,
>                         priv->tx_queue_attr[j].fqid);
>
> -               ppriv->net_dev.dev = *dev;
> -               INIT_LIST_HEAD(&ppriv->net_dev.napi_list);

napi_list is not needed anymore? There is no mention in commit.

Regards
Gaurav Jain
> -               netif_napi_add_tx_weight(&ppriv->net_dev, &ppriv->napi,
> +               ppriv->net_dev = alloc_netdev_dummy(0);
> +               if (!ppriv->net_dev) {
> +                       err = -ENOMEM;
> +                       goto err_alloc_netdev;
> +               }
> +               cpumask_set_cpu(cpu, &clean_mask);
> +               ppriv->net_dev->dev = *dev;
> +
> +               netif_napi_add_tx_weight(ppriv->net_dev, &ppriv->napi,
>                                          dpaa2_dpseci_poll,
>                                          DPAA2_CAAM_NAPI_WEIGHT);
>         }
>
>         return 0;
>
> +err_alloc_netdev:
> +       free_dpaa2_pcpu_netdev(priv, &clean_mask);
>  err_get_rx_queue:
>         dpaa2_dpseci_congestion_free(priv);
>  err_get_vers:
> @@ -5153,6 +5174,7 @@ static int __cold dpaa2_dpseci_disable(struct
> dpaa2_caam_priv *priv)
>                 ppriv = per_cpu_ptr(priv->ppriv, i);
>                 napi_disable(&ppriv->napi);
>                 netif_napi_del(&ppriv->napi);
> +               free_netdev(ppriv->net_dev);
>         }
>
>         return 0;
> diff --git a/drivers/crypto/caam/caamalg_qi2.h
> b/drivers/crypto/caam/caamalg_qi2.h
> index abb502bb675c..61d1219a202f 100644
> --- a/drivers/crypto/caam/caamalg_qi2.h
> +++ b/drivers/crypto/caam/caamalg_qi2.h
> @@ -81,7 +81,7 @@ struct dpaa2_caam_priv {
>   */
>  struct dpaa2_caam_priv_per_cpu {
>         struct napi_struct napi;
> -       struct net_device net_dev;
> +       struct net_device *net_dev;
>         int req_fqid;
>         int rsp_fqid;
>         int prio;
> --
> 2.43.0
Breno Leitao July 3, 2024, 11:26 a.m. UTC | #2
Hello Gaurav,

On Wed, Jul 03, 2024 at 05:45:23AM +0000, Gaurav Jain wrote:

> > @@ -5096,15 +5109,23 @@ static int __cold dpaa2_dpseci_setup(struct
> > fsl_mc_device *ls_dev)
> >                         priv->rx_queue_attr[j].fqid,
> >                         priv->tx_queue_attr[j].fqid);
> >
> > -               ppriv->net_dev.dev = *dev;
> > -               INIT_LIST_HEAD(&ppriv->net_dev.napi_list);

> napi_list is not needed anymore? There is no mention in commit.

Good question. This allocation is now done in the alloc_netdev_dummy()
path. This is the code path:

alloc_netdev_dummy()->alloc_netdev()->alloc_netdev_mqs() which calls:

	INIT_LIST_HEAD(&dev->napi_list);

So, napi_list is initialized when the net_device interface is allocated.
diff mbox series

Patch

diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c
index a4f6884416a0..207dc422785a 100644
--- a/drivers/crypto/caam/caamalg_qi2.c
+++ b/drivers/crypto/caam/caamalg_qi2.c
@@ -4990,11 +4990,23 @@  static int dpaa2_dpseci_congestion_setup(struct dpaa2_caam_priv *priv,
 	return err;
 }
 
+static void free_dpaa2_pcpu_netdev(struct dpaa2_caam_priv *priv, const cpumask_t *cpus)
+{
+	struct dpaa2_caam_priv_per_cpu *ppriv;
+	int i;
+
+	for_each_cpu(i, cpus) {
+		ppriv = per_cpu_ptr(priv->ppriv, i);
+		free_netdev(ppriv->net_dev);
+	}
+}
+
 static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
 {
 	struct device *dev = &ls_dev->dev;
 	struct dpaa2_caam_priv *priv;
 	struct dpaa2_caam_priv_per_cpu *ppriv;
+	cpumask_t clean_mask;
 	int err, cpu;
 	u8 i;
 
@@ -5073,6 +5085,7 @@  static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
 		}
 	}
 
+	cpumask_clear(&clean_mask);
 	i = 0;
 	for_each_online_cpu(cpu) {
 		u8 j;
@@ -5096,15 +5109,23 @@  static int __cold dpaa2_dpseci_setup(struct fsl_mc_device *ls_dev)
 			priv->rx_queue_attr[j].fqid,
 			priv->tx_queue_attr[j].fqid);
 
-		ppriv->net_dev.dev = *dev;
-		INIT_LIST_HEAD(&ppriv->net_dev.napi_list);
-		netif_napi_add_tx_weight(&ppriv->net_dev, &ppriv->napi,
+		ppriv->net_dev = alloc_netdev_dummy(0);
+		if (!ppriv->net_dev) {
+			err = -ENOMEM;
+			goto err_alloc_netdev;
+		}
+		cpumask_set_cpu(cpu, &clean_mask);
+		ppriv->net_dev->dev = *dev;
+
+		netif_napi_add_tx_weight(ppriv->net_dev, &ppriv->napi,
 					 dpaa2_dpseci_poll,
 					 DPAA2_CAAM_NAPI_WEIGHT);
 	}
 
 	return 0;
 
+err_alloc_netdev:
+	free_dpaa2_pcpu_netdev(priv, &clean_mask);
 err_get_rx_queue:
 	dpaa2_dpseci_congestion_free(priv);
 err_get_vers:
@@ -5153,6 +5174,7 @@  static int __cold dpaa2_dpseci_disable(struct dpaa2_caam_priv *priv)
 		ppriv = per_cpu_ptr(priv->ppriv, i);
 		napi_disable(&ppriv->napi);
 		netif_napi_del(&ppriv->napi);
+		free_netdev(ppriv->net_dev);
 	}
 
 	return 0;
diff --git a/drivers/crypto/caam/caamalg_qi2.h b/drivers/crypto/caam/caamalg_qi2.h
index abb502bb675c..61d1219a202f 100644
--- a/drivers/crypto/caam/caamalg_qi2.h
+++ b/drivers/crypto/caam/caamalg_qi2.h
@@ -81,7 +81,7 @@  struct dpaa2_caam_priv {
  */
 struct dpaa2_caam_priv_per_cpu {
 	struct napi_struct napi;
-	struct net_device net_dev;
+	struct net_device *net_dev;
 	int req_fqid;
 	int rsp_fqid;
 	int prio;