Skip to content

Commit 29e83c7

Browse files
horiagherbertx
authored andcommitted
crypto: caam/qi - simplify CGR allocation, freeing
CGRs (Congestion Groups) have to be freed by the same CPU that initialized them. This is why currently the driver takes special measures; however, using set_cpus_allowed_ptr() is incorrect - as reported by Sebastian. Instead of the generic solution of replacing set_cpus_allowed_ptr() with work_on_cpu_safe(), we use the qman_delete_cgr_safe() QBMan API instead of qman_delete_cgr() - which internally takes care of proper CGR deletion. Link: https://lkml.kernel.org/r/20181005125443.dfhd2asqktm22ney@linutronix.de Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 58c8a86 commit 29e83c7

File tree

2 files changed

+5
-40
lines changed

2 files changed

+5
-40
lines changed

drivers/crypto/caam/qi.c

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ EXPORT_SYMBOL(caam_congested);
8383
static u64 times_congested;
8484
#endif
8585

86-
/*
87-
* CPU from where the module initialised. This is required because QMan driver
88-
* requires CGRs to be removed from same CPU from where they were originally
89-
* allocated.
90-
*/
91-
static int mod_init_cpu;
92-
9386
/*
9487
* This is a a cache of buffers, from which the users of CAAM QI driver
9588
* can allocate short (CAAM_QI_MEMCACHE_SIZE) buffers. It's faster than
@@ -492,12 +485,11 @@ void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx)
492485
}
493486
EXPORT_SYMBOL(caam_drv_ctx_rel);
494487

495-
int caam_qi_shutdown(struct device *qidev)
488+
void caam_qi_shutdown(struct device *qidev)
496489
{
497-
int i, ret;
490+
int i;
498491
struct caam_qi_priv *priv = dev_get_drvdata(qidev);
499492
const cpumask_t *cpus = qman_affine_cpus();
500-
struct cpumask old_cpumask = current->cpus_allowed;
501493

502494
for_each_cpu(i, cpus) {
503495
struct napi_struct *irqtask;
@@ -510,26 +502,12 @@ int caam_qi_shutdown(struct device *qidev)
510502
dev_err(qidev, "Rsp FQ kill failed, cpu: %d\n", i);
511503
}
512504

513-
/*
514-
* QMan driver requires CGRs to be deleted from same CPU from where they
515-
* were instantiated. Hence we get the module removal execute from the
516-
* same CPU from where it was originally inserted.
517-
*/
518-
set_cpus_allowed_ptr(current, get_cpu_mask(mod_init_cpu));
519-
520-
ret = qman_delete_cgr(&priv->cgr);
521-
if (ret)
522-
dev_err(qidev, "Deletion of CGR failed: %d\n", ret);
523-
else
524-
qman_release_cgrid(priv->cgr.cgrid);
505+
qman_delete_cgr_safe(&priv->cgr);
506+
qman_release_cgrid(priv->cgr.cgrid);
525507

526508
kmem_cache_destroy(qi_cache);
527509

528-
/* Now that we're done with the CGRs, restore the cpus allowed mask */
529-
set_cpus_allowed_ptr(current, &old_cpumask);
530-
531510
platform_device_unregister(priv->qi_pdev);
532-
return ret;
533511
}
534512

535513
static void cgr_cb(struct qman_portal *qm, struct qman_cgr *cgr, int congested)
@@ -718,22 +696,11 @@ int caam_qi_init(struct platform_device *caam_pdev)
718696
struct device *ctrldev = &caam_pdev->dev, *qidev;
719697
struct caam_drv_private *ctrlpriv;
720698
const cpumask_t *cpus = qman_affine_cpus();
721-
struct cpumask old_cpumask = current->cpus_allowed;
722699
static struct platform_device_info qi_pdev_info = {
723700
.name = "caam_qi",
724701
.id = PLATFORM_DEVID_NONE
725702
};
726703

727-
/*
728-
* QMAN requires CGRs to be removed from same CPU+portal from where it
729-
* was originally allocated. Hence we need to note down the
730-
* initialisation CPU and use the same CPU for module exit.
731-
* We select the first CPU to from the list of portal owning CPUs.
732-
* Then we pin module init to this CPU.
733-
*/
734-
mod_init_cpu = cpumask_first(cpus);
735-
set_cpus_allowed_ptr(current, get_cpu_mask(mod_init_cpu));
736-
737704
qi_pdev_info.parent = ctrldev;
738705
qi_pdev_info.dma_mask = dma_get_mask(ctrldev);
739706
qi_pdev = platform_device_register_full(&qi_pdev_info);
@@ -795,8 +762,6 @@ int caam_qi_init(struct platform_device *caam_pdev)
795762
return -ENOMEM;
796763
}
797764

798-
/* Done with the CGRs; restore the cpus allowed mask */
799-
set_cpus_allowed_ptr(current, &old_cpumask);
800765
#ifdef CONFIG_DEBUG_FS
801766
debugfs_create_file("qi_congested", 0444, ctrlpriv->ctl,
802767
&times_congested, &caam_fops_u64_ro);

drivers/crypto/caam/qi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc);
173173
void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx);
174174

175175
int caam_qi_init(struct platform_device *pdev);
176-
int caam_qi_shutdown(struct device *dev);
176+
void caam_qi_shutdown(struct device *dev);
177177

178178
/**
179179
* qi_cache_alloc - Allocate buffers from CAAM-QI cache

0 commit comments

Comments
 (0)