From patchwork Mon Jan 27 16:56:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 198169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E161C35248 for ; Mon, 27 Jan 2020 16:57:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 302B4214AF for ; Mon, 27 Jan 2020 16:57:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q1Mtlft6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbgA0Q5k (ORCPT ); Mon, 27 Jan 2020 11:57:40 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36305 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726428AbgA0Q5I (ORCPT ); Mon, 27 Jan 2020 11:57:08 -0500 Received: by mail-pl1-f196.google.com with SMTP id a6so3964531plm.3; Mon, 27 Jan 2020 08:57:08 -0800 (PST) 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=TcjeClmRH5R/km2Nzp0idBoWoVhmeZ5+erKgXpUxBBo=; b=Q1Mtlft6a4GSlcQtk4C4LnJ99CA+QFsHXr5JBozHH5iFzbtVMefOlsAH5dmjNQdK4o PQadM0OxOiJXWgs9yy0RXFeYcGfDroruZDrkxtR8K5Kio5OANuPCeu+ph8Foq/B+osG5 TWVeDkU9d2CsVaX14ZAmUzt39n4uCsnWKQ5dTxfXVWQeHNq5GRy6XlvH2nal1g2dDMFz OvbwJbfkfMY1QWXA/q5juX8BBRO71y7WiFnUl3tcUbu0Fj/09Mq/5y7yv7q2oX+jmYS4 6JXpFz45+UpQeq70Ltgz8ZmyBWFf1vYwLx6ymWRhe5aXXMsxNWaL7FWQc9sOrLkcRG3y WukA== 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=TcjeClmRH5R/km2Nzp0idBoWoVhmeZ5+erKgXpUxBBo=; b=Sq5513e64hEmvWCqd7aUT7LMupt0MtNCLAvofIdmIgXWFbvaKEBxiONp2R14DSiAEG eFHB5ksCJGayGA+Y6BvaOT8rCYG/944yvmF5C57w2kDLs7yzOVpT4tUSI6VwH1Z00Rh/ bYttsjXxM4GKW6D3TtfFKDra09Z0yEdzI7QLCQc5H5Sj1Ob5p1JqBnZEOe9o+X2aVAgO um8uJVACGrvgbfkMvvGG2tVLPLlF0+6/J5LjTsZqkQnPlJTO90Wc7UUfSeu79gzcC1Z1 wV0ym8WsA0VZABtZn4+DOxyZJxvk6tYHvX5nIh9XrxsUW2Cjbbba5siwoLrX+E/dvban ah3g== X-Gm-Message-State: APjAAAW3LIOp+fqTUFEys7FDkAmVYOnPwXU+1ycjz09hb8LgvRyV3vFA ujTtcaWb3ir7cHQ2kqxCuz4iB2aO X-Google-Smtp-Source: APXvYqz+yLuw5NkGsIKVpT98QYpSDv6QGN953xt08HGy0A3KNseQFgaApXkUDTUi+1dDEoT/5aVYVw== X-Received: by 2002:a17:902:8495:: with SMTP id c21mr18782308plo.279.1580144227787; Mon, 27 Jan 2020 08:57:07 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id u23sm16368642pfm.29.2020.01.27.08.57.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 08:57:06 -0800 (PST) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant?= =?utf-8?b?xIM=?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v7 2/9] crypto: caam - use struct hwrng's .init for initialization Date: Mon, 27 Jan 2020 08:56:39 -0800 Message-Id: <20200127165646.19806-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200127165646.19806-1-andrew.smirnov@gmail.com> References: <20200127165646.19806-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 Make caamrng code a bit more symmetric by moving initialization code to .init hook of struct hwrng. 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 Cc: linux-imx@nxp.com --- drivers/crypto/caam/caamrng.c | 47 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index e8baacaabe07..1ce7fbd29e85 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -256,6 +256,7 @@ static void caam_cleanup(struct hwrng *rng) } rng_unmap_ctx(rng_ctx); + caam_jr_free(rng_ctx->jrdev); } static int caam_init_buf(struct caam_rng_ctx *ctx, int buf_id) @@ -274,28 +275,43 @@ 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(struct hwrng *rng) { + struct caam_rng_ctx *ctx = rng_ctx; int err; - ctx->jrdev = jrdev; + ctx->jrdev = caam_jr_alloc(); + err = PTR_ERR_OR_ZERO(ctx->jrdev); + if (err) { + pr_err("Job Ring Device allocation for transform failed\n"); + return err; + } err = rng_create_sh_desc(ctx); if (err) - return err; + goto free_jrdev; ctx->current_buf = 0; ctx->cur_buf_idx = 0; err = caam_init_buf(ctx, 0); if (err) - return err; + goto free_jrdev; + + err = caam_init_buf(ctx, 1); + if (err) + goto free_jrdev; - return caam_init_buf(ctx, 1); + return 0; + +free_jrdev: + caam_jr_free(ctx->jrdev); + return err; } static struct hwrng caam_rng = { .name = "rng-caam", + .init = caam_init, .cleanup = caam_cleanup, .read = caam_read, }; @@ -305,14 +321,12 @@ void caam_rng_exit(void) if (!init_done) return; - caam_jr_free(rng_ctx->jrdev); hwrng_unregister(&caam_rng); kfree(rng_ctx); } int caam_rng_init(struct device *ctrldev) { - struct device *dev; u32 rng_inst; struct caam_drv_private *priv = dev_get_drvdata(ctrldev); int err; @@ -328,21 +342,11 @@ int caam_rng_init(struct device *ctrldev) if (!rng_inst) return 0; - 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; - } - err = caam_init_rng(rng_ctx, dev); - if (err) - goto free_rng_ctx; + if (!rng_ctx) + return -ENOMEM; - dev_info(dev, "registering rng-caam\n"); + dev_info(ctrldev, "registering rng-caam\n"); err = hwrng_register(&caam_rng); if (!err) { @@ -350,9 +354,6 @@ int caam_rng_init(struct device *ctrldev) return err; } -free_rng_ctx: kfree(rng_ctx); -free_caam_alloc: - caam_jr_free(dev); return err; } From patchwork Mon Jan 27 16:56:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 198170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 684EAC33CB7 for ; Mon, 27 Jan 2020 16:57:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D865214D8 for ; Mon, 27 Jan 2020 16:57:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rkeYz8H9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbgA0Q5M (ORCPT ); Mon, 27 Jan 2020 11:57:12 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:56073 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725845AbgA0Q5K (ORCPT ); Mon, 27 Jan 2020 11:57:10 -0500 Received: by mail-pj1-f65.google.com with SMTP id d5so3172128pjz.5; Mon, 27 Jan 2020 08:57:10 -0800 (PST) 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=y820Lp2M/a5OhA2vLH1uw/txeBMDoNX2HSIoVGLcKRY=; b=rkeYz8H9ByzmIZ/+BUIIXj3MuldJXN0xDafK/yD7IaJlWrNmw0ax8iEbv/d7yHS3UU JULrp1Z27UYjL0LlrPm3XT5fgVmhwrAwu4C0GPHWBIsF8rlBpjB+2xVF6A3U3YzZwdhf yqLNmDBWFdcrZOMZH6yZkbkiFziA5X5n542IlkcVPZJV7sj0zWaQh/6hDugDPT6Ifv0e 6jWh6LaH1A4hQhRtQmVbgvoyYobC4/3Krd0Fmy9pUBMKZ+nWax+caO4dRo3zHAoQS2dz ai+7XRy34bgJGTc92nIgANvToQ40RTuQZXnfEwk4ulg8SD26gRL3li0Z1V5ataFLtd2A TfCQ== 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=y820Lp2M/a5OhA2vLH1uw/txeBMDoNX2HSIoVGLcKRY=; b=gpVu61cxb7vpNIi9rByLkVsj8wthAc3wq6glpmG7bhDyHxvHGEp/SxOvcUvtHC0enj YZPqEOcfiwM5b8iXCpVOgMtfqBPeIqqbuGPItWL3PGqkgA038gmr4trjMAFnJyeB62O+ cYN41mtSNB6BFcfZzpp3Alg7eE+/fyw6lCTLNq8faValagBpmXp2ZaiC9E3sR6IBRYUW CKCL8F6qoupda51aETUvNgotx8hMEhCrTqv1e2U8ht2A2QAT6IOqden2kqbtD9i5SXER Yf4jCUAlb5QctgaiHV0rbHoDLw3tcUaLSUoECne2HbuZPRdu/DEPOOKDA2N/ugBsFP5s 3TOg== X-Gm-Message-State: APjAAAW7rEClKK45DIkz1PMpGhY5RUub/GHXv1TK47XlxXbKK1gom5sh xGPXZomrOBvhqVV/2oU8uZiDnf/U X-Google-Smtp-Source: APXvYqxTj85P9NypyXFitpnioyZBt5er1aZDrGKs3oXQUgNJpVopnFxNW3w1k7b7yxVZxIpqhzKxZQ== X-Received: by 2002:a17:902:8341:: with SMTP id z1mr18050363pln.178.1580144229226; Mon, 27 Jan 2020 08:57:09 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id u23sm16368642pfm.29.2020.01.27.08.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 08:57:08 -0800 (PST) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant?= =?utf-8?b?xIM=?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v7 3/9] crypto: caam - use devm_kzalloc to allocate JR data Date: Mon, 27 Jan 2020 08:56:40 -0800 Message-Id: <20200127165646.19806-4-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200127165646.19806-1-andrew.smirnov@gmail.com> References: <20200127165646.19806-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 devm_kzalloc() to allocate JR data in order to make sure that it is initialized consistently every time. 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 Cc: linux-imx@nxp.com --- drivers/crypto/caam/jr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index fc97cde27059..a627de959b1e 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -505,7 +505,7 @@ static int caam_jr_probe(struct platform_device *pdev) int error; jrdev = &pdev->dev; - jrpriv = devm_kmalloc(jrdev, sizeof(*jrpriv), GFP_KERNEL); + jrpriv = devm_kzalloc(jrdev, sizeof(*jrpriv), GFP_KERNEL); if (!jrpriv) return -ENOMEM; From patchwork Mon Jan 27 16:56:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 198171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89BB2C33CB1 for ; Mon, 27 Jan 2020 16:57:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F458214D8 for ; Mon, 27 Jan 2020 16:57:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gYZ2iu3V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725985AbgA0Q52 (ORCPT ); Mon, 27 Jan 2020 11:57:28 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39170 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbgA0Q5Q (ORCPT ); Mon, 27 Jan 2020 11:57:16 -0500 Received: by mail-pf1-f193.google.com with SMTP id q10so5171556pfs.6; Mon, 27 Jan 2020 08:57:16 -0800 (PST) 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=Lq9n6SOnc0hSj1FFyZM2mcFj9cA359i3RcrvKhosWgE=; b=gYZ2iu3VsXA3qiwG2OYbTYh/yKOssH7yYlaE6Wjtj7IFjrOE37+Hz/xxtBTpSNbdf0 lrx9ft3PWOtp4/KMoEQX/mv130d6cl/B7/fXd/AS6qz10YhCnd22LFtPTtRyViaC0ac3 OH2511wNBKOxX4lzExyThiPV8ierATtYRFwC1zkBl9SoCk9If32piaP96WJETZsBlwGX /kLkoW59PRSbFF6GxPWkNZ82gIV6zXvKZbIDia+kq1Hu2yDhnYTIMbWGSv2viWgF6x7F 4i8MIyQlpYQM5OXdX4tBZCGnLYwG2lGoXCQ8lf8ufqeYcnhsLKeGIoDvjVFL5HRUPQEi 2dyA== 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=Lq9n6SOnc0hSj1FFyZM2mcFj9cA359i3RcrvKhosWgE=; b=BhYyG6a5+pTm1BnjFoWgySMQ3j2yD+aRRKadMyib3/ITZvGDmRsCpRZqZT/1PcLnrP AA0vu19TZtuzIzfeACH0P+bb5a3j/NWWK4YqnonKfe4Uss81yQxfTSA8g5FJjV++CApu kYpITgZYu8WORjmAJaLlrS6SO9mSHbUB05JP/fhmjll6vGO9JhT98NwznCDSs4lsOoWn 2Ba5LDNhQ2xQOvl5186fU+Ug18ATvLontDzc3ACfhZWY9+Wf8crhGREFh9rs8IVO12m6 mmWsFUqOr/2MsCvgT3zGRY88CVSxoO3rWwPkvUEqbATSdMrw9AKBhXS0+D5J6CzHD7Ex LRqA== X-Gm-Message-State: APjAAAVRuxwmB6nMo68Ffuih7q+NwLuwlDeyiNGjE8R3uehcel3Mxn31 rn2owhdZ8PZk/dYcwXLlTmdCXFO/ X-Google-Smtp-Source: APXvYqyLD95AlCbgEqM+4v6Kr8vCV6GDxYDLssTIspHzAHcPGuWACLzLPVklCIAoeReFVetQT0s/4g== X-Received: by 2002:a63:30c:: with SMTP id 12mr20072591pgd.276.1580144235264; Mon, 27 Jan 2020 08:57:15 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id u23sm16368642pfm.29.2020.01.27.08.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 08:57:14 -0800 (PST) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Aymen Sghaier , Vipul Kumar , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant?= =?utf-8?b?xIM=?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v7 7/9] crypto: caam - invalidate entropy register during RNG initialization Date: Mon, 27 Jan 2020 08:56:44 -0800 Message-Id: <20200127165646.19806-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200127165646.19806-1-andrew.smirnov@gmail.com> References: <20200127165646.19806-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 make sure that we always use non-stale entropy data, change the code to invalidate entropy register during RNG initialization. Signed-off-by: Aymen Sghaier Signed-off-by: Vipul Kumar [andrew.smirnov@gmail.com ported to upstream kernel, rewrote commit msg] 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 Cc: linux-imx@nxp.com --- drivers/crypto/caam/ctrl.c | 11 ++++++++--- drivers/crypto/caam/regs.h | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index a11c13a89ef8..bcbc832b208e 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -339,8 +339,12 @@ static void kick_trng(struct platform_device *pdev, int ent_delay) ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl; r4tst = &ctrl->r4tst[0]; - /* put RNG4 into program mode */ - clrsetbits_32(&r4tst->rtmctl, 0, RTMCTL_PRGM); + /* + * Setting both RTMCTL:PRGM and RTMCTL:TRNG_ACC causes TRNG to + * properly invalidate the entropy in the entropy register and + * force re-generation. + */ + clrsetbits_32(&r4tst->rtmctl, 0, RTMCTL_PRGM | RTMCTL_ACC); /* * Performance-wise, it does not make sense to @@ -370,7 +374,8 @@ static void kick_trng(struct platform_device *pdev, int ent_delay) * select raw sampling in both entropy shifter * and statistical checker; ; put RNG4 into run mode */ - clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC); + clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM | RTMCTL_ACC, + RTMCTL_SAMP_MODE_RAW_ES_SC); } static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl) diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h index 05127b70527d..c191e8fd0fa7 100644 --- a/drivers/crypto/caam/regs.h +++ b/drivers/crypto/caam/regs.h @@ -487,7 +487,8 @@ struct rngtst { /* RNG4 TRNG test registers */ struct rng4tst { -#define RTMCTL_PRGM 0x00010000 /* 1 -> program mode, 0 -> run mode */ +#define RTMCTL_ACC BIT(5) /* TRNG access mode */ +#define RTMCTL_PRGM BIT(16) /* 1 -> program mode, 0 -> run mode */ #define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_SC 0 /* use von Neumann data in both entropy shifter and statistical checker */ From patchwork Mon Jan 27 16:56:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 198172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51333C2D0DB for ; Mon, 27 Jan 2020 16:57:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 249A6214AF for ; Mon, 27 Jan 2020 16:57:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V6vcvtVN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727296AbgA0Q5T (ORCPT ); Mon, 27 Jan 2020 11:57:19 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39432 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbgA0Q5T (ORCPT ); Mon, 27 Jan 2020 11:57:19 -0500 Received: by mail-pl1-f196.google.com with SMTP id g6so3952301plp.6; Mon, 27 Jan 2020 08:57:19 -0800 (PST) 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=gBX0rF+FM22EQWDgrCOhfsho6eL33Pl7f2z/Wb05rxk=; b=V6vcvtVNGL1dkzbEEu5edrSulsfvxMusZPHTKrlqP1YctbYITDoWl4FcIrt3OagBqs cRz9R1ag1kwmkqpe88XQu0chXEwdmZGBiBynw97aoo/7IkN8V2LQuOaByn/X97MVJ/mv yhGQyesxee/3u2b5zTUzfQN4uUxB8n7zkuJClVUwBLJyViiBoq+k1qy+G2VeGjtk0sbb aHqv+oOXHfidda6SJIuj9AOMuG0DywQMxZyrfREGxOFh0oYkoiuxdWUzst7DjKzXxxVY JLHmlZWJ2t5WGJrnKJvbppOXHaZUXylNb6yE7JznH+wOgURycPrjWfeZQXsI2+3xqf5n 9fwg== 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=gBX0rF+FM22EQWDgrCOhfsho6eL33Pl7f2z/Wb05rxk=; b=fGetXjQ26hD0D3O848VckdKaOTWVLauqsFBwss5XWR7wCOm6QYcvo8949y7NoJ29f7 dU8MOgDDrn4WrIHDgNORtmlhfqONtWadnCtJgEWAW35aX6wShvvhNlujeTADXm1J6usn PrDJ/sXc9PEXLl3p/6/vXGPR7QUTaL/JWmt1T0XI5EfNDBVvCOyc/bTGr6Uxl7B4ezo1 LcQaIH1mJzUpcvhiiVh9b+Vuz21wXjiPsDSunfiaDNCF+ujyBnwgfAag7kj0ZMBsh4AN 6GPZXdfsocQ7FrZ3bPYLHWVnHKDpTcljVIvMS+CvddR0Po2sUxJeSS1kp2aUshWvL8Jv ZLXw== X-Gm-Message-State: APjAAAU7VmaviQdEAxKxZTO6vAgZCI1vmgUZvjPsQ2Fs9n2Dx7wXftA3 2rS/eH42vKFHdqRQh6R/zWmD/Aig X-Google-Smtp-Source: APXvYqy4pV0aoh/I0RzG7st8QuqEadZ9OoF6E4Td9jxqCEaH3yBPrehQHMfoI9YELup/g23o06vIdA== X-Received: by 2002:a17:902:7d8c:: with SMTP id a12mr17548169plm.47.1580144238429; Mon, 27 Jan 2020 08:57:18 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id u23sm16368642pfm.29.2020.01.27.08.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 08:57:17 -0800 (PST) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Healy , Lucas Stach , =?utf-8?q?Horia_Geant?= =?utf-8?b?xIM=?= , Herbert Xu , Iuliana Prodan , linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v7 9/9] crypto: caam - limit single JD RNG output to maximum of 16 bytes Date: Mon, 27 Jan 2020 08:56:46 -0800 Message-Id: <20200127165646.19806-10-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200127165646.19806-1-andrew.smirnov@gmail.com> References: <20200127165646.19806-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 follow recommendation in SP800-90C (section "9.4 The Oversampling-NRBG Construction") limit the output of "generate" JD submitted to CAAM. See https://lore.kernel.org/linux-crypto/VI1PR0402MB3485EF10976A4A69F90E5B0F98580@VI1PR0402MB3485.eurprd04.prod.outlook.com/ for more details. This change should make CAAM's hwrng driver good enough to have 1024 quality rating. 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 Cc: linux-imx@nxp.com --- drivers/crypto/caam/caamrng.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c index 62f3a69ae837..c0981fce68b7 100644 --- a/drivers/crypto/caam/caamrng.c +++ b/drivers/crypto/caam/caamrng.c @@ -23,9 +23,9 @@ #include "error.h" /* length of descriptors */ -#define CAAM_RNG_MAX_FIFO_STORE_SIZE U16_MAX +#define CAAM_RNG_MAX_FIFO_STORE_SIZE 16 -#define CAAM_RNG_FIFO_LEN SZ_32K /* Must be a multiple of 2 */ +#define CAAM_RNG_FIFO_LEN 64 /* Must be a multiple of 2 */ /* * See caam_init_desc() @@ -128,7 +128,7 @@ static void caam_rng_fill_async(struct caam_rng_ctx *ctx) sg_init_table(sg, ARRAY_SIZE(sg)); nents = kfifo_dma_in_prepare(&ctx->fifo, sg, ARRAY_SIZE(sg), - CAAM_RNG_FIFO_LEN); + CAAM_RNG_MAX_FIFO_STORE_SIZE); if (!nents) return; @@ -246,6 +246,7 @@ int caam_rng_init(struct device *ctrldev) ctx->rng.init = caam_init; ctx->rng.cleanup = caam_cleanup; ctx->rng.read = caam_read; + ctx->rng.quality = 1024; dev_info(ctrldev, "registering rng-caam\n");