From patchwork Sun Mar 15 23:19:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Wolokita X-Patchwork-Id: 6014411 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EC2CCBF90F for ; Sun, 15 Mar 2015 23:20:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6AB02014A for ; Sun, 15 Mar 2015 23:20:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF6292012E for ; Sun, 15 Mar 2015 23:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751793AbbCOXU0 (ORCPT ); Sun, 15 Mar 2015 19:20:26 -0400 Received: from mail-bn1bon0076.outbound.protection.outlook.com ([157.56.111.76]:55744 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751796AbbCOXU0 (ORCPT ); Sun, 15 Mar 2015 19:20:26 -0400 Received: from BN3PR0301CA0048.namprd03.prod.outlook.com (25.160.152.144) by CY1PR0301MB1257.namprd03.prod.outlook.com (25.161.212.155) with Microsoft SMTP Server (TLS) id 15.1.112.19; Sun, 15 Mar 2015 23:20:23 +0000 Received: from BN1BFFO11OLC003.protection.gbl (2a01:111:f400:7c10::1:110) by BN3PR0301CA0048.outlook.office365.com (2a01:111:e400:401e::16) with Microsoft SMTP Server (TLS) id 15.1.112.19 via Frontend Transport; Sun, 15 Mar 2015 23:20:23 +0000 Received: from nwd2mta1.analog.com (137.71.25.55) by BN1BFFO11OLC003.mail.protection.outlook.com (10.58.145.14) with Microsoft SMTP Server (TLS) id 15.1.112.13 via Frontend Transport; Sun, 15 Mar 2015 23:20:22 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.72.140]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id t2FNJf8s025343 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Sun, 15 Mar 2015 16:19:41 -0700 Received: from pelican.spd.analog.com (10.122.9.130) by NWD2HUBCAS7.ad.analog.com (10.64.72.140) with Microsoft SMTP Server (TLS) id 14.3.210.2; Sun, 15 Mar 2015 19:19:32 -0400 From: Andre Wolokita To: CC: , Andre Wolokita Subject: [PATCH] omap-rng: Change RNG_CONFIG_REG to RNG_CONTROL_REG when checking and disabling TRNG Date: Mon, 16 Mar 2015 10:19:11 +1100 Message-ID: <1426461551-14130-1-git-send-email-Andre.Wolokita@analog.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-Originating-IP: [10.122.9.130] X-EOPAttributedMessage: 0 Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=Andre.Wolokita@analog.com; gondor.apana.org.au; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:137.71.25.55; CTRY:US; IPV:NLI; EFV:NLI; BMV:1; SFV:NSPM; SFS:(10009020)(6009001)(438002)(189002)(199003)(50986999)(19580395003)(19580405001)(6806004)(229853001)(48376002)(87936001)(50466002)(110136001)(2351001)(92566002)(77156002)(62966003)(16796002)(86362001)(50226001)(77096005)(106466001)(46102003)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB1257; H:nwd2mta1.analog.com; FPR:; SPF:Pass; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1257; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5002010)(5005006); SRVR:CY1PR0301MB1257; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1257; X-Forefront-PRVS: 05168A3970 X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2015 23:20:22.2631 (UTC) X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a; Ip=[137.71.25.55]; Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB1257 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In omap4_rng_init(), a check of bit 10 of the RNG_CONFIG_REG is done to determine whether the RNG is running. This is suspicious firstly due to the use of RNG_CONTROL_ENABLE_TRNG_MASK and secondly because the same mask is written to RNG_CONTROL_REG after configuration of the FROs. Similar suspicious logic is repeated in omap4_rng_cleanup() when RNG_CONTROL_REG masked with RNG_CONTROL_ENABLE_TRNG_MASK is read, the same mask bit is cleared, and then written to RNG_CONFIG_REG. Unless the TRNG is enabled with one bit in RNG_CONTROL and disabled with another in RNG_CONFIG and these bits are mirrored in some way, I believe that the TRNG is not really shutting off. Apart from the strange logic, I have reason to suspect that the OMAP4 related code in this driver is driving an Inside Secure IP hardware RNG and strongly suspect that bit 10 of RNG_CONFIG_REG is one of the bits configuring the sampling rate of the FROs. This option is by default set to 0 and is not being set anywhere in omap-rng.c. Reading this bit during omap4_rng_init() will always return 0. It will remain 0 because ~(value of TRNG_MASK in control) will always be 0, because the TRNG is never shut off. This is of course presuming that the OMAP4 features the Inside Secure IP. I'm interested in knowing what the guys at TI think about this, as only they can confirm or deny the detailed structure of these registers. Signed-off-by: Andre Wolokita --- drivers/char/hw_random/omap-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c index ff74e5d..67151cb 100644 --- a/drivers/char/hw_random/omap-rng.c +++ b/drivers/char/hw_random/omap-rng.c @@ -262,7 +262,7 @@ static void omap4_rng_cleanup(struct omap_rng_dev *priv) val = omap_rng_read(priv, RNG_CONTROL_REG); val &= ~RNG_CONTROL_ENABLE_TRNG_MASK; - omap_rng_write(priv, RNG_CONFIG_REG, val); + omap_rng_write(priv, RNG_CONTROL_REG, val); } static irqreturn_t omap4_rng_irq(int irq, void *dev_id)