From patchwork Fri Oct 13 19:32:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 10005791 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 87498602B3 for ; Fri, 13 Oct 2017 19:43:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 795EB29137 for ; Fri, 13 Oct 2017 19:43:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DF2E2914B; Fri, 13 Oct 2017 19:43:38 +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 DD91929137 for ; Fri, 13 Oct 2017 19:43:37 +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=8ODSASPteG3M+V/7/MHXzE011TeZ19zR9VHCqAa2Gnk=; b=bvktkN8aBAdV38 mhLyNUDunSe0R9TVAQKMSRFnGrhkrNMgYCIj9he0I9dTdEqNYoYdwZvXoi97tdIxl5Ajx/kTNOrzX ru8saTCNfkbDjw3iY9iXKtwcjVstL7hk7nOJnX1Vlt2uJSwqn5VYyT3iqhgdQKRoNIfKjMg1LbrZJ o5iG4cZ7bnk3OqTJ49QoxnGbTYbno6MPN2ZEsEXf7R8v8ObkF5YhE0ph5emlgG6jxUxUO9c+VoaF2 /PJnRIvQvWTjEWJpBxQTE9WWgNyAmPcyeERG98kp7ghQ4wfqsg90XWauNmVt6ztkQHOPgZ3DqBXyW eTVg8f/zxSM/wV0rdoZg==; 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 1e35rW-0005jH-Io; Fri, 13 Oct 2017 19:43:14 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e35rT-0005e1-Gz for linux-arm-kernel@bombadil.infradead.org; Fri, 13 Oct 2017 19:43:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=02Z3Eg+g5k8UbLiTPgobvRPAKHTwdsoC9R26trZkvkQ=; b=P4pSxmn2tturh9VEl/adcOb2Y F0w03aT6K4yMO9Aln1Fe1k4ewlXJ5KBcZcaa0vmFjyaWpH66LBKOhxnMUg+E+s6PtGKop5mJOt/Sv j4OLkHycSKbnYEGeJgygreK0de0EGMzU7QkaQaXYy3QVWZf9vw2NmFmwi/3SQU+ABRxIixjEd4MOq +9V9HN0zrBSaIKRkLzL3twJ4cTRGY/wTGuty0ifg02lqhyIcXzud+fpFUoPJYdQxnWV37H3yQLchQ aybQSK+0rAGQc4QuJch0a/FvmjwSRO+96at5yjXFvF+nCdGG2/8gZkYSuMLOhtx3swns819KKjcVh Oll7xr4QA==; Received: from mail-db5eur01on0085.outbound.protection.outlook.com ([104.47.2.85] helo=EUR01-DB5-obe.outbound.protection.outlook.com) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e35jU-0006BT-N1 for linux-arm-kernel@lists.infradead.org; Fri, 13 Oct 2017 19:34:59 +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=02Z3Eg+g5k8UbLiTPgobvRPAKHTwdsoC9R26trZkvkQ=; b=N3yhja6e3l4uFeSXuhTIE17QEu5+02o+jBbZ+NofxbOCzfBIxFaFjcRB5yE8OgZKe3d22oOFP+YGzLCZYZ3DYpoPYnvRyq2ggIaqcDwGU/fIioe3DCZ//YdbADR/PlQ15jwZgEOC9dhR6+urn3g0jnFukk0vETNKsu7T/G9AXX0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.52) by AM4PR0301MB2131.eurprd03.prod.outlook.com (2603:10a6:200:4d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Fri, 13 Oct 2017 19:34:33 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Fri, 13 Oct 2017 22:34:30 +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: Fri, 13 Oct 2017 22:32:42 +0300 Message-Id: <1507923164-12796-13-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507923164-12796-1-git-send-email-volodymyr_babchuk@epam.com> References: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> <1507923164-12796-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.52] X-ClientProxiedBy: AM0PR0102CA0054.eurprd01.prod.exchangelabs.com (2603:10a6:208::31) To AM4PR0301MB2131.eurprd03.prod.outlook.com (2603:10a6:200:4d::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5e4b4733-eac7-4700-1049-08d512716e5f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:AM4PR0301MB2131; X-Microsoft-Exchange-Diagnostics: 1; AM4PR0301MB2131; 3:KftVnSGRv1aMXHRLnjJZwiUzD5p77TIljKANT4QgMVKn9jbCSp8++t014gLx/sbgIFwZ27ZEtivHVmVOhk5Q5w0s0mdKXlC2iT+QYLEGb0JpUK0pPy3Gte+11nL0DBsL0kWZYFYM6qrsIOBgKLhUZ4Ntp8FUBVpbCo/eLWsYcNBr+CwA6JtQvH6oxNM+4xlddB2XYredebzOJwY9b9jEsDF21dnF3+M3lNqZHINE45SM/VtlLFoFyPM8zuV60rrM; 25:vL52l6SNdy8up3b22Uk+MTIbIDsg4GEMbRvstC+mHM2oCuRFV6IrGvjxSVr1yI9aKoEHd/tqtETT+fh3QJStUncR1EHS6JZ8LmEepAmKDYB+ZyI7Om6wZOH6raaSCHfajQP7aLU8nfeZdYi09ejCPGYo29gM4I7hsy9UnPf3zn0szhE7FrV+kgkJ5+x3tJNARdaf61+4Hq5hiV2s5Thg2/NKz0wvYoB92WLvJYrvgj97eHFHaJhI8HVsHCtukxIWB3UBWXqMc2Eu1jw7mbWx4rqVq5vg2OGcXWSN+QCQC1RGSZ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YxlTiYFPCZWr0Tf16nFYWFRae7Wk0c5GxOh7g+RSDXGlG 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)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(3002001)(6041248)(20161123562025)(20161123560025)(20161123558100)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR0301MB2131; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR0301MB2131; X-Forefront-PRVS: 04599F3534 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(199003)(189002)(316002)(16586007)(48376002)(42186006)(86362001)(50466002)(6116002)(47776003)(97736004)(2906002)(80792005)(478600001)(101416001)(7736002)(72206003)(305945005)(106356001)(36756003)(105586002)(107886003)(5003940100001)(8936002)(33646002)(122856001)(68736007)(6666003)(76176999)(39060400002)(50226002)(50986999)(189998001)(4326008)(3846002)(53936002)(66066001)(5660300001)(8676002)(6916009)(2950100002)(81166006)(81156014); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0301MB2131; 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; AM4PR0301MB2131; 23:xYrlTGOyetzU+G2LbTtDpMkg2Zx2dYJrIZ9zuHO?= =?us-ascii?Q?D5itGM2l98kRskZSHSN0MWg/Wd8zGwzRWuUlnD717chmj/jx3t0BbHqXD+gs?= =?us-asc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Output: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2017 19:34:33.1526 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0301MB2131 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171013_203456_910423_838D9204 X-CRM114-Status: GOOD ( 17.88 ) 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 , volodymyr_babchuk@epam.com 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 dbe5a61..51d5575 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" @@ -219,6 +220,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; } @@ -397,21 +402,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) { @@ -441,22 +447,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 */ @@ -534,7 +567,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;