From patchwork Wed Sep 4 02:35:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129213 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D522E112C for ; Wed, 4 Sep 2019 02:36:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4F9F208E4 for ; Wed, 4 Sep 2019 02:36:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aKwsNpRy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727950AbfIDCff (ORCPT ); Tue, 3 Sep 2019 22:35:35 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45904 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727222AbfIDCfd (ORCPT ); Tue, 3 Sep 2019 22:35:33 -0400 Received: by mail-pg1-f195.google.com with SMTP id 4so6784367pgm.12; Tue, 03 Sep 2019 19:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/Vz3+FFcpK6JU84307Yag/Sm9BKHY7RRzc3BqadD5HQ=; b=aKwsNpRyh/V2OWW7e4hCWXCs0PB2rvQR5ufxCbysYv26uMecM6hOmgW6I5EIcFRwBU sEoAwPkhkru9Z+y7aZTarzJCJn9b9PxyPLnCI0Xknn5xvybgmn3Hsw4nYCS3f56lmX70 6WNotQ57WjfveCHi0zqCHrjdFcMBg700cc/rzDKvTBNntDtTYjJCBHysIKb5dkG3oJPD k5LXIZx1OVeg7Wjvpg6ooeKPt040Q76njTMyZmJONQon67ww81S/GkRxgjoKsF+L1xPq HZB4meG2rJVO01Jv39J526ZgBbSQjBxFI9m6QGxw9VvbdaXizZGVSUuYjSfBZv7/BxNW f/XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/Vz3+FFcpK6JU84307Yag/Sm9BKHY7RRzc3BqadD5HQ=; b=UAlP/VimAyUDkSMAdjsJuoOH6j/yoIAh2qHpyDv218+I04YNdbm8O0Al8bdihK1v8v 0VJkFfgE3ti8Yg7Ic7MJKI6Wc9wSIDM6VHFnqsWWUSYx1EnaO8f+HUsdzKDc7J5EUrJV IBLvkhOlbLII0bhoQ9jFe5/YuaY4fsj8WtHqRRUdlSdhpDqfN+2A9LVMrlxxrSeWN59V lEnh1o4DChAOOlNaUgst4lA6eeedjB5zbhXDiLs5LFMlWzHYCx1N7jfzWsyPuPl9htKw 5KFdQGDEPyvW42e24WAgtVHTnA+/oxnYLs9X2z+j+G1cy/J91J8zWEfemHxE23oriT3c YVDA== X-Gm-Message-State: APjAAAUdMq4VTd/zQse7QrHzOsec7h8ztdkNRcSiPlw0YFrGrJxJ1fre 5/RjPlCgOnQoSZiahMlaYMQopBr7uQM= X-Google-Smtp-Source: APXvYqxHYh3GCWa0AI1Ai2/9QvB01YG7eDooQPP9i1ZoxJRNQjuB6bjsvTas0nFhCn9yaCO95RqSpg== X-Received: by 2002:a17:90a:19c4:: with SMTP id 4mr2635503pjj.20.1567564532375; Tue, 03 Sep 2019 19:35:32 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:31 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 01/12] crypto: caam - make sure clocks are enabled first Date: Tue, 3 Sep 2019 19:35:04 -0700 Message-Id: <20190904023515.7107-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org In order to access IP block's registers we need to enable appropriate clocks first, otherwise we are risking hanging the CPU. The problem becomes very apparent when trying to use CAAM driver built as a kernel module. In that case caam_probe() gets called after clk_disable_unused() which means all of the necessary clocks are guaranteed to be disabled. Coincidentally, this change also fixes iomap leak introduced by early return (instead of "goto iounmap_ctrl") in commit 41fc54afae70 ("crypto: caam - simplfy clock initialization") Tested on ZII i.MX6Q+ RDU2 Fixes: 176435ad2ac7 ("crypto: caam - defer probing until QMan is available") Fixes: 41fc54afae70 ("crypto: caam - simplfy clock initialization") Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Tested-by: Horia Geantă --- drivers/crypto/caam/ctrl.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 3c059d0e4207..db22777d59b4 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -594,6 +594,21 @@ static int caam_probe(struct platform_device *pdev) dev_set_drvdata(dev, ctrlpriv); nprop = pdev->dev.of_node; + imx_soc_match = soc_device_match(caam_imx_soc_table); + caam_imx = (bool)imx_soc_match; + + if (imx_soc_match) { + if (!imx_soc_match->data) { + dev_err(dev, "No clock data provided for i.MX SoC"); + return -EINVAL; + } + + ret = init_clocks(dev, imx_soc_match->data); + if (ret) + return ret; + } + + /* Get configuration properties from device tree */ /* First, get register page */ ctrl = of_iomap(nprop, 0); @@ -604,9 +619,6 @@ static int caam_probe(struct platform_device *pdev) caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) & (CSTA_PLEND | CSTA_ALT_PLEND)); - imx_soc_match = soc_device_match(caam_imx_soc_table); - caam_imx = (bool)imx_soc_match; - comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms); if (comp_params & CTPR_MS_PS && rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR) caam_ptr_sz = sizeof(u64); @@ -640,18 +652,6 @@ static int caam_probe(struct platform_device *pdev) } #endif - if (imx_soc_match) { - if (!imx_soc_match->data) { - dev_err(dev, "No clock data provided for i.MX SoC"); - return -EINVAL; - } - - ret = init_clocks(dev, imx_soc_match->data); - if (ret) - return ret; - } - - /* Allocating the BLOCK_OFFSET based on the supported page size on * the platform */ From patchwork Wed Sep 4 02:35:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129211 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ACD3813B1 for ; Wed, 4 Sep 2019 02:36:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CB26208E4 for ; Wed, 4 Sep 2019 02:36:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mo44f9ga" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727940AbfIDCff (ORCPT ); Tue, 3 Sep 2019 22:35:35 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35393 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727930AbfIDCfe (ORCPT ); Tue, 3 Sep 2019 22:35:34 -0400 Received: by mail-pf1-f196.google.com with SMTP id 205so9763258pfw.2; Tue, 03 Sep 2019 19:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vkEqfSccoN1oLEz/SRYe0sDy4jQ4PKYZEDS6j9FIsrA=; b=mo44f9gaZjLO5yp1PvOxiMQzQk8O9iAxlVSx4K/SQpnmG+VFBf7LRm5Ce/BXhQXPmk dmx/y5QZg7tGISUHQZKqmd2uKB90L2iGQbqHvM+gEAE1zpODorp5NgIqj0KzleR77Ahm aob6QzNhCT8vXXhbZNswr2ODMoEYxGrgzmqyalHWh59rbH/TMzAWI0dFo26PWYHGmysW vp7t1MRT1Ki2+dLzYt9XBSevFxp/3uoadKneQ3bRbQa4M2iU6U+fTQHa94ElwRwF9FQp ebas5qf5/f0Is6Tfbyk1KeICKfh5btoj+eI182SFaJwqn64CwSyRJ9uDfU0ArQsjHV7o kP9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vkEqfSccoN1oLEz/SRYe0sDy4jQ4PKYZEDS6j9FIsrA=; b=G2Mge0EBtyH2Ipu+nrX3Zd8m77p75aZRn7dWfSBLyD9sXzegjmihpEKMiuwkyoi8cg hZRWi6izfgdAg6c4QEcp1axMd+RayavpESkRlSkro4DMjhgE0kmekUiKXXWohdJBVyVf GAOHJLLxQdvGowfvkvOjvs4DxsPfsn4bG++SbNQeniMMArKtgqw1GSuafGw7LsK7mjI8 Iv9B9znWplqDrfApNlEj0QiCYUsZKP9QhZmCwmdPU+DiLvwsCTl9JyGg4NU1k+veQHfQ k/Uchcu7LcLljxFgaEpAe83KrZNk7QoiB9nMzPWv+XdBPSew2L2XMeUW6JGlL9n8RjxF cz5g== X-Gm-Message-State: APjAAAVEwYY5QvEjhyTY2+yJk6fUaOJn7a0Nc9RM14Ha2RjI6sjsbeJh JjE8w5Cq50gugFAxVR3jyQtWbsLIlqY= X-Google-Smtp-Source: APXvYqzl/+Q+m0AdgnJABJi+C3BzrMBNqoW9byPFmsX+kO+EmmMx0mxCSgYdOAIG57gc1v66j7gl4A== X-Received: by 2002:a63:1749:: with SMTP id 9mr33806066pgx.0.1567564533848; Tue, 03 Sep 2019 19:35:33 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:33 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 02/12] crypto: caam - use devres to unmap JR's registers Date: Tue, 3 Sep 2019 19:35:05 -0700 Message-Id: <20190904023515.7107-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use devres to unmap memory and drop explicit de-initialization code. NOTE: There's no corresponding unmapping code in caam_jr_remove which seems like a resource leak. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Horia Geantă --- drivers/crypto/caam/jr.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index 417ad52615c6..7947d61a25cf 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -498,6 +498,7 @@ static int caam_jr_probe(struct platform_device *pdev) struct caam_job_ring __iomem *ctrl; struct caam_drv_private_jr *jrpriv; static int total_jobrs; + struct resource *r; int error; jrdev = &pdev->dev; @@ -513,9 +514,15 @@ static int caam_jr_probe(struct platform_device *pdev) nprop = pdev->dev.of_node; /* Get configuration properties from device tree */ /* First, get register page */ - ctrl = of_iomap(nprop, 0); + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!r) { + dev_err(jrdev, "platform_get_resource() failed\n"); + return -ENOMEM; + } + + ctrl = devm_ioremap(jrdev, r->start, resource_size(r)); if (!ctrl) { - dev_err(jrdev, "of_iomap() failed\n"); + dev_err(jrdev, "devm_ioremap() failed\n"); return -ENOMEM; } @@ -525,7 +532,6 @@ static int caam_jr_probe(struct platform_device *pdev) if (error) { dev_err(jrdev, "dma_set_mask_and_coherent failed (%d)\n", error); - iounmap(ctrl); return error; } @@ -536,7 +542,6 @@ static int caam_jr_probe(struct platform_device *pdev) error = caam_jr_init(jrdev); /* now turn on hardware */ if (error) { irq_dispose_mapping(jrpriv->irq); - iounmap(ctrl); return error; } From patchwork Wed Sep 4 02:35:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129209 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A25EB13B1 for ; Wed, 4 Sep 2019 02:36:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 825D9208E4 for ; Wed, 4 Sep 2019 02:36:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YsHRUH31" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728081AbfIDCgT (ORCPT ); Tue, 3 Sep 2019 22:36:19 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40093 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727949AbfIDCfg (ORCPT ); Tue, 3 Sep 2019 22:35:36 -0400 Received: by mail-pf1-f196.google.com with SMTP id w16so12213479pfn.7; Tue, 03 Sep 2019 19:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kt0n6bzsKyTFfjulhfhV37Mi2N4194QFhOH4tXXRRAc=; b=YsHRUH31fnI6bd0ZA0gAPNFt0v8ZXWq7ADbdpRPeLHyqusI3ibbDAteDhCwxIVu/u6 MohQ0/76rMSujjkA2HDpl+mLOP2N3iGee0LgKPQxm3SJ1i/k/tGJnpW+H4ScTRGuN6S1 q65bEV2rreX4ubjnRxE6i5JQfKW9XiRPmLV9MSSg+r4o4H0WFWn5FiRh9mN6MdAgm+Io ulhCkCYTfeuScYCp5RfIuI6UwoLPxZ/kEwQfsmS51Qzm2pyr5xh/1QWm/78uV5GBQGcl PzQGN0JKFxU/sRbVFwNW/82FKrW31c/IT5up8TI3shTqLSglJLw8oloceEC7qFpfw8Vp b/0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kt0n6bzsKyTFfjulhfhV37Mi2N4194QFhOH4tXXRRAc=; b=iNVCl9UbN1X0eq7x5SbN7GP0CQCyy2maJKvr/zb77XSwP7u3D06+0WtQdshGfUtXjp KzoDhGO5/bDAf3B2i5f5UcvhbP6MBFcYS972iotjrQ1rnP5PLr8xgLe/HRfmHTE4t5NN WPhu4XASILekodS4k3Vm9qlHhY49aNJC0CUJIV+/qu56/J7Rp27w0FhVEPbGuY96axL+ erwzb37OmxX59kKq5oUlu7Wd+WND+4d9yT0I+hx7xSIuEUaJPTYwUN1B8sHXmBCBo9X3 VnaXKmEh6KI8mQTd6Q5S7icWhy2i5Zukq1Gkb7GfRqSPt9U+dRo9g3WO+7DNvxpLT3AF iAOQ== X-Gm-Message-State: APjAAAWLxcuu43WFndYIsC+ZkpIg9lCAFKtGKGiSU2dMb2vu4J8KF6I0 oHo2YpoOTvBQABQYxZTQq8clg0utrCE= X-Google-Smtp-Source: APXvYqwM5QlTGTCCjesiCSHjb3QdWxA+jovpNDbl8leRnGMYBMG5GxsNU72mZeWskh2rDIivFDtNQA== X-Received: by 2002:a63:fb14:: with SMTP id o20mr32595287pgh.136.1567564535077; Tue, 03 Sep 2019 19:35:35 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:34 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 03/12] crypto: caam - check irq_of_parse_and_map for errors Date: Tue, 3 Sep 2019 19:35:06 -0700 Message-Id: <20190904023515.7107-4-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Irq_of_parse_and_map will return zero in case of error, so add a error check for that. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Horia Geantă --- drivers/crypto/caam/jr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index 7947d61a25cf..2732f3a0725a 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -537,6 +537,10 @@ static int caam_jr_probe(struct platform_device *pdev) /* Identify the interrupt */ jrpriv->irq = irq_of_parse_and_map(nprop, 0); + if (!jrpriv->irq) { + dev_err(jrdev, "irq_of_parse_and_map failed\n"); + return -EINVAL; + } /* Now do the platform independent part */ error = caam_jr_init(jrdev); /* now turn on hardware */ From patchwork Wed Sep 4 02:35:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129205 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D53DF112C for ; Wed, 4 Sep 2019 02:36:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B54A0208E4 for ; Wed, 4 Sep 2019 02:36:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ufvRrBj+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728067AbfIDCfk (ORCPT ); Tue, 3 Sep 2019 22:35:40 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46741 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727995AbfIDCfh (ORCPT ); Tue, 3 Sep 2019 22:35:37 -0400 Received: by mail-pg1-f195.google.com with SMTP id m3so10307789pgv.13; Tue, 03 Sep 2019 19:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RzbHrWIg0lBmbShcmgiv3bz+4va6hNwAkwxG7N3nZBA=; b=ufvRrBj+X4/HCzkx/G0GmmmdwOwqBYJF3kBUUebp9LPIMk548rPc6wAJ6NqmcFzPZU /6IKwQmbgBYpGtoSBgshWR5c499Lpr/BbJ/LhM1u3qKyLms1jtMmOETLC9vaOfoyAfsf cRGjvTSDUz0HqtSVXPD5lGmd52VPAbBOF6kXm/w8jKmMB6uba7m9O8KkCcyylAKQ4sRe Zn0m1CJnj5eAQkG17ftnKzsEvDX6CP4ulOgvJbnXnsyVgCAHuTxwVC3oz4QdGM3lwR7s Nyt6X9/5gkcbv3USjWheep1tq4JCWfzPrnMzRi8Ew6xX0K77YJDWnmrZ3Tm2fTDk429s Zmrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RzbHrWIg0lBmbShcmgiv3bz+4va6hNwAkwxG7N3nZBA=; b=qSIh85dvpVXUq9vVMh+EppTHFox4mnQb9L0w3CQhI43wWhDwsebpCyXw7SYvjqayQ/ r9pHkD06vwwLcsdGMeD8fA/8ICjzA2zUjxWm1aWVhJgGs5Hy3DfKCE/0zdT8TfMVPB5p fu1HChP45m1clRCiHaFNeV7DOwt4crLokDAOHZYu7Alcrn1RM4leqpZyYap8/SkkjoZn /J27qI7AKu/8AW4gJORJjVKOHUMwQ41E9jse9sLQb65mlj3CJes9gTdE81+2SIfI5xBD sio+5U8Srmc2sr1jbJZMnNCo6eVr94vf7johdtoQp9J2CdJtNNBYulvZ4wO7Oc/6WgvZ KTQg== X-Gm-Message-State: APjAAAW7pV1k+rA4Af+SMXrZfXlcgCrYcYp/AY7K/UflgwpfAlctXI1p z9RXWT3crDnZVc1rln5pxQB/eZyIJnY= X-Google-Smtp-Source: APXvYqyyz1ppKDoCfLzcc42jJI63cCVNbyYUIXxpPJ8LP/vk3zxG1+L1pTb2r3pPJePVtvcp+2hZPA== X-Received: by 2002:a17:90a:24a1:: with SMTP id i30mr2729879pje.128.1567564536188; Tue, 03 Sep 2019 19:35:36 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:35 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 04/12] crypto: caam - dispose of IRQ mapping only after IRQ is freed Date: Tue, 3 Sep 2019 19:35:07 -0700 Message-Id: <20190904023515.7107-5-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org With IRQ requesting being managed by devres we need to make sure that we dispose of IRQ mapping after and not before it is free'd (otherwise we'll end up with a warning from the kernel). To achieve that simply convert IRQ mapping to rely on devres as well. Fixes: f314f12db65c ("crypto: caam - convert caam_jr_init() to use devres") Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Horia Geantă --- drivers/crypto/caam/jr.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index 2732f3a0725a..d11956bc358f 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -146,7 +146,6 @@ static int caam_jr_remove(struct platform_device *pdev) ret = caam_jr_shutdown(jrdev); if (ret) dev_err(jrdev, "Failed to shut down job ring\n"); - irq_dispose_mapping(jrpriv->irq); return ret; } @@ -487,6 +486,10 @@ static int caam_jr_init(struct device *dev) return error; } +static void caam_jr_irq_dispose_mapping(void *data) +{ + irq_dispose_mapping((int)data); +} /* * Probe routine for each detected JobR subsystem. @@ -542,12 +545,15 @@ static int caam_jr_probe(struct platform_device *pdev) return -EINVAL; } + error = devm_add_action_or_reset(jrdev, caam_jr_irq_dispose_mapping, + (void *)jrpriv->irq); + if (error) + return error; + /* Now do the platform independent part */ error = caam_jr_init(jrdev); /* now turn on hardware */ - if (error) { - irq_dispose_mapping(jrpriv->irq); + if (error) return error; - } jrpriv->dev = jrdev; spin_lock(&driver_data.jr_alloc_lock); From patchwork Wed Sep 4 02:35:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129189 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A01E13B1 for ; Wed, 4 Sep 2019 02:35:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57E2E22DBF for ; Wed, 4 Sep 2019 02:35:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PIelyfrA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728046AbfIDCfk (ORCPT ); Tue, 3 Sep 2019 22:35:40 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43241 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727222AbfIDCfj (ORCPT ); Tue, 3 Sep 2019 22:35:39 -0400 Received: by mail-pg1-f195.google.com with SMTP id u72so6147327pgb.10; Tue, 03 Sep 2019 19:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VBYI9fYSI2nwboVcyiJxwUOgiBRwP/UdUW2a0Ojdh5g=; b=PIelyfrAXDiumhGRN4EjKHVTz8kwW9LilaHYfvmElZBKbdCVullDzD9Ne6yDZZ1QOv Wiq/+ts2cQaODhSncAwQ62j3JAmwFPBEwh/B+7l8WrJO91+Otn2FiJx0Qd0Tp3S+Fcwf JnnEqzoMMSOqdFGe7nE7/t45YUHLSpiDIUsoNSLk/d4I8g3j4l2KgKA8UGf2bJ5q8glx IKmi1h+HFfhFdHVMh1mS+ZFf983QuMrVVqnRbp/WJ8OHXbuk2igaW/h0033f84aC2kUw 09hA1ytd15j4zSVaag53xBnV/TnROOadTyxbleeyz7GDRmpPsQqtvBPpf/U2zxkwCyIV m/Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VBYI9fYSI2nwboVcyiJxwUOgiBRwP/UdUW2a0Ojdh5g=; b=QcKcLyRFQbB9/XLB7Clp5EMobzq/jYLwAh3JrLCb0+mbPQ9xk5HM7w27aoKiXJyK4T byUMO4a5UhTu+XklrWlrik6LQ0PWLV/xaaVeS5yVv8KMyZy5hTx6Tl+e5vN9hcgZZqtj ZzgTkYVW6E3XWzGutzIvtaeNz7XQ69qdQrxyahCWFsCunz8H5bZivYMUYjgojIUrDLtI o1uoLdD5YT1d311M/ggddz56qCLRa+6PU7goZRt5PSfbvwZG9V7UfJ9yihfRN7qdvpfI B7iEciJUcaak0AoKw70I+27HdGhUHdLsHLgDJ2RqaR1E2QzwImIw/cL9psC/5gA/cwDE 9lvw== X-Gm-Message-State: APjAAAUmDJWYr9PcG00RHFSnob6pGITwN4xrksyny1CuBo5nXN+ghILa /tOnvp5tSUGZ1T8jmjsJcSIMCjHJFEE= X-Google-Smtp-Source: APXvYqwbNaCiBRsKe1mxnFrqF9NZwtUDANOKU0kvpPSpBPZk6/adsZ8v83rhU3tryOl/O0h96Xch9w== X-Received: by 2002:a62:63c1:: with SMTP id x184mr45048290pfb.11.1567564537345; Tue, 03 Sep 2019 19:35:37 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:36 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 05/12] crypto: caam - use devres to unmap memory Date: Tue, 3 Sep 2019 19:35:08 -0700 Message-Id: <20190904023515.7107-6-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use devres to unmap memory and drop corresponding iounmap() call. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Horia Geantă --- drivers/crypto/caam/ctrl.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index db22777d59b4..35bf82d1bedc 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -308,11 +308,9 @@ static int caam_remove(struct platform_device *pdev) { struct device *ctrldev; struct caam_drv_private *ctrlpriv; - struct caam_ctrl __iomem *ctrl; ctrldev = &pdev->dev; ctrlpriv = dev_get_drvdata(ctrldev); - ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl; /* Remove platform devices under the crypto node */ of_platform_depopulate(ctrldev); @@ -334,9 +332,6 @@ static int caam_remove(struct platform_device *pdev) debugfs_remove_recursive(ctrlpriv->dfs_root); #endif - /* Unmap controller region */ - iounmap(ctrl); - return 0; } @@ -611,10 +606,11 @@ static int caam_probe(struct platform_device *pdev) /* Get configuration properties from device tree */ /* First, get register page */ - ctrl = of_iomap(nprop, 0); - if (!ctrl) { + ctrl = devm_of_iomap(dev, nprop, 0, NULL); + ret = PTR_ERR_OR_ZERO(ctrl); + if (ret) { dev_err(dev, "caam: of_iomap() failed\n"); - return -ENOMEM; + return ret; } caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) & @@ -632,22 +628,18 @@ static int caam_probe(struct platform_device *pdev) if (ctrlpriv->qi_present && !caam_dpaa2) { ret = qman_is_probed(); if (!ret) { - ret = -EPROBE_DEFER; - goto iounmap_ctrl; + return -EPROBE_DEFER; } else if (ret < 0) { dev_err(dev, "failing probe due to qman probe error\n"); - ret = -ENODEV; - goto iounmap_ctrl; + return -ENODEV; } ret = qman_portals_probed(); if (!ret) { - ret = -EPROBE_DEFER; - goto iounmap_ctrl; + return -EPROBE_DEFER; } else if (ret < 0) { dev_err(dev, "failing probe due to qman portals probe error\n"); - ret = -ENODEV; - goto iounmap_ctrl; + return -ENODEV; } } #endif @@ -722,7 +714,7 @@ static int caam_probe(struct platform_device *pdev) ret = dma_set_mask_and_coherent(dev, caam_get_dma_mask(dev)); if (ret) { dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", ret); - goto iounmap_ctrl; + return ret; } ctrlpriv->era = caam_get_era(ctrl); @@ -927,8 +919,6 @@ static int caam_probe(struct platform_device *pdev) if (ctrlpriv->qi_init) caam_qi_shutdown(dev); #endif -iounmap_ctrl: - iounmap(ctrl); return ret; } From patchwork Wed Sep 4 02:35:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129207 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 510FB112C for ; Wed, 4 Sep 2019 02:36:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 320A3208E4 for ; Wed, 4 Sep 2019 02:36:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SkqR950j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728509AbfIDCgN (ORCPT ); Tue, 3 Sep 2019 22:36:13 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:32928 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728053AbfIDCfk (ORCPT ); Tue, 3 Sep 2019 22:35:40 -0400 Received: by mail-pg1-f196.google.com with SMTP id n190so10349497pgn.0; Tue, 03 Sep 2019 19:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=79mGtzg2avauSIHeamJMGyddX51QEzlIz9816hhBdak=; b=SkqR950jwmIP+2IMd8TQ9ltEgBMi8oFi45w0W5YFwEN5Q86jZzTFq/ZH5DTJPMB6zT c0GVw/QE2hRHRx/Ug2ijGoJgFbrKUYNF+cmAQ+P/RghkJE7ckGBvpzp6iEp2E8Bi4ak1 EDbmkBW/u48ck7J54B0YyZYRlHPKrxTggmLuRSzCTXdFnfgqWeipKQuQ9jtYGFRNhfDg rCljJJQSqWtGDJeFdQTHV2JHjp5GIMIxBDNIQ+QYPjaBITtY6EL9UJhsyq/LzUk2aBlX oZJt6ALN1slq9F/FfPpBx9BjwUSyiJ8mjxROidVt5Fk9EIs8B3Ff3h/gGfvF+2KSErMG jX3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=79mGtzg2avauSIHeamJMGyddX51QEzlIz9816hhBdak=; b=El3J2100WyYboyW1Ahu716L5gk72Fj3F4nktAXzBLxUDMVJjMfKE81TfxdYSxRfrNd ESz95obtn0FYzQ/zy0Slp4u5TY48v79yBWDKxPKnLov6CkfkhuL9xCxQd5trWVgbQWdI nNZdSZPM4AFtKV7ojLYhJSMd8whwhrW+Pt2meHpxK8HimuwIdHMO3tNjdnveAdHXV2DA +vc4YCyP1VmlFqkHhNxm3YOTxpuswjGqYAtbpmhbCa/zmvu4w2LAgebEqYlDy+uVl161 gu1cS8er4QE+tl5ajcJL5X9m2Oq4uwBYgl9CbJMSETCrNvi8Iy6SLhxNsf9kzcrfRCQz OJ8A== X-Gm-Message-State: APjAAAV3bvTooeDFauQiVbX5ju6jgwhwdd2H0fskeUa06DVLO8z38tEy qlIj9MXJG3k0fIvp5r43v8W4o2wbvWc= X-Google-Smtp-Source: APXvYqwfycK82vB9x7SPDZkaPhMG1HPJrGE4mhyFXHoWcHHnUDragJhVmo/COyQ1VhZ4qlfBIEw3iw== X-Received: by 2002:a63:d04e:: with SMTP id s14mr31489424pgi.189.1567564539509; Tue, 03 Sep 2019 19:35:39 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:38 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 06/12] crypto: caam - use devres to remove debugfs Date: Tue, 3 Sep 2019 19:35:09 -0700 Message-Id: <20190904023515.7107-7-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use devres to remove debugfs and drop corresponding debugfs_remove_recursive() call. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Horia Geantă --- drivers/crypto/caam/ctrl.c | 21 ++++++++++++++------- drivers/crypto/caam/intern.h | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 35bf82d1bedc..254963498abc 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -327,11 +327,6 @@ static int caam_remove(struct platform_device *pdev) if (!ctrlpriv->mc_en && ctrlpriv->rng4_sh_init) deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init); - /* Shut down debug views */ -#ifdef CONFIG_DEBUG_FS - debugfs_remove_recursive(ctrlpriv->dfs_root); -#endif - return 0; } @@ -563,6 +558,13 @@ static int init_clocks(struct device *dev, const struct caam_imx_data *data) return devm_add_action_or_reset(dev, disable_clocks, ctrlpriv); } +#ifdef CONFIG_DEBUG_FS +static void caam_remove_debugfs(void *root) +{ + debugfs_remove_recursive(root); +} +#endif + /* Probe routine for CAAM top (controller) level */ static int caam_probe(struct platform_device *pdev) { @@ -575,6 +577,7 @@ static int caam_probe(struct platform_device *pdev) struct caam_drv_private *ctrlpriv; #ifdef CONFIG_DEBUG_FS struct caam_perfmon *perfmon; + struct dentry *dfs_root; #endif u32 scfgr, comp_params; u8 rng_vid; @@ -728,8 +731,12 @@ static int caam_probe(struct platform_device *pdev) */ perfmon = (struct caam_perfmon __force *)&ctrl->perfmon; - ctrlpriv->dfs_root = debugfs_create_dir(dev_name(dev), NULL); - ctrlpriv->ctl = debugfs_create_dir("ctl", ctrlpriv->dfs_root); + dfs_root = debugfs_create_dir(dev_name(dev), NULL); + ret = devm_add_action_or_reset(dev, caam_remove_debugfs, dfs_root); + if (ret) + return ret; + + ctrlpriv->ctl = debugfs_create_dir("ctl", dfs_root); #endif /* Check to see if (DPAA 1.x) QI present. If so, enable */ diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h index 731b06becd9c..359eb76d1259 100644 --- a/drivers/crypto/caam/intern.h +++ b/drivers/crypto/caam/intern.h @@ -102,7 +102,6 @@ struct caam_drv_private { * variables at runtime. */ #ifdef CONFIG_DEBUG_FS - struct dentry *dfs_root; struct dentry *ctl; /* controller dir */ struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap; #endif From patchwork Wed Sep 4 02:35:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129203 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D33FA112C for ; Wed, 4 Sep 2019 02:36:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB8F422CF8 for ; Wed, 4 Sep 2019 02:36:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g8l0cxXV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727722AbfIDCgH (ORCPT ); Tue, 3 Sep 2019 22:36:07 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45163 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728081AbfIDCfm (ORCPT ); Tue, 3 Sep 2019 22:35:42 -0400 Received: by mail-pl1-f196.google.com with SMTP id x3so3708123plr.12; Tue, 03 Sep 2019 19:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pt/GBpcJQe6RBgeOuceiGFWi5YBQKs6SQx1eqllYD2g=; b=g8l0cxXVh4OEOhKG8I6tq3p4vQpg14tn8CIGz/816KbkRL5eQ1tqYFwKjEB4KWK895 Xa6XyRi6O1pUht4dvtp0uoDpF03D9UCO1XNdmPYUif89ook1OAwh6YtcWtZSHWWR5ZQL XnSWL7ZJchmWD/VhCrLvhajnaig76SJcaLPzGomtqv/HgH37zmb7X8YYr2et/EIXRXpl nKVVn70e0IClBbKj6Oeo4jTxe8fWY9by6JZkTxt2IPqEYm4yau/Pjsy51+R5KkADGL3U hRm9P2wWZ6sFyHpVQamm8Lll7w7Im5wsSkdhSbZ18ZaaPyKpwzazemdL1/8Nnj5wAo1d O2WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pt/GBpcJQe6RBgeOuceiGFWi5YBQKs6SQx1eqllYD2g=; b=abfk9fLDXfz6vj2NgJlWouDeZ3TZMjMgKB8sMaKhugvF/iH4gPdgZYwlm7uMTQgr6z XBVTBfB9Dyc5Rs20cGfsPVLtT2BWfCFEd56S9H5QUvxsJK4ikD9pM6r2QeK9NnEWyq6z GKGPqHYJfChIXzsFsRz9B3d5nJtUmczkEi780S7KGGrEybDM/iRI1pw3nrWrAotV2vaA 5b7E9iAV9nQKWHTv5n05e6y4sKgQtdT4223IDdBqGXt2LzPcefkHY76C/GVzGYIB4OeV ap+jlLVF7CLNruedFuKQGeHvUIeSjunGc7XDQ4rp/ym7rNhFxB0KRPc0xUfCN3thmutI jMMA== X-Gm-Message-State: APjAAAXSmALtkMhc+t9GDqwwPBHiKJIrw8b/+Kmd/o+8ddwgV/8KOE2P T0IoIHkkxFyqK7y57TY8oOk+UolN46A= X-Google-Smtp-Source: APXvYqyLn46tC98ruFyb2a/5B7Q4zSm9ATGY1QCOLhxROkjwt/Bdtq8gz5KqrlqWlrXRbpjRrvTpNw== X-Received: by 2002:a17:902:b190:: with SMTP id s16mr28632954plr.199.1567564540678; Tue, 03 Sep 2019 19:35:40 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:40 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 07/12] crypto: caam - use devres to de-initialize the RNG Date: Tue, 3 Sep 2019 19:35:10 -0700 Message-Id: <20190904023515.7107-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use devres to de-initialize the RNG and drop explicit de-initialization code in caam_remove(). Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/crypto/caam/ctrl.c | 129 ++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 59 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 254963498abc..25f8f76551a5 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -175,6 +175,73 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc, return 0; } +/* + * deinstantiate_rng - builds and executes a descriptor on DECO0, + * which deinitializes the RNG block. + * @ctrldev - pointer to device + * @state_handle_mask - bitmask containing the instantiation status + * for the RNG4 state handles which exist in + * the RNG4 block: 1 if it's been instantiated + * + * Return: - 0 if no error occurred + * - -ENOMEM if there isn't enough memory to allocate the descriptor + * - -ENODEV if DECO0 couldn't be acquired + * - -EAGAIN if an error occurred when executing the descriptor + */ +static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask) +{ + u32 *desc, status; + int sh_idx, ret = 0; + + desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL); + if (!desc) + return -ENOMEM; + + for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) { + /* + * If the corresponding bit is set, then it means the state + * handle was initialized by us, and thus it needs to be + * deinitialized as well + */ + if ((1 << sh_idx) & state_handle_mask) { + /* + * Create the descriptor for deinstantating this state + * handle + */ + build_deinstantiation_desc(desc, sh_idx); + + /* Try to run it through DECO0 */ + ret = run_descriptor_deco0(ctrldev, desc, &status); + + if (ret || + (status && status != JRSTA_SSRC_JUMP_HALT_CC)) { + dev_err(ctrldev, + "Failed to deinstantiate RNG4 SH%d\n", + sh_idx); + break; + } + dev_info(ctrldev, "Deinstantiated RNG4 SH%d\n", sh_idx); + } + } + + kfree(desc); + + return ret; +} + +static void devm_deinstantiate_rng(void *data) +{ + struct device *ctrldev = data; + struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctrldev); + + /* + * De-initialize RNG state handles initialized by this driver. + * In case of SoCs with Management Complex, RNG is managed by MC f/w. + */ + if (ctrlpriv->rng4_sh_init) + deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init); +} + /* * instantiate_rng - builds and executes a descriptor on DECO0, * which initializes the RNG block. @@ -247,60 +314,11 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask, kfree(desc); - return ret; -} - -/* - * deinstantiate_rng - builds and executes a descriptor on DECO0, - * which deinitializes the RNG block. - * @ctrldev - pointer to device - * @state_handle_mask - bitmask containing the instantiation status - * for the RNG4 state handles which exist in - * the RNG4 block: 1 if it's been instantiated - * - * Return: - 0 if no error occurred - * - -ENOMEM if there isn't enough memory to allocate the descriptor - * - -ENODEV if DECO0 couldn't be acquired - * - -EAGAIN if an error occurred when executing the descriptor - */ -static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask) -{ - u32 *desc, status; - int sh_idx, ret = 0; - - desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL); - if (!desc) - return -ENOMEM; - - for (sh_idx = 0; sh_idx < RNG4_MAX_HANDLES; sh_idx++) { - /* - * If the corresponding bit is set, then it means the state - * handle was initialized by us, and thus it needs to be - * deinitialized as well - */ - if ((1 << sh_idx) & state_handle_mask) { - /* - * Create the descriptor for deinstantating this state - * handle - */ - build_deinstantiation_desc(desc, sh_idx); - - /* Try to run it through DECO0 */ - ret = run_descriptor_deco0(ctrldev, desc, &status); - - if (ret || - (status && status != JRSTA_SSRC_JUMP_HALT_CC)) { - dev_err(ctrldev, - "Failed to deinstantiate RNG4 SH%d\n", - sh_idx); - break; - } - dev_info(ctrldev, "Deinstantiated RNG4 SH%d\n", sh_idx); - } + if (!ret) { + ret = devm_add_action_or_reset(ctrldev, devm_deinstantiate_rng, + ctrldev); } - kfree(desc); - return ret; } @@ -320,13 +338,6 @@ static int caam_remove(struct platform_device *pdev) caam_qi_shutdown(ctrldev); #endif - /* - * De-initialize RNG state handles initialized by this driver. - * In case of SoCs with Management Complex, RNG is managed by MC f/w. - */ - if (!ctrlpriv->mc_en && ctrlpriv->rng4_sh_init) - deinstantiate_rng(ctrldev, ctrlpriv->rng4_sh_init); - return 0; } From patchwork Wed Sep 4 02:35:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129201 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 782ED13B1 for ; Wed, 4 Sep 2019 02:36:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 50C7522CF8 for ; Wed, 4 Sep 2019 02:36:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N89FswKp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728203AbfIDCgC (ORCPT ); Tue, 3 Sep 2019 22:36:02 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33173 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728107AbfIDCfm (ORCPT ); Tue, 3 Sep 2019 22:35:42 -0400 Received: by mail-pl1-f193.google.com with SMTP id t11so2765386plo.0; Tue, 03 Sep 2019 19:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a1OXvWBHbx6Jpw0bU7aMn0vFZQwXoXSk/2hAapg2HNo=; b=N89FswKpklM+SWQ7xH7sP3vvgxQXcVsgZFT70yhrJFGdHj5N1A5osZuiPlmaAxFmA6 y531hW2VCze8hfb67Vhp+kVuzpTWQQc0j22tqMgN5DofSmuSmuR264OdVGDmwjbg6o8k yE2v5xq/FY8VsUVvCHTvEj/CqCEVCFgM34ac6ZvA3G/aM8eaj6KGrmEf+uSi+p3XXRrA 3NOdQYfM0MaHc2DrsGXnjXan7w8SbtrwTuMx71geFdPBqNXD+fuHCNZ36qBbuTjnG9zh DuayDqXupdKaUoMPXjUkqmzjXllXl0ZYMKnEhtEegpG3srVZkjJJe1Z4l66MEWgHhMPp NrOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a1OXvWBHbx6Jpw0bU7aMn0vFZQwXoXSk/2hAapg2HNo=; b=nNNCZUN0rHXJiO9p724q/R4JwHWUqaXX5tWnjFDGBP9rrMyryO6S3YETXWMK86FO3I eafNpYHsVowCfi0vzC0dxctdvjvWBbG07wKTKhqTKdAMBMqHowKvRIe8LSMcYnyONxdN p9Qnhg/tktcGFHL0KVTK8ayvrldmw0GazJLC3ybFrxaIhfZ+XCmuKXWXaFiw7sylB/we CyZddQboX/Sx81AYpxB+CGUbgW7zCvlQwHYnFcO4g88IoudTI4XywggS4X+Bjs8/EMN8 a7dqblK7vd8T+Le7wpT0NXKJyL7HbXSd5tYBEkC3MLOmm1QWyGLy+iAdNmgOFIJKQ3EA QMcw== X-Gm-Message-State: APjAAAWh5e411KEGT3iO6gsEzeVgnjiiMTsM7MYizr0GpNTyJdYjK2AH jpq1aWTruq87gODqR7VaNF6AFXHz8fc= X-Google-Smtp-Source: APXvYqwUghA4TVKfW2qDHg/7FIK5uKmxjYeQsM/wQ6mJu/s0HfWLzR95ucRe/K4+OeOynoI9eHcJcw== X-Received: by 2002:a17:902:e605:: with SMTP id cm5mr1921890plb.226.1567564541965; Tue, 03 Sep 2019 19:35:41 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:41 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 08/12] crypto: caam - use devres to de-initialize QI Date: Tue, 3 Sep 2019 19:35:11 -0700 Message-Id: <20190904023515.7107-9-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use devres to de-initialize the QI and drop explicit de-initialization code in caam_remove(). Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Horia Geantă --- drivers/crypto/caam/ctrl.c | 14 +------------- drivers/crypto/caam/intern.h | 3 --- drivers/crypto/caam/qi.c | 8 ++++++-- drivers/crypto/caam/qi.h | 1 - 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 25f8f76551a5..37cd04f8ddb1 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -333,11 +333,6 @@ static int caam_remove(struct platform_device *pdev) /* Remove platform devices under the crypto node */ of_platform_depopulate(ctrldev); -#ifdef CONFIG_CAAM_QI - if (ctrlpriv->qi_init) - caam_qi_shutdown(ctrldev); -#endif - return 0; } @@ -770,7 +765,7 @@ static int caam_probe(struct platform_device *pdev) ret = of_platform_populate(nprop, caam_match, NULL, dev); if (ret) { dev_err(dev, "JR platform devices creation error\n"); - goto shutdown_qi; + return ret; } ring = 0; @@ -931,13 +926,6 @@ static int caam_probe(struct platform_device *pdev) caam_remove: caam_remove(pdev); return ret; - -shutdown_qi: -#ifdef CONFIG_CAAM_QI - if (ctrlpriv->qi_init) - caam_qi_shutdown(dev); -#endif - return ret; } static struct platform_driver caam_driver = { diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h index 359eb76d1259..c7c10c90464b 100644 --- a/drivers/crypto/caam/intern.h +++ b/drivers/crypto/caam/intern.h @@ -81,9 +81,6 @@ struct caam_drv_private { */ u8 total_jobrs; /* Total Job Rings in device */ u8 qi_present; /* Nonzero if QI present in device */ -#ifdef CONFIG_CAAM_QI - u8 qi_init; /* Nonzero if QI has been initialized */ -#endif u8 mc_en; /* Nonzero if MC f/w is active */ int secvio_irq; /* Security violation interrupt number */ int virt_en; /* Virtualization enabled in CAAM */ diff --git a/drivers/crypto/caam/qi.c b/drivers/crypto/caam/qi.c index 378f627e1d64..dacf2fa4aa8e 100644 --- a/drivers/crypto/caam/qi.c +++ b/drivers/crypto/caam/qi.c @@ -500,9 +500,10 @@ void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx) } EXPORT_SYMBOL(caam_drv_ctx_rel); -void caam_qi_shutdown(struct device *qidev) +static void caam_qi_shutdown(void *data) { int i; + struct device *qidev = data; struct caam_qi_priv *priv = &qipriv; const cpumask_t *cpus = qman_affine_cpus(); @@ -761,7 +762,10 @@ int caam_qi_init(struct platform_device *caam_pdev) ×_congested, &caam_fops_u64_ro); #endif - ctrlpriv->qi_init = 1; + err = devm_add_action_or_reset(qidev, caam_qi_shutdown, ctrlpriv); + if (err) + return err; + dev_info(qidev, "Linux CAAM Queue I/F driver initialised\n"); return 0; } diff --git a/drivers/crypto/caam/qi.h b/drivers/crypto/caam/qi.h index db0549549e3b..848958951f68 100644 --- a/drivers/crypto/caam/qi.h +++ b/drivers/crypto/caam/qi.h @@ -147,7 +147,6 @@ int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc); void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx); int caam_qi_init(struct platform_device *pdev); -void caam_qi_shutdown(struct device *dev); /** * qi_cache_alloc - Allocate buffers from CAAM-QI cache From patchwork Wed Sep 4 02:35:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129191 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51250112C for ; Wed, 4 Sep 2019 02:35:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30B432339E for ; Wed, 4 Sep 2019 02:35:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uA7W+0Qu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727995AbfIDCfo (ORCPT ); Tue, 3 Sep 2019 22:35:44 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35250 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728132AbfIDCfo (ORCPT ); Tue, 3 Sep 2019 22:35:44 -0400 Received: by mail-pl1-f193.google.com with SMTP id gn20so8847652plb.2; Tue, 03 Sep 2019 19:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BhpxphdWBSz1L2B9ZesztRoMGvUE4getK82ZLPQsGtU=; b=uA7W+0QuGo4CfSUGJFtcIxVBeJHAXQr7NMTxwWhTSHPmEft7Y50uESN5XZhyYSvskD oLnz4yfwXPto9dDkaWqTVvzzJUy3Kmmw3se8i7TQvlkspqQMwoWaFXCVmf29+AEV8xg/ 7jQip18Y1VLk4UJ6QKxt1zcNzeCTkJ0acHsZzy2Sdlk6/RYB759lxDFLga4VVeRfJ0pr CQ+ARLxflLHfqZ0/nCXGxuG2cv31mKP7PCAU4q6tJEazGiWpapEklyNL4WYWqPxNx/kw /puwtHk/f+Dv4VCACQ84nCZ/avvUws7kWue0JTFoC9PKONA25/8abUOnG7gpJnp3JVa6 JYYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BhpxphdWBSz1L2B9ZesztRoMGvUE4getK82ZLPQsGtU=; b=OvrqDSUcdcLz9yen0WoVAHFVpZubaktRSqfDychewGORT4GkPmf+i5RwIjJHoF6ShD 9YBcJQCUQ8YdkEvqQXI3nmpJwuXkSVrgFD+R1u3CLbUzpzmk/XYGndBKbRNMOVQNPwzk OHMjAHuGQYm7Iz1BKnqPs5c5Zau3MWdvT3S/Roz+IMnR1wn4uQyogrgi55ADonQ/0V/s I/Y9wh/77B3RaWx7qeTRa5qj5mbWy6tZFuHOqZMfpq6GrDqctAtnE+fH9YCI/F0ZUvi8 0EqAsWQlZ629QOOXbCevfcmFCBsvWHHGywpcGFTGogpKf2Y5fKgnLIAz2kSWaF2XJ5xp hTDg== X-Gm-Message-State: APjAAAUHZxRwcrmPe/6VR+FQGfUogAZlT8WcpEo6c2IAqnhrDa/JkGV3 ZBTU93CMSI1d1vLnw05MnKMM6XoYck8= X-Google-Smtp-Source: APXvYqw6FnMQh0U7BoqICAUQEf+gIXACPri+NLjJWx1LxnWK07lqcBLU657h8PWLnw8GSL5FgkQMPg== X-Received: by 2002:a17:902:758a:: with SMTP id j10mr31127712pll.233.1567564543249; Tue, 03 Sep 2019 19:35:43 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:42 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 09/12] crypto: caam - user devres to populate platform devices Date: Tue, 3 Sep 2019 19:35:12 -0700 Message-Id: <20190904023515.7107-10-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use devres to de-initialize the RNG and drop explicit de-initialization code in caam_remove(). Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Horia Geantă --- drivers/crypto/caam/ctrl.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 37cd04f8ddb1..4a84c2701311 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -322,20 +322,6 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask, return ret; } -static int caam_remove(struct platform_device *pdev) -{ - struct device *ctrldev; - struct caam_drv_private *ctrlpriv; - - ctrldev = &pdev->dev; - ctrlpriv = dev_get_drvdata(ctrldev); - - /* Remove platform devices under the crypto node */ - of_platform_depopulate(ctrldev); - - return 0; -} - /* * kick_trng - sets the various parameters for enabling the initialization * of the RNG4 block in CAAM @@ -762,7 +748,7 @@ static int caam_probe(struct platform_device *pdev) #endif } - ret = of_platform_populate(nprop, caam_match, NULL, dev); + ret = devm_of_platform_populate(dev); if (ret) { dev_err(dev, "JR platform devices creation error\n"); return ret; @@ -784,8 +770,7 @@ static int caam_probe(struct platform_device *pdev) /* If no QI and no rings specified, quit and go home */ if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) { dev_err(dev, "no queues configured, terminating\n"); - ret = -ENOMEM; - goto caam_remove; + return -ENOMEM; } if (ctrlpriv->era < 10) @@ -848,7 +833,7 @@ static int caam_probe(struct platform_device *pdev) } while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX)); if (ret) { dev_err(dev, "failed to instantiate RNG"); - goto caam_remove; + return ret; } /* * Set handles init'ed by this module as the complement of the @@ -922,10 +907,6 @@ static int caam_probe(struct platform_device *pdev) &ctrlpriv->ctl_tdsk_wrap); #endif return 0; - -caam_remove: - caam_remove(pdev); - return ret; } static struct platform_driver caam_driver = { @@ -934,7 +915,6 @@ static struct platform_driver caam_driver = { .of_match_table = caam_match, }, .probe = caam_probe, - .remove = caam_remove, }; module_platform_driver(caam_driver); From patchwork Wed Sep 4 02:35:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129193 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFB3513B1 for ; Wed, 4 Sep 2019 02:35:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9FB352339D for ; Wed, 4 Sep 2019 02:35:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SMUxmMqA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728167AbfIDCfq (ORCPT ); Tue, 3 Sep 2019 22:35:46 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46463 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728151AbfIDCfp (ORCPT ); Tue, 3 Sep 2019 22:35:45 -0400 Received: by mail-pl1-f195.google.com with SMTP id t1so594139plq.13; Tue, 03 Sep 2019 19:35:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+aCoTyAZq4seXeFgHdkNVujIOOXIGfZdUZjUTxRnOZM=; b=SMUxmMqAIY1WN9/3k3mlL3l2Yzd7jJU5ppxBEG6GWDsenDmSo01JOxBFxRCSK5ahuT zorODh4g8Ff4lDs+tV4BjCYQPoK3YRgnV+NQKJsUnyO367EI5EJA6tMKO352upN5KNyD 4/f1Hgu24ZwdZBLWCbihDXjyRhKV8DFHP5C19rUOpYwbj3U26Vu9en4exETIT6MpvZiy f398GEo6QASN1nddxrFHjeeEqIlVlvvEowtbOAf/WSi59gZ3OrHrEEcRUE5QT63qhsIB AznOzCQo5RX3YP4FwFMCaSe5h3jLgTVMZTHPMqGdbjGKXcstczSCPzEtCsWlcXHpGpm8 Sbaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+aCoTyAZq4seXeFgHdkNVujIOOXIGfZdUZjUTxRnOZM=; b=kpiBHlzdI+y2hFS/DudV54SACtuuP81ZrrQFlt8nTa0iEoK7tI9uk9361aSzQ+tTnk GGHPAVSG1GuMcL/ZXNJNdq36hIX6PofWvx2R0K6qzbIbc5gRIGK0JEdW4hzX0xLDrYMb T8sxvdyjosvK7rKj72ASDS1pc8GgUD+EsvCY5AtRptub0fAkvQ3qWOO+Rb9tpha62NUT W6bexUWxBJ/SEJbgIdCN3IkglR68p6d9GRDXagFQA1P/6f+aAZBtMlhPt69HGbNO+OSc fL+PtlMUYMCZYw1CfbheKdTDixzbgSrx5MtC87fQd+a79txNf9mJUUUlihiVACE7IcVg c4Eg== X-Gm-Message-State: APjAAAUdrGRZWpo6AKME4p1WDUzCUhCnUffup/Xk7JAWubD0VrES2l12 kryOSrSEhWMRcRUZlU5gL5lOCUG9lAI= X-Google-Smtp-Source: APXvYqydA6JXAS/WhUxQ3k++ihkagpTBo4PkpFPjs+D1DpDP+ZvmTu8rQyRF7N6qvhN+KBr3FYuZAw== X-Received: by 2002:a17:902:9686:: with SMTP id n6mr37418102plp.113.1567564544354; Tue, 03 Sep 2019 19:35:44 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:43 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 10/12] crypto: caam - populate platform devices last Date: Tue, 3 Sep 2019 19:35:13 -0700 Message-Id: <20190904023515.7107-11-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Move the call to devm_of_platform_populate() at the end of caam_probe(), so we won't try to add any child devices until all of the initialization is finished successfully. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/crypto/caam/ctrl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index 4a84c2701311..d101c28d3d1f 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -748,12 +748,6 @@ static int caam_probe(struct platform_device *pdev) #endif } - ret = devm_of_platform_populate(dev); - if (ret) { - dev_err(dev, "JR platform devices creation error\n"); - return ret; - } - ring = 0; for_each_available_child_of_node(nprop, np) if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") || @@ -906,6 +900,13 @@ static int caam_probe(struct platform_device *pdev) debugfs_create_blob("tdsk", S_IRUSR | S_IRGRP | S_IROTH, ctrlpriv->ctl, &ctrlpriv->ctl_tdsk_wrap); #endif + + ret = devm_of_platform_populate(dev); + if (ret) { + dev_err(dev, "JR platform devices creation error\n"); + return ret; + } + return 0; } From patchwork Wed Sep 4 02:35:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129197 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02A04112C for ; Wed, 4 Sep 2019 02:36:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDB6322DBF for ; Wed, 4 Sep 2019 02:36:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M5QHPpHz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728196AbfIDCfr (ORCPT ); Tue, 3 Sep 2019 22:35:47 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35855 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728163AbfIDCfq (ORCPT ); Tue, 3 Sep 2019 22:35:46 -0400 Received: by mail-pl1-f193.google.com with SMTP id f19so8849396plr.3; Tue, 03 Sep 2019 19:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HBBIQ2ygAAAzNXsLICQMJrTUcjEuunt/v0rZQB2OEV8=; b=M5QHPpHz5gIwrnbKFChx+FQxefSY8txehv2OMO9WlkjGE+jJy4GQpyfyLNmOf0F8Ng 63HZCJLelAe25ImvuEzSo97x7SLlwszwlwp0xRR169CafLYDUdIb5LOwvj8PvHixugvK oDcSrIX5+tQiLEKHnq2+tslWOCDzDfwzC8h0YB19KakOExWjjVoAhRT4SJNaZzE2rnSt RxjT+0S+Q/bC3ncG0i49s+4eLD/wpWXfV4wFD7JBda8c+G+ucy92NlOSoOS4/IFConSp otV/QZc7XcOqCVOURu5CEq/H5LTkFRL3+1pvNpj2GzohHESriwu5Id6MyouazRIj8qeb Tr6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HBBIQ2ygAAAzNXsLICQMJrTUcjEuunt/v0rZQB2OEV8=; b=sPwGT3fSfCPrbDVc4J1J9zHfYwkUjeyZPHjWpz1UK/TjdtwxxWqkE2rFU0pxo4QRFc PUcycOdvLvDJr5Wst3M1h7lju0xlm1hHnltr1pRpWh+yZHPlU5nOCZ2mso58LzfN1SbV qsJCkdZOxHEt/xo1g45tc4oBdTstgAaIZkfSg1NKhMs5ZcIhMiWOOqWat314rqLw/tCy BWqmonDv6OdoOgElVCvrsL1POsf3yFw3E8B1wjrn9N6FiWcUauS+GW6OM//zyAkZ+zbE H353h5beM2XuJqeYpynAgJFx/NWrqWlIV4aIAUL1FubdMwpJk7p9uS1KFZyZTy4tZv/p s0QQ== X-Gm-Message-State: APjAAAV2ry5tGSskk1+9Q5SdMmWconcIrNiDgObeYcfXYv8U8yifqSrR 9Lrwgw1NVxsKwb/mOpHHbV9L+bhVepU= X-Google-Smtp-Source: APXvYqwGvKRGkMvXbflmJT/LOzlrcM/4q3gVyrWRlvcjoRY2KIPfksZ/8ZI6d+uNq7bo3NCwW7M50w== X-Received: by 2002:a17:902:7c07:: with SMTP id x7mr20907394pll.54.1567564545683; Tue, 03 Sep 2019 19:35:45 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:45 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 11/12] crypto: caam - convert caamrng to platform device Date: Tue, 3 Sep 2019 19:35:14 -0700 Message-Id: <20190904023515.7107-12-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org In order to allow caam_jr_enqueue() to lock underlying JR's device (via device_lock(), see commit that follows) we need to make sure that no code calls caam_jr_enqueue() as a part of caam_jr_probe() to avoid a deadlock. Unfortunately, current implementation of caamrng code does exactly that in caam_init_buf(). Another big problem with original caamrng initialization is a circular reference in the form of: 1. caam_rng_init() aquires JR via caam_jr_alloc(). Freed only by caam_rng_exit() 2. caam_rng_exit() is only called by unregister_algs() once last JR is shut down 3. caam_jr_remove() won't call unregister_algs() for last JR until tfm_count reaches zero, which can only happen via unregister_algs() -> caam_rng_exit() call chain. To avoid all of that, convert caamrng code to a platform device driver and extend caam_probe() to create corresponding platform device. Additionally, this change also allows us to remove any access to struct caam_drv_private in caamrng.c as well as simplify resource ownership/deallocation via devres. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/crypto/caam/caamrng.c | 102 +++++++++++++--------------------- drivers/crypto/caam/ctrl.c | 39 +++++++++++++ drivers/crypto/caam/jr.c | 23 ++++++-- 3 files changed, 97 insertions(+), 67 deletions(-) diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index e8baacaabe07..f83ad34ac009 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -70,6 +70,7 @@ struct buf_data { /* rng per-device context */ struct caam_rng_ctx { + struct hwrng hwrng; struct device *jrdev; dma_addr_t sh_desc_dma; u32 sh_desc[DESC_RNG_LEN]; @@ -78,14 +79,6 @@ struct caam_rng_ctx { struct buf_data bufs[2]; }; -static struct caam_rng_ctx *rng_ctx; - -/* - * Variable used to avoid double free of resources in case - * algorithm registration was unsuccessful - */ -static bool init_done; - static inline void rng_unmap_buf(struct device *jrdev, struct buf_data *bd) { if (bd->addr) @@ -143,7 +136,7 @@ static inline int submit_job(struct caam_rng_ctx *ctx, int to_current) static int caam_read(struct hwrng *rng, void *data, size_t max, bool wait) { - struct caam_rng_ctx *ctx = rng_ctx; + struct caam_rng_ctx *ctx = (void *)rng->priv; struct buf_data *bd = &ctx->bufs[ctx->current_buf]; int next_buf_idx, copied_idx; int err; @@ -247,15 +240,16 @@ static inline int rng_create_job_desc(struct caam_rng_ctx *ctx, int buf_id) static void caam_cleanup(struct hwrng *rng) { int i; + struct caam_rng_ctx *ctx = (void *)rng->priv; struct buf_data *bd; for (i = 0; i < 2; i++) { - bd = &rng_ctx->bufs[i]; + bd = &ctx->bufs[i]; if (atomic_read(&bd->empty) == BUF_PENDING) wait_for_completion(&bd->filled); } - rng_unmap_ctx(rng_ctx); + rng_unmap_ctx(ctx); } static int caam_init_buf(struct caam_rng_ctx *ctx, int buf_id) @@ -274,12 +268,10 @@ static int caam_init_buf(struct caam_rng_ctx *ctx, int buf_id) return 0; } -static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev) +static int caam_init_rng(struct caam_rng_ctx *ctx) { int err; - ctx->jrdev = jrdev; - err = rng_create_sh_desc(ctx); if (err) return err; @@ -294,65 +286,49 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev) return caam_init_buf(ctx, 1); } -static struct hwrng caam_rng = { - .name = "rng-caam", - .cleanup = caam_cleanup, - .read = caam_read, -}; - -void caam_rng_exit(void) +static void caamrng_jr_free(void *data) { - if (!init_done) - return; - - caam_jr_free(rng_ctx->jrdev); - hwrng_unregister(&caam_rng); - kfree(rng_ctx); + caam_jr_free(data); } -int caam_rng_init(struct device *ctrldev) +static int caamrng_probe(struct platform_device *pdev) { - struct device *dev; - u32 rng_inst; - struct caam_drv_private *priv = dev_get_drvdata(ctrldev); + struct device *dev = &pdev->dev; + struct caam_rng_ctx *ctx; int err; - init_done = false; - - /* Check for an instantiated RNG before registration */ - if (priv->era < 10) - rng_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) & - CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT; - else - rng_inst = rd_reg32(&priv->ctrl->vreg.rng) & CHA_VER_NUM_MASK; - if (!rng_inst) - return 0; + ctx = devm_kmalloc(dev, sizeof(*ctx), GFP_DMA | GFP_KERNEL); + if (!ctx) + return -ENOMEM; - dev = caam_jr_alloc(); - if (IS_ERR(dev)) { - pr_err("Job Ring Device allocation for transform failed\n"); - return PTR_ERR(dev); - } - rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA | GFP_KERNEL); - if (!rng_ctx) { - err = -ENOMEM; - goto free_caam_alloc; + ctx->jrdev = caam_jr_alloc(); + err = PTR_ERR_OR_ZERO(ctx->jrdev); + if (err) { + dev_err(dev, "Job Ring Device allocation for transform failed\n"); + return err; } - err = caam_init_rng(rng_ctx, dev); - if (err) - goto free_rng_ctx; - dev_info(dev, "registering rng-caam\n"); + err = devm_add_action_or_reset(dev, caamrng_jr_free, ctx->jrdev); + if (err) + return err; - err = hwrng_register(&caam_rng); - if (!err) { - init_done = true; + err = caam_init_rng(ctx); + if (err) return err; - } -free_rng_ctx: - kfree(rng_ctx); -free_caam_alloc: - caam_jr_free(dev); - return err; + ctx->hwrng.cleanup = caam_cleanup; + ctx->hwrng.read = caam_read; + ctx->hwrng.name = "rng-caam"; + ctx->hwrng.priv = (unsigned long)ctx; + + dev_info(dev, "registering rng-caam\n"); + + return devm_hwrng_register(dev, &ctx->hwrng); } + +struct platform_driver caamrng_driver = { + .probe = caamrng_probe, + .driver = { + .name = "caamrng", + }, +}; diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index d101c28d3d1f..ce3d5817c443 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -557,6 +557,26 @@ static void caam_remove_debugfs(void *root) } #endif +static void caam_platform_device_unregister(void *data) +{ + platform_device_unregister(data); +} + +static int caam_platform_device_register(struct device *dev, const char *name) +{ + struct platform_device *pdev; + int ret; + + pdev = platform_device_register_simple(name, -1, NULL, 0); + ret = PTR_ERR_OR_ZERO(pdev); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, + caam_platform_device_unregister, + pdev); +} + /* Probe routine for CAAM top (controller) level */ static int caam_probe(struct platform_device *pdev) { @@ -907,6 +927,25 @@ static int caam_probe(struct platform_device *pdev) return ret; } + if (IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API)) { + u32 rng_inst; + + /* Check for an instantiated RNG before registration */ + if (ctrlpriv->era < 10) + rng_inst = (rd_reg32(&ctrl->perfmon.cha_num_ls) & + CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT; + else + rng_inst = rd_reg32(&ctrl->vreg.rng) & + CHA_VER_NUM_MASK; + + + if (rng_inst) { + ret = caam_platform_device_register(dev, "caamrng"); + if (ret) + return ret; + } + } + return 0; } diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index d11956bc358f..47b389cb1c62 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -37,7 +37,6 @@ static void register_algs(struct device *dev) caam_algapi_init(dev); caam_algapi_hash_init(dev); caam_pkc_init(dev); - caam_rng_init(dev); caam_qi_algapi_init(dev); algs_unlock: @@ -53,7 +52,6 @@ static void unregister_algs(void) caam_qi_algapi_exit(); - caam_rng_exit(); caam_pkc_exit(); caam_algapi_hash_exit(); caam_algapi_exit(); @@ -287,7 +285,7 @@ struct device *caam_jr_alloc(void) if (list_empty(&driver_data.jr_list)) { spin_unlock(&driver_data.jr_alloc_lock); - return ERR_PTR(-ENODEV); + return ERR_PTR(-EPROBE_DEFER); } list_for_each_entry(jrpriv, &driver_data.jr_list, list_node) { @@ -587,15 +585,32 @@ static struct platform_driver caam_jr_driver = { .remove = caam_jr_remove, }; +extern struct platform_driver caamrng_driver; + static int __init jr_driver_init(void) { + int ret; + spin_lock_init(&driver_data.jr_alloc_lock); INIT_LIST_HEAD(&driver_data.jr_list); - return platform_driver_register(&caam_jr_driver); + ret = platform_driver_register(&caam_jr_driver); + if (ret) + return ret; + + if (IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API)) { + ret = platform_driver_register(&caamrng_driver); + if (ret) { + platform_driver_unregister(&caam_jr_driver); + return ret; + } + } + + return 0; } static void __exit jr_driver_exit(void) { + platform_driver_unregister(&caamrng_driver); platform_driver_unregister(&caam_jr_driver); } From patchwork Wed Sep 4 02:35:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11129195 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A76813B1 for ; Wed, 4 Sep 2019 02:36:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5234E22DBF for ; Wed, 4 Sep 2019 02:36:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KlNICeLz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728259AbfIDCfz (ORCPT ); Tue, 3 Sep 2019 22:35:55 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42210 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728203AbfIDCfs (ORCPT ); Tue, 3 Sep 2019 22:35:48 -0400 Received: by mail-pl1-f195.google.com with SMTP id y1so8822828plp.9; Tue, 03 Sep 2019 19:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8qVYauEaF289x3cMhI4s/1Faayix+NfSLUGn8z2s1l8=; b=KlNICeLzni8606fHeBg3p2Gs7jsz8W0wYZD1eNpKr8RBpEsnEK6/Vl97FcoRSEuixK JOhlFlN7UKvbN/xLzPQYke6bGEvG788Raxy0rUnH5evklIc6LeWgbX0N0+oMVBXE+fpj VbVPcBKlCaWo7xdZE5L+SmPCrDBbn0U5yAa2twIsEcAXRgsK/bpD54U4vnBIs0nSMtp0 hPBNidHIMqeF2sG4rcKjAnxFpAoDjivJZnDfYN7g71tYc6nuW67W9a0+Lx9dW+TykGLm ytdI/PPaUBKWb9+xvDkNMvjDeate6YydpvgqlB997iKrl8Nye0rQkrAfj+/qiCNfypeq sd8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8qVYauEaF289x3cMhI4s/1Faayix+NfSLUGn8z2s1l8=; b=rgFPqiyDIui5ZuMhEvDVAmkVrx0Dn2mDqL0E6dqrLQk2HywIYPeZ9+mni4i6HBb2GP Mjki1wMp8JsP2WESEj+1UFwRqCHxLARvHuzKygprWAzl9w33j+aXyCeTtgPKYKWKMqAg Ovvprv+P1I+2w0uIKZX3JjHUOt7W3LGEgJaBRmINr2HoUi4FCSitrIdXJXJyXBCVy+Rx U5yJTJl+24Up97/VMsw6+egMMbPJLOPUTl7iNEdhUyRBrTO6PEAg2soBF0lXXy8j/wbG RMcwZErQW+vMOfhS7rb8fO0BhtbsaqvCzQz0ycEXcGYbl2ujTOn4q+M4h3HdWlaJqaCg CUGQ== X-Gm-Message-State: APjAAAX2WVmW5jKLP4pug9/GAy04TcorOQ0fPO0cwxdRrvtItwUiYM39 nS1DnLtw8rtE2MtSbK/jfH22s43XBz0= X-Google-Smtp-Source: APXvYqwnAGnhH5o46xWifKgP2jXR/QyoQk1BhIrYvTTHKZS9rgDcSS9ehbi5TqfWaCTe+QkEBvIwjw== X-Received: by 2002:a17:902:7886:: with SMTP id q6mr39191212pll.78.1567564546864; Tue, 03 Sep 2019 19:35:46 -0700 (PDT) Received: from localhost.lan (c-67-185-54-80.hsd1.wa.comcast.net. [67.185.54.80]) by smtp.gmail.com with ESMTPSA id i74sm7480250pfe.28.2019.09.03.19.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 19:35:46 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant=C4=83?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org Subject: [PATCH 12/12] crypto: caam - change JR device ownership scheme Date: Tue, 3 Sep 2019 19:35:15 -0700 Message-Id: <20190904023515.7107-13-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190904023515.7107-1-andrew.smirnov@gmail.com> References: <20190904023515.7107-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Returning -EBUSY from platform device's .remove() callback won't stop the removal process, so the code in caam_jr_remove() is not going to have the desired effect of preventing JR from being removed. In order to be able to deal with removal of the JR device, change the code as follows: 1. To make sure that underlying struct device remains valid for as long as we have a reference to it, add appropriate device refcount management to caam_jr_alloc() and caam_jr_free() 2. To make sure that device removal doesn't happen in parallel to use using the device in caam_jr_enqueue() augment the latter to acquire/release device lock for the duration of the subroutine 3. In order to handle the case when caam_jr_enqueue() is executed right after corresponding caam_jr_remove(), add code to check that driver data has not been set to NULL. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Herbert Xu Cc: Iuliana Prodan Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/crypto/caam/jr.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index 47b389cb1c62..8a30bbd7f2aa 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -124,14 +124,6 @@ static int caam_jr_remove(struct platform_device *pdev) jrdev = &pdev->dev; jrpriv = dev_get_drvdata(jrdev); - /* - * Return EBUSY if job ring already allocated. - */ - if (atomic_read(&jrpriv->tfm_count)) { - dev_err(jrdev, "Device is busy\n"); - return -EBUSY; - } - /* Unregister JR-based RNG & crypto algorithms */ unregister_algs(); @@ -300,7 +292,7 @@ struct device *caam_jr_alloc(void) if (min_jrpriv) { atomic_inc(&min_jrpriv->tfm_count); - dev = min_jrpriv->dev; + dev = get_device(min_jrpriv->dev); } spin_unlock(&driver_data.jr_alloc_lock); @@ -318,13 +310,16 @@ void caam_jr_free(struct device *rdev) struct caam_drv_private_jr *jrpriv = dev_get_drvdata(rdev); atomic_dec(&jrpriv->tfm_count); + put_device(rdev); } EXPORT_SYMBOL(caam_jr_free); /** * caam_jr_enqueue() - Enqueue a job descriptor head. Returns 0 if OK, * -EBUSY if the queue is full, -EIO if it cannot map the caller's - * descriptor. + * descriptor, -ENODEV if given device was removed and is no longer + * valid + * * @dev: device of the job ring to be used. This device should have * been assigned prior by caam_jr_register(). * @desc: points to a job descriptor that execute our request. All @@ -354,15 +349,32 @@ int caam_jr_enqueue(struct device *dev, u32 *desc, u32 status, void *areq), void *areq) { - struct caam_drv_private_jr *jrp = dev_get_drvdata(dev); + struct caam_drv_private_jr *jrp; struct caam_jrentry_info *head_entry; int head, tail, desc_size; dma_addr_t desc_dma; + /* + * Lock the device to prevent it from being removed while we + * are using it + */ + device_lock(dev); + + /* + * If driver data is NULL, it is very likely that this device + * was removed already. Nothing we can do here but bail out. + */ + jrp = dev_get_drvdata(dev); + if (!jrp) { + device_unlock(dev); + return -ENODEV; + } + desc_size = (caam32_to_cpu(*desc) & HDR_JD_LENGTH_MASK) * sizeof(u32); desc_dma = dma_map_single(dev, desc, desc_size, DMA_TO_DEVICE); if (dma_mapping_error(dev, desc_dma)) { dev_err(dev, "caam_jr_enqueue(): can't map jobdesc\n"); + device_unlock(dev); return -EIO; } @@ -375,6 +387,7 @@ int caam_jr_enqueue(struct device *dev, u32 *desc, CIRC_SPACE(head, tail, JOBR_DEPTH) <= 0) { spin_unlock_bh(&jrp->inplock); dma_unmap_single(dev, desc_dma, desc_size, DMA_TO_DEVICE); + device_unlock(dev); return -EBUSY; } @@ -411,6 +424,7 @@ int caam_jr_enqueue(struct device *dev, u32 *desc, jrp->inpring_avail = rd_reg32(&jrp->rregs->inpring_avail); spin_unlock_bh(&jrp->inplock); + device_unlock(dev); return 0; }