Skip to content

Commit 82c81e7

Browse files
leitaokuba-moo
authored andcommitted
crypto: caam: Unembed net_dev structure from qi
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 caam_qi_pcpu_priv by converting them into pointers, and allocating them dynamically. Use the leverage alloc_netdev_dummy() to allocate the net_device object at caam_qi_init(). The free of the device occurs at caam_qi_shutdown(). Link: https://lore.kernel.org/all/[email protected]/ [1] Signed-off-by: Breno Leitao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent beba377 commit 82c81e7

File tree

1 file changed

+35
-8
lines changed
  • drivers/crypto/caam

1 file changed

+35
-8
lines changed

drivers/crypto/caam/qi.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct caam_napi {
5757
*/
5858
struct caam_qi_pcpu_priv {
5959
struct caam_napi caam_napi;
60-
struct net_device net_dev;
60+
struct net_device *net_dev;
6161
struct qman_fq *rsp_fq;
6262
} ____cacheline_aligned;
6363

@@ -144,7 +144,7 @@ static void caam_fq_ern_cb(struct qman_portal *qm, struct qman_fq *fq,
144144
{
145145
const struct qm_fd *fd;
146146
struct caam_drv_req *drv_req;
147-
struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev);
147+
struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev->dev);
148148
struct caam_drv_private *priv = dev_get_drvdata(qidev);
149149

150150
fd = &msg->ern.fd;
@@ -530,6 +530,7 @@ static void caam_qi_shutdown(void *data)
530530

531531
if (kill_fq(qidev, per_cpu(pcpu_qipriv.rsp_fq, i)))
532532
dev_err(qidev, "Rsp FQ kill failed, cpu: %d\n", i);
533+
free_netdev(per_cpu(pcpu_qipriv.net_dev, i));
533534
}
534535

535536
qman_delete_cgr_safe(&priv->cgr);
@@ -573,7 +574,7 @@ static enum qman_cb_dqrr_result caam_rsp_fq_dqrr_cb(struct qman_portal *p,
573574
struct caam_napi *caam_napi = raw_cpu_ptr(&pcpu_qipriv.caam_napi);
574575
struct caam_drv_req *drv_req;
575576
const struct qm_fd *fd;
576-
struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev);
577+
struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev->dev);
577578
struct caam_drv_private *priv = dev_get_drvdata(qidev);
578579
u32 status;
579580

@@ -718,12 +719,24 @@ static void free_rsp_fqs(void)
718719
kfree(per_cpu(pcpu_qipriv.rsp_fq, i));
719720
}
720721

722+
static void free_caam_qi_pcpu_netdev(const cpumask_t *cpus)
723+
{
724+
struct caam_qi_pcpu_priv *priv;
725+
int i;
726+
727+
for_each_cpu(i, cpus) {
728+
priv = per_cpu_ptr(&pcpu_qipriv, i);
729+
free_netdev(priv->net_dev);
730+
}
731+
}
732+
721733
int caam_qi_init(struct platform_device *caam_pdev)
722734
{
723735
int err, i;
724736
struct device *ctrldev = &caam_pdev->dev, *qidev;
725737
struct caam_drv_private *ctrlpriv;
726738
const cpumask_t *cpus = qman_affine_cpus();
739+
cpumask_t clean_mask;
727740

728741
ctrlpriv = dev_get_drvdata(ctrldev);
729742
qidev = ctrldev;
@@ -743,6 +756,8 @@ int caam_qi_init(struct platform_device *caam_pdev)
743756
return err;
744757
}
745758

759+
cpumask_clear(&clean_mask);
760+
746761
/*
747762
* Enable the NAPI contexts on each of the core which has an affine
748763
* portal.
@@ -751,10 +766,16 @@ int caam_qi_init(struct platform_device *caam_pdev)
751766
struct caam_qi_pcpu_priv *priv = per_cpu_ptr(&pcpu_qipriv, i);
752767
struct caam_napi *caam_napi = &priv->caam_napi;
753768
struct napi_struct *irqtask = &caam_napi->irqtask;
754-
struct net_device *net_dev = &priv->net_dev;
769+
struct net_device *net_dev;
755770

771+
net_dev = alloc_netdev_dummy(0);
772+
if (!net_dev) {
773+
err = -ENOMEM;
774+
goto fail;
775+
}
776+
cpumask_set_cpu(i, &clean_mask);
777+
priv->net_dev = net_dev;
756778
net_dev->dev = *qidev;
757-
INIT_LIST_HEAD(&net_dev->napi_list);
758779

759780
netif_napi_add_tx_weight(net_dev, irqtask, caam_qi_poll,
760781
CAAM_NAPI_WEIGHT);
@@ -766,16 +787,22 @@ int caam_qi_init(struct platform_device *caam_pdev)
766787
dma_get_cache_alignment(), 0, NULL);
767788
if (!qi_cache) {
768789
dev_err(qidev, "Can't allocate CAAM cache\n");
769-
free_rsp_fqs();
770-
return -ENOMEM;
790+
err = -ENOMEM;
791+
goto fail2;
771792
}
772793

773794
caam_debugfs_qi_init(ctrlpriv);
774795

775796
err = devm_add_action_or_reset(qidev, caam_qi_shutdown, ctrlpriv);
776797
if (err)
777-
return err;
798+
goto fail2;
778799

779800
dev_info(qidev, "Linux CAAM Queue I/F driver initialised\n");
780801
return 0;
802+
803+
fail2:
804+
free_rsp_fqs();
805+
fail:
806+
free_caam_qi_pcpu_netdev(&clean_mask);
807+
return err;
781808
}

0 commit comments

Comments
 (0)