From patchwork Thu Sep 28 18:04:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9976639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 26CD26034B for ; Thu, 28 Sep 2017 18:09:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17F93201F5 for ; Thu, 28 Sep 2017 18:09:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CB5D262AE; Thu, 28 Sep 2017 18:09:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 82B7B201F5 for ; Thu, 28 Sep 2017 18:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W936d7AmBvFZPVK2/f9VOJAD1mO9BoKda59YYqyQreY=; b=doXe9vulw1ZIHb ITJSIFabWgq5KvgQvVgZolV9C/NWMaIrh79FQaQzmU2/RWu1cDDreVREAgVvMBN5y7W/K3OZkEU4G HJdbGsgzMmoRjlO0ggB6saZib6AJLs9QVBc8lsbSZJ2UiXLy+5vgPhCu+n5oTD4Nd7s2rf/YCEvix WAwi3FCTnMCR2z3MBxmWiGEAnE1rhP1Vzo4g0ZjWzciM72vRu8w3bZJWbNtPm5GTzFLAUsRSuhrBG rKiszSROiw/5IihPMReIqdsZbYUjmPBrf41/XpTpO36eoiPvsdYy9hj19JZD01JXgmS8owafGjr1o jaA222U33FYqfTPIp+KQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dxdEw-0007zG-JZ; Thu, 28 Sep 2017 18:08:50 +0000 Received: from mail-he1eur01on0050.outbound.protection.outlook.com ([104.47.0.50] helo=EUR01-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dxdCQ-0005Or-2a for linux-arm-kernel@lists.infradead.org; Thu, 28 Sep 2017 18:06:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=EPAM.onmicrosoft.com; s=selector1-epam-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=szfs7RlCIri8P+4FHvVlki4sbxt0z4HH6w1tsMX9Egw=; b=Vnthw1wRGy02r2focqdGu3PVe9I1iSk/vJH5URFYRuzlOLXc53XFtTyC0fRvZGwuMzyEBfz7iL3oUS38Ly6z2/Fax/9yg2OcxLAdwe92vk3OWqj3kcwuJAQoUgbPUJwQaBHXDkEV5hENgJWJn8xJK4FwqX7T3r6qrvrgZbDxd6o= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.59) by VI1PR0301MB2141.eurprd03.prod.outlook.com (2603:10a6:800:26::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Thu, 28 Sep 2017 18:05:49 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 28 Sep 2017 21:05:45 +0300 From: Volodymyr Babchuk To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Jens Wiklander Subject: [PATCH v1 12/14] tee: optee: enable dynamic SHM support Date: Thu, 28 Sep 2017 21:04:09 +0300 Message-Id: <1506621851-6929-13-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> References: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.59] X-ClientProxiedBy: VI1PR0101CA0084.eurprd01.prod.exchangelabs.com (2603:10a6:800:1f::52) To VI1PR0301MB2141.eurprd03.prod.outlook.com (2603:10a6:800:26::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 013b4f4b-1d59-490d-8f5a-08d5069b8d4b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:VI1PR0301MB2141; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0301MB2141; 3:ETrAyztglKl2hChdf+9HzGkbJmV2evZNK0xa+nE/6w/GZbjFdzNyjb/0WPhMRA89bEnlqWIbG4AGaw/uWGX50T1Gq49TFJzLrRgrRPbkBofUaw3DVj87Z2+XsW32fPUdL5Dox2IhvEPIXOdNADoXzDaMWPDiGSUIxxVRsmvPRMnrPL+em3Fj/qPSc7/7tJs72ZJY0IAVGXjZ+HrJ2GaASAokz083kGaWpHMFPFYa5hf4vKeKr7ngq7v2wIB2tENJ; 25:YwF3kPoX++g/IJacl4uCjITvA7vLsB9O5Vwz20Xm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BSb4bGsTky14LY+JNyfZQIXWbRs4cd7PPjJiijOGsCq4WFeoOtqdxo4eAAvfrF; 4:ju6A3M6UFR8AyJWEmsMaZXvclNVUUnOL7YHkNMzl2mOaplbEVmhpdCWVoWx7NtdMKTe2JSQLhxz12BUcpjF4CICZ40brPJlCogGqjfVNrkIHPFNv0Jz7U31c7u1YtL42P5U2cLa/5dRfq/pPFy5QOIVoao3nBnqyKo0+Dnq7HIRseHxPNu+0jxENbkqSQke3Yq1XmRqQYR/Qt70Y3c8fBJEYhgJov9Qbea5abfsDqwXzWHM8loQtVOwz3f+R6S+z X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(20161123555025)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0301MB2141; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0301MB2141; X-Forefront-PRVS: 0444EB1997 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(199003)(189002)(16586007)(42186006)(97736004)(80792005)(316002)(2906002)(122856001)(81166006)(81156014)(76176999)(50986999)(6916009)(8676002)(5003940100001)(8936002)(39060400002)(50466002)(48376002)(4326008)(5660300001)(2950100002)(86362001)(72206003)(478600001)(33646002)(106356001)(50226002)(105586002)(305945005)(7736002)(66066001)(47776003)(68736007)(189998001)(6666003)(6116002)(3846002)(36756003)(101416001)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0301MB2141; H:EPUAKYIW2556.kyiv.epam.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: epam.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0301MB2141; 23:Lb/AgoAwxgTlfLeqy8an/t5dijDFxuOLA+hGXSS?= =?us-ascii?Q?jDHtK8hlaGgRMuuZR9BN3EPJ8q90UXx6DQiFy3j/8U9khmPYSOzfoljXmGIZ?= =?us-ascii?Q?d6ji3qRuN4HHV7ZjnwtgHpEc+uzDIhNLo9hR+CCxl7H5+5LgNZSVP04qCTzo?= =?us-ascii?Q?fb1p866HBIAW3X+AQ2905EbdpQA9ig+zc/gyOzEUf+xuWgCWsLPjGRM82Rua?= =?us-ascii?Q?I9C4GkjDze4r6eNKo8yURCYGabzzKAX92IYN9+Lt4NaqklCCjnEG01QZoxOV?= =?us-ascii?Q?jU9TvQX3/ToD2ZGdYcuJBeNEiMixDLFg73+7mZS7JpkZz+5526KNpLgQK/jt?= =?us-ascii?Q?a3EqRJXL6JJjiRWHGoC3I2cS0zmjVL2zCBveqIKSOAZEq68IiZ1J53SAtXw4?= =?us-ascii?Q?R/KrnAiTdhjiNq2XZOYFo0ceqfxAF0cLSDJNYryG2+4w/3rrJtulSt6h3KTX?= =?us-ascii?Q?dfMgz2G2D4dvmkwbUrregwlE2KL3bzMxLnWGL59fZjHRcR6VCr1M2mKgi/NJ?= =?us-ascii?Q?HAa/jdAVVZm8ZFMk52dkwLu2bK81RSCbIv3qdQXVqkQX5D5fG0bPxbSgNkVg?= =?us-ascii?Q?t5l0TQTGN8DscGT5wjervCOO9/KJs7UDmv67pkXvLeIdubAd6QJ3DK0unsDc?= =?us-ascii?Q?h3WWmJCUBb2FwqrZywR0E99rlBrJXGb+y/V4LsCevHhZ63DbqfKR1i45s6Ok?= =?us-ascii?Q?vOz0mZumlLlNrLOY6ePG1Odx2K9zmR0d0kS6F1LM0zwh23e2vqZ3HLXX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Yq9dLmrodagEOh/ML83WaoncoeADTkdfh17lHyS5vy3S+9zHW2wZgTU94i8WfvyC5bD9EcxNtCNH9r/n5UlPoZqG3VrdibHhiGtCV4TDyfC0bPbcPHTvNvYUIbF30EGrkEsBTJIsT7YXUd6vbeIHC3shFMrD+aqEsfVIrPHqWZaAVZsLuCpt5T3zFiftkj9rz80Yy6Fj8tbZqToJ0mVaz+CSn/KtQDF0W4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2017 18:05:49.9905 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0301MB2141 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170928_110615_202946_E7DB2CB2 X-CRM114-Status: GOOD ( 15.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Volodymyr Babchuk Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Volodymyr Babchuk Previous patches added various features that are needed for dynamic SHM. Dynamic SHM allows Normal World to share any buffers with OP-TEE. While original design suggested to use pre-allocated region (usually of 1M to 2M of size), this new approach allows to use all non-secure RAM for command buffers, RPC allocations and TA parameters. This patch checks capability OPTEE_SMC_SEC_CAP_DYNAMIC_SHM. If it was set by OP-TEE, then kernel part of OP-TEE will use kernel page allocator to allocate command buffers. Also it will set TEE_GEN_CAP_REG_MEM capability to tell userspace that it supports shared memory registration. Signed-off-by: Volodymyr Babchuk --- drivers/tee/optee/core.c | 69 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 8e012ea..e8fd9af 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -28,6 +28,7 @@ #include #include "optee_private.h" #include "optee_smc.h" +#include "shm_pool.h" #define DRIVER_NAME "optee" @@ -227,6 +228,10 @@ static void optee_get_version(struct tee_device *teedev, .impl_caps = TEE_OPTEE_CAP_TZ, .gen_caps = TEE_GEN_CAP_GP, }; + struct optee *optee = tee_get_drvdata(teedev); + + if (optee->sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) + v.gen_caps |= TEE_GEN_CAP_REG_MEM; *vers = v; } @@ -405,21 +410,22 @@ static bool optee_msg_exchange_capabilities(optee_invoke_fn *invoke_fn, } static struct tee_shm_pool * -optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm) +optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm, + u32 sec_caps) { union { struct arm_smccc_res smccc; struct optee_smc_get_shm_config_result result; } res; - struct tee_shm_pool *pool; unsigned long vaddr; phys_addr_t paddr; size_t size; phys_addr_t begin; phys_addr_t end; void *va; - struct tee_shm_pool_mem_info priv_info; - struct tee_shm_pool_mem_info dmabuf_info; + struct tee_shm_pool_mgr *priv_mgr; + struct tee_shm_pool_mgr *dmabuf_mgr; + void *rc; invoke_fn(OPTEE_SMC_GET_SHM_CONFIG, 0, 0, 0, 0, 0, 0, 0, &res.smccc); if (res.result.status != OPTEE_SMC_RETURN_OK) { @@ -449,22 +455,49 @@ optee_config_shm_memremap(optee_invoke_fn *invoke_fn, void **memremaped_shm) } vaddr = (unsigned long)va; - priv_info.vaddr = vaddr; - priv_info.paddr = paddr; - priv_info.size = OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; - dmabuf_info.vaddr = vaddr + OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; - dmabuf_info.paddr = paddr + OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; - dmabuf_info.size = size - OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; - - pool = tee_shm_pool_alloc_res_mem(&priv_info, &dmabuf_info); - if (IS_ERR(pool)) { - memunmap(va); - goto out; + /* + * If OP-TEE can work with unregistered SHM, we will use own pool + * for private shm + */ + if (sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) { + rc = optee_shm_pool_alloc_pages(); + if (IS_ERR(rc)) + goto err_memunmap; + priv_mgr = rc; + } else { + const size_t sz = OPTEE_SHM_NUM_PRIV_PAGES * PAGE_SIZE; + + rc = tee_shm_pool_mgr_alloc_res_mem(vaddr, paddr, sz, + 3 /* 8 bytes aligned */); + if (IS_ERR(rc)) + goto err_memunmap; + priv_mgr = rc; + + vaddr += sz; + paddr += sz; + size -= sz; } + rc = tee_shm_pool_mgr_alloc_res_mem(vaddr, paddr, size, PAGE_SHIFT); + if (IS_ERR(rc)) + goto err_free_priv_mgr; + dmabuf_mgr = rc; + + rc = tee_shm_pool_alloc(priv_mgr, dmabuf_mgr); + if (IS_ERR(rc)) + goto err_free_dmabuf_mgr; + *memremaped_shm = va; -out: - return pool; + + return rc; + +err_free_dmabuf_mgr: + tee_shm_pool_mgr_destroy(dmabuf_mgr); +err_free_priv_mgr: + tee_shm_pool_mgr_destroy(priv_mgr); +err_memunmap: + memunmap(va); + return rc; } /* Simple wrapper functions to be able to use a function pointer */ @@ -542,7 +575,7 @@ static struct optee *optee_probe(struct device_node *np) if (!(sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM)) return ERR_PTR(-EINVAL); - pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm); + pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm, sec_caps); if (IS_ERR(pool)) return (void *)pool;