crypto: starfive - fix recursive mutex_lock
authorTan En De <ende.tan@starfivetech.com>
Wed, 2 Nov 2022 07:00:47 +0000 (15:00 +0800)
committerJia Jie Ho <jiajie.ho@starfivetech.com>
Fri, 24 Feb 2023 05:50:03 +0000 (13:50 +0800)
In jh7110_rsa_domain_transfer(), there is a path that may lead to
recursive mutex_lock when calling jh7110_pka_wait_done(). Replace it
with completion variable, which is more suitable for signaling
completion instead of using mutex, not to mention using mutex_*() in
interrupt context is bad.

Signed-off-by: Tan En De <ende.tan@starfivetech.com>
Signed-off-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
drivers/crypto/starfive/jh7110/jh7110-pka.c
drivers/crypto/starfive/jh7110/jh7110-sec.c
drivers/crypto/starfive/jh7110/jh7110-str.h

index f01313a..2cada3a 100644 (file)
@@ -45,6 +45,9 @@ static int jh7110_pka_wait_done(struct jh7110_sec_dev *sdev)
 {
        int ret = -1;
 
+       wait_for_completion(&sdev->rsa_comp);
+       reinit_completion(&sdev->rsa_comp);
+       mutex_unlock(&sdev->doing);
        mutex_lock(&sdev->doing);
        if (sdev->done_flags & JH7110_PKA_DONE)
                ret = 0;
index a3dc124..b328a0c 100755 (executable)
@@ -67,8 +67,8 @@ static irqreturn_t jh7110_cryp_irq_thread(int irq, void *arg)
                if (sdev->cry_type != JH7110_PKA_TYPE)
                        return IRQ_HANDLED;
 
-       mutex_unlock(&sdev->doing);
 
+       complete(&sdev->rsa_comp);
        return IRQ_HANDLED;
 }
 
@@ -180,6 +180,7 @@ static int jh7110_cryp_probe(struct platform_device *pdev)
        mutex_init(&sdev->sha_lock);
        mutex_init(&sdev->aes_lock);
        mutex_init(&sdev->rsa_lock);
+       init_completion(&sdev->rsa_comp);
 
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "secreg");
        sdev->io_base = devm_ioremap_resource(dev, res);
index 06b210e..9113805 100644 (file)
@@ -109,6 +109,7 @@ struct jh7110_sec_dev {
        struct mutex                            sha_lock;
        struct mutex                            aes_lock;
        struct mutex                            rsa_lock;
+       struct completion                       rsa_comp;
 
 #define JH7110_SHA_SHA_DONE                    BIT(2)
 #define JH7110_AES_DONE                                BIT(3)