From patchwork Fri Jan 26 12:19:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 125951 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp294744ljd; Fri, 26 Jan 2018 04:20:47 -0800 (PST) X-Google-Smtp-Source: AH8x227VlsSE4RG+/qK+YJ6tfB1c9ad82A6vZGchIU9hGbqkqzOJ5BQunOjOnvwUv8KfHFdmqPoP X-Received: by 10.80.241.152 with SMTP id x24mr33661290edl.59.1516969247219; Fri, 26 Jan 2018 04:20:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516969247; cv=none; d=google.com; s=arc-20160816; b=B6UwcUHOCayZso6A3NSJeQYY/vUCfKfA73F9CKtbLH8pm6Tc5BVCKF/AGhO4QAHHMY 5a55jub/mxjWZLei+wiaGnrgJYUSGd2mCwQdsbhcFNh8aslLijIGpg2iB+fNFguiN2bX IbbnxVYmli6SAii6uRqMdBPOQVR8htr1oTbTNk04LhsXqlPT6nro22qL0P9R7JMfRvKI izP3uCOx8cg+EzZa3R3FUjQqp4dnZmdiyQSZcZt3gZhuRBy+MnrZUCl+0j+u44BtI/ze n/Tqr+LE+1m8JzhLDAEw2WLt8SLPKVAgfAR1CRM4+SMK9h4FI5lV9FWaLpRNvd1TCKd2 tTEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=ESb42AMR2CA7QFJ1E3josv6VS+cDVqLvWp2LTPpMmDA=; b=wpuTcCG/MMNfxzQRPO6CBPBen2oAbO8EgO7ohItVv9teXBzAq/P0x3l01G8R0CP8WM L+8OaPGel+P73ax//UCmniaUEeu+zcE7Ql0JUbOQCz5VylGcXTcYpxaGNkBeJOTv7REm L2cPJF9DjmD8AxpeUAJeE25hqfDUrveEL6R31y+YEYFawhaoSJywMHgiP4b6V3YcXQHb CwNrua9e6Ofkyv0a3fQj+3mmlCuFfTqnuqdPPUN3FdeYPQKdZ3qQj5+Obbxwne7MaIQ9 kNtNt6cJxF8iPsJm9OdmVnWF3yvLe3/OJCcqMr4y86y/ZT8YGWIwL5jy2ZGGdEe8bnTj 5xUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=OlpwBtLd; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id z89si3881011ede.362.2018.01.26.04.20.46; Fri, 26 Jan 2018 04:20:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=OlpwBtLd; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id D2C48C224EA; Fri, 26 Jan 2018 12:19:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 33BBAC224BD; Fri, 26 Jan 2018 12:19:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 586B1C224D5; Fri, 26 Jan 2018 12:19:17 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id F0A61C224DC for ; Fri, 26 Jan 2018 12:19:16 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id f3so20865811wmc.1 for ; Fri, 26 Jan 2018 04:19:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4dNx/TMrG7D8yi9QXj/S16kmmumBLJq2+LV+GS99h2c=; b=OlpwBtLdutvlhIG6axMfT+7urWMcv3coJryKhpjpakJIONw4GZsNz1a+v9KbPoCBvH cDdy2wEWaRoDxfFOgDOBxhobVhcM0UGXBJ9S9L55DIxV/DD67ne6gGjMBhJmkk4/2FVa fYX/ukd8/AfY0zhC0oNAjuDSVREV8M2b7/ftc= 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; bh=4dNx/TMrG7D8yi9QXj/S16kmmumBLJq2+LV+GS99h2c=; b=g/ffE9LEEeL9xINL/AnkYp7dwhHcAs0BeHWkfOSO7BCB3Id4ny4Fc42SR3+gZ/7sB/ rULOwRUSxPP62xtuqV+tHfkA29ahn6fja5VQabkQ+B3O6KOPCuyhZntFvl8720cB9kcj QAUGFAvoVZ3z6vki0zQ0BkrGYkGAkw99OA0gh9k301w0sFLdEaw848pTQv4ojncP1kNd HKqJzlRRtzYDsKR4Y7ELwaFj66d1Fi89pN5Ubw5z6w4fY9EhSjGnJWR3wv8Z2/25VoPh Av6fjZY6bcfI5b9GsP6d2jquveNK/9ot71hVPGYP8QO51o+hnuk9yniN5y9mnAD8mDYR YnGA== X-Gm-Message-State: AKwxytcZtIbjOLyqySgdrPXWp6LmLfZKMJDArXv5mZpSbfAYUqahQPMw S3OQFIOSxsJcKR0WQZiED+KfYNKr7Iw= X-Received: by 10.80.186.202 with SMTP id x68mr24390990ede.264.1516969156449; Fri, 26 Jan 2018 04:19:16 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id o26sm2217427edi.18.2018.01.26.04.19.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jan 2018 04:19:15 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 26 Jan 2018 12:19:12 +0000 Message-Id: <1516969153-19053-2-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516969153-19053-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516969153-19053-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Aneesh Bansal , fabio.estevam@nxp.com, Ruchika Gupta Subject: [U-Boot] [PATCH v3 1/2] drivers/crypto/fsl: assign job-rings to non-TrustZone X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" After enabling TrustZone various parts of the CAAM silicon become inaccessible to non TrustZone contexts. The job-ring registers are designed to allow non TrustZone contexts like Linux to still submit jobs to CAAM even after TrustZone has been enabled. The default job-ring permissions after the BootROM look like this for job-ring zero. ms=0x00008001 ls=0x00008001 The MS field is JRaMIDR_MS (job ring MID most significant). Referring to "Security Reference Manual for i.MX 7Dual and 7Solo Applications Processors, Rev. 0, 03/2017" section 8.10.4 we see that JROWN_NS controls whether or not a job-ring is accessible from non TrustZone. Bit 15 (TrustZone) is the logical inverse of bit 3 hence the above value of 0x8001 shows that JROWN_NS=0 and TrustZone=1. Clearly then as soon as TrustZone becomes active the job-ring registers are no longer accessible from Linux, which is not what we want. This patch explicitly sets all job-ring registers to JROWN_NS=1 (non TrustZone) by default and to the Non-Secure MID 001. Both settings are required to successfully assign a job-ring to non-secure mode. If a piece of TrustZone firmware requires ownership of job-ring registers it can unset the JROWN_NS bit itself. This patch in conjunction with a modification of the Linux kernel to skip HWRNG initialisation makes CAAM usable to Linux with TrustZone enabled. Signed-off-by: Bryan O'Donoghue Cc: Fabio Estevam Cc: Peng Fan Cc: Alex Porosanu Cc: Ruchika Gupta Cc: Aneesh Bansal Link: https://github.com/OP-TEE/optee_os/issues/1408 Link: https://tinyurl.com/yam5gv9a Tested-by: Lukas Auer --- drivers/crypto/fsl/jr.c | 9 +++++++++ drivers/crypto/fsl/jr.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c index a6dad01..34bd070 100644 --- a/drivers/crypto/fsl/jr.c +++ b/drivers/crypto/fsl/jr.c @@ -579,6 +579,8 @@ int sec_init_idx(uint8_t sec_idx) { ccsr_sec_t *sec = (void *)SEC_ADDR(sec_idx); uint32_t mcr = sec_in32(&sec->mcfgr); + uint32_t jrown_ns; + int i; int ret = 0; #ifdef CONFIG_FSL_CORENET @@ -634,6 +636,13 @@ int sec_init_idx(uint8_t sec_idx) #endif #endif + /* Set ownership of job rings to non-TrustZone mode by default */ + for (i = 0; i < ARRAY_SIZE(sec->jrliodnr); i++) { + jrown_ns = sec_in32(&sec->jrliodnr[i].ms); + jrown_ns |= JROWN_NS | JRMID_NS; + sec_out32(&sec->jrliodnr[i].ms, jrown_ns); + } + ret = jr_init(sec_idx); if (ret < 0) { printf("SEC initialization failed\n"); diff --git a/drivers/crypto/fsl/jr.h b/drivers/crypto/fsl/jr.h index f546226..ef515e7 100644 --- a/drivers/crypto/fsl/jr.h +++ b/drivers/crypto/fsl/jr.h @@ -34,6 +34,8 @@ #define JRNSLIODN_MASK 0x0fff0000 #define JRSLIODN_SHIFT 0 #define JRSLIODN_MASK 0x00000fff +#define JROWN_NS 0x00000008 +#define JRMID_NS 0x00000001 #define JQ_DEQ_ERR -1 #define JQ_DEQ_TO_ERR -2