Received: by 10.223.176.5 with SMTP id f5csp2669876wra; Thu, 1 Feb 2018 04:18:13 -0800 (PST) X-Google-Smtp-Source: AH8x227Ull+gOf4qlirSJO9lZV5S9FVfYHXbMTBfZhee3g2OL4ylI0XAPSIi1tGU/GgWX3fn34Oe X-Received: by 10.98.131.200 with SMTP id h191mr36661075pfe.149.1517487493861; Thu, 01 Feb 2018 04:18:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517487493; cv=none; d=google.com; s=arc-20160816; b=y9vHEP0/WB6VyGVdMIx+zYVSV/p7seeWzFYlGD8wGZR6ZT+iUfI+J4NJ2O+gDIDPqv RiQN65zY0RC3BCW96Az6MloYnHvaKeySqfJBTuAGuv/wczG4vy/Vpylwirps1w58dZFg ++01Ar2yZwhByX+FP4/HCFoyeyJEYo7+nHi6DKPnw1+ag3+s4b4fH2vyomQIYv1a5JPP 8vho+qZiDxLPKkjb3KbVY2ng1179haH4UfQ+7Cr085v90ajHvdZ85AARSi1l6Ts57oV6 ndi2oP/18cUObm++WWlCKrvf2/w2exhbFZwZCLD3VcXIMuSbAGdFxpPwrOITQlIDRF9I fN0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=i59E69iGhg+RbxOz6eTRy/IjhQsyDKdywXn/N9UM4ts=; b=l9lBeyVoOjOzcMFrCHgKExCXuxxlDngTuZ/kjTWd7jHEL6WvzkXtjFuZ3wCpNYr7mW v6vAAHJn/n1AoHL200AuT8Du6kChUbMu2PpjW6rmRmUE2rPtOTV6ojXYbIlLiv6z5ziY 3CK4lzrttGcSu6DsskjUUZptrG/Z8rGU3FfzpoiCmGWGS/8fcvm+jJriUEQcu2ZRZolR 7GgwjXuVm3KAdSpfrFTPq4ryme2LVeOROa+t55OBuEqeJ9oKU8poXPXOqNQ8+I+rGnSP HYN+nXzygRlxFiittL5T4UvaPapS9GoauxooQS15GX4f2v0kZxM66JO8LvjWSxYqyY0z NZLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=bZumMtnz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a35-v6si3795775pli.173.2018.02.01.04.17.58; Thu, 01 Feb 2018 04:18:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=bZumMtnz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752434AbeBAMQ6 (ORCPT + 99 others); Thu, 1 Feb 2018 07:16:58 -0500 Received: from mail-he1eur01on0058.outbound.protection.outlook.com ([104.47.0.58]:44730 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752237AbeBAMQ4 (ORCPT ); Thu, 1 Feb 2018 07:16:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=i59E69iGhg+RbxOz6eTRy/IjhQsyDKdywXn/N9UM4ts=; b=bZumMtnzaVw3gwkF8UQKHoo7FClP+jgfQ6qglZxKv4z++60cz4RJd/0kA0z1os/SeW3lE5Ai4nuIJVbGByZ1D5d/8FjvkhaVYLRd+0T52XXNDyuX0UCe4yh7v3koSIKao9H/lwC2msi93SKt1mqsTErnfi0m3ifd+9xpv9ou3K4= Received: from VI1PR0402MB3342.eurprd04.prod.outlook.com (52.134.8.142) by VI1PR0402MB3390.eurprd04.prod.outlook.com (52.134.1.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Thu, 1 Feb 2018 12:16:52 +0000 Received: from VI1PR0402MB3342.eurprd04.prod.outlook.com ([fe80::3507:8836:aae3:375e]) by VI1PR0402MB3342.eurprd04.prod.outlook.com ([fe80::3507:8836:aae3:375e%13]) with mapi id 15.20.0444.016; Thu, 1 Feb 2018 12:16:51 +0000 From: =?iso-8859-2?Q?Horia_Geant=E3?= To: Bryan O'Donoghue , Aymen Sghaier , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Fabio Estevam , Peng Fan , "davem@davemloft.net" , "lukas.auer@aisec.fraunhofer.de" , "rui.silva@linaro.org" , "ryan.harkin@linaro.org" , Herbert Xu Subject: Re: [PATCH v3 2/5] crypto: caam: Fix endless loop when RNG is already initialized Thread-Topic: [PATCH v3 2/5] crypto: caam: Fix endless loop when RNG is already initialized Thread-Index: AQHTmjdOwMiIynBKwEGhPiBJHBZpZw== Date: Thu, 1 Feb 2018 12:16:51 +0000 Message-ID: References: <1517364040-27607-1-git-send-email-pure.logic@nexus-software.ie> <1517364040-27607-3-git-send-email-pure.logic@nexus-software.ie> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=horia.geanta@nxp.com; x-originating-ip: [192.88.166.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR0402MB3390;7:oYG0lTAtDeZMrFvLG/jCyiCvEXd1g1XZyS8LLACW3SL0SY6ZCCO04b3Iz/8Ttdpw+YFF2788VZjw9dy4QBnxMKrYeItP75BnNB7RNb3s0pTmyG8rqmTCS904YVMBF1euMg0pV1ITlDq5XB0pIonbzdJVEnoi1dymOdxnRzD3rwXKL9SfGf+WEMZu3ilCjHjiOsSuvT6+Qw2jxiiasTFnvx2Y6znV/KQlPthXhg9l1qJ+8gMd0xSSVlXCfuxNyIz2 x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10009020)(376002)(396003)(39380400002)(39860400002)(366004)(346002)(199004)(189003)(7736002)(316002)(81166006)(6246003)(86362001)(74316002)(305945005)(478600001)(4326008)(53936002)(9686003)(25786009)(55016002)(14454004)(2501003)(97736004)(66066001)(2900100001)(3846002)(6116002)(54906003)(2201001)(5250100002)(110136005)(106356001)(8936002)(3280700002)(2906002)(68736007)(99286004)(53546011)(102836004)(6436002)(5660300001)(7696005)(33656002)(76176011)(186003)(3660700001)(26005)(8676002)(105586002)(81156014)(6506007)(229853002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0402MB3390;H:VI1PR0402MB3342.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 61335b6b-727f-482e-b332-08d5696dacea x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020);SRVR:VI1PR0402MB3390; x-ms-traffictypediagnostic: VI1PR0402MB3390: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231101)(2400082)(944501161)(93006095)(93001095)(6055026)(6041288)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:VI1PR0402MB3390;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0402MB3390; x-forefront-prvs: 0570F1F193 received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 7mYlUtTExGFriJpGEbQ64M6cTTD2aJ+5lL+5lVq7vC/CZ+S1hQDfSlqnm99yupA8Zcc0u7RZdozW2H6kXlJ/AQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61335b6b-727f-482e-b332-08d5696dacea X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Feb 2018 12:16:51.5113 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3390 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/31/2018 4:00 AM, Bryan O'Donoghue wrote:=0A= > commit 1005bccd7a4a ("crypto: caam - enable instantiation of all RNG4 sta= te=0A= > handles") introduces a control when incrementing ent_delay which contains= =0A= > the following comment above it:=0A= > =0A= > /*=0A= > * If either SH were instantiated by somebody else=0A= > * (e.g. u-boot) then it is assumed that the entropy=0A= > * parameters are properly set and thus the function=0A= > * setting these (kick_trng(...)) is skipped.=0A= > * Also, if a handle was instantiated, do not change=0A= > * the TRNG parameters.=0A= > */=0A= > =0A= > This is a problem observed when sec_init() has been run in u-boot and=0A= > and TrustZone is enabled. We can fix this by instantiating all rng state= =0A= > handles in u-boot but, on the Kernel side we should ensure that this=0A= > non-terminating path is dealt with.=0A= > =0A= > Fixes: 1005bccd7a4a ("crypto: caam - enable instantiation of all RNG4 sta= te=0A= > handles")=0A= > =0A= > Reported-by: Ryan Harkin =0A= > Cc: "Horia Geant=E3" =0A= > Cc: Aymen Sghaier =0A= > Cc: Fabio Estevam =0A= > Cc: Peng Fan =0A= > Cc: "David S. Miller" =0A= > Cc: Lukas Auer =0A= > Cc: # 4.12+=0A= > Signed-off-by: Bryan O'Donoghue =0A= > ---=0A= > drivers/crypto/caam/ctrl.c | 3 +++=0A= > 1 file changed, 3 insertions(+)=0A= > =0A= > diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c=0A= > index 98986d3..0a1e96b 100644=0A= > --- a/drivers/crypto/caam/ctrl.c=0A= > +++ b/drivers/crypto/caam/ctrl.c=0A= > @@ -704,7 +704,10 @@ static int caam_probe(struct platform_device *pdev)= =0A= > ent_delay);=0A= > kick_trng(pdev, ent_delay);=0A= > ent_delay +=3D 400;=0A= > + } else if (ctrlpriv->rng4_sh_init && inst_handles) {=0A= > + ent_delay +=3D 400;=0A= > }=0A= If both RNG state handles are initialized before kernel runs, then=0A= instantiate_rng() should be a no-op and return 0, which is enough to exit t= he=0A= loop: while ((ret =3D=3D -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX))=0A= =0A= If the loop cannot exit based on value of "ret" !=3D -EAGAIN, then it means= =0A= caam_probe() will eventually fail due to ret =3D=3D -EAGAIN:=0A= if (ret) {=0A= dev_err(dev, "failed to instantiate RNG");=0A= goto caam_remove;=0A= }=0A= =0A= Please provide more details, so that the root cause is found and fixed.=0A= For e.g. what is the value of RDSTA (RNG DRNG Status register @0x6C0):=0A= -before & after u-boot initializes RNG=0A= -as seen by kernel during caam_probe()=0A= Also provide related error messages displayed during boot.=0A= =0A= Thanks,=0A= Horia=0A=