From patchwork Thu Sep 28 18:04:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9976629 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 1F5E46034B for ; Thu, 28 Sep 2017 18:06:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13A1B296D2 for ; Thu, 28 Sep 2017 18:06:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 082AA296D9; Thu, 28 Sep 2017 18:06:55 +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 7D058296D2 for ; Thu, 28 Sep 2017 18:06:54 +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=iGYbc2IZ8Ns2tRM4GiCwenhgxNplYtCqUfpLYfWq+pU=; b=YsYtS7XpI6mCeE RR3AAwMctRxjdoFa8iK/SbGHchqvWtb7AZyBMBfS72N+AWvmjT/I4LfxD4FIaFTcyD/Vude9/glNd Sh56vi6n7u6VnJiXsas9VA2B+LTlaJAQAgOjE9zCOiRLQpuLm0VvcFnH0T5eNSYPRfQqXRHMGotX0 vTTVv8lvw8QLesWyVEEm/ilqDTJ33PdXB/cvlnpXbzNyk9l3oD+qLWZ59PEtaE9Chj5akZpIHjMGJ blK2rAc6df6EoxVGIA4Je9a5VrzG5c6E0if5c76eUbr2CEE7jd015Tf0/m38CyNELw6Xu/q7cfFwT wyn758WLfmI70ZBHkELQ==; 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 1dxdCy-00062q-TE; Thu, 28 Sep 2017 18:06:48 +0000 Received: from mail-eopbgr20078.outbound.protection.outlook.com ([40.107.2.78] helo=EUR02-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dxdBx-0004zm-2f for linux-arm-kernel@lists.infradead.org; Thu, 28 Sep 2017 18:06:12 +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=sW2pu4PvP9enZ+mAUIpjTb31GgEZksGiukfhsNdhW0c=; b=Ufc19SOs9D2Ux26hPLjMA9Kn034caJqT3AjP+G5TuECaFf4wDPFBrnHAyVAyNNBS7kF1aif1SrSaR22x7rISkrXmB0QSJoDvb8t+T+K8drRyljZNq+jRCiDaJqgtx/GP3xq+a4jVh7LiqHvVELX7/25Bj+YTEorRRKkkReyzZjo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.59) by HE1PR0301MB2139.eurprd03.prod.outlook.com (2603:10a6:3:21::16) 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:20 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 28 Sep 2017 21:05:16 +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 07/14] tee: optee: add shared buffer registration functions Date: Thu, 28 Sep 2017 21:04:04 +0300 Message-Id: <1506621851-6929-8-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: VI1PR0101CA0049.eurprd01.prod.exchangelabs.com (2603:10a6:800:1f::17) To HE1PR0301MB2139.eurprd03.prod.outlook.com (2603:10a6:3:21::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06866de8-a9ee-4b45-2ce5-08d5069b7bb4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:HE1PR0301MB2139; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0301MB2139; 3:HDb6pmZrJgMBwCPg732EnqKISUX2gFz2Q8LoHQcVAJcasXYgHc+cwJZTCwNKzhbtMfwdwODcn4TfSzWAWVePScKdCT1KbJQAy5RoWKE9vCPLK2PqUnJJT8iaPbB51JGOIHVO7SoC+H32g70C4f82WC6Xf4LaGxg2JfOY7VIEKmkEgyKu1IJNCWs+E3GhpLuTbTwNVuE5aKxh8+6WL1DTEl1bYgQ7JoP6HNsliJR0qgu4EA8m1vcNVXxigvRQQhON; 25:OXybK5i5w73f16S5e7gMk9N5F6AAAx2Ms+U57+N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ew8P32WcjfjCN8sAeS68LKvZ2/Gy6BGlMTT3Yg91coV6EXgf1YHoOoU4ygbqKGP; 4:7DqRnXLo3HF2yx2Y7meA6S9lJ1r3s5mPPsjdWEMhDgmFMonAIiCdx8iawSNQoYYtgbyIkzUav3K7IREMtR30va0gEoSyYt8ceGhVWHvJi6XaLPPeKvO/kGbxskk9hroWBxRmMLmLAp5QUFod4bwoQDLuiAT+ACFaUJ6YF73xuOVYDhtzds1djHKsekhhzlR8dMMbbQr9XfnFGwp0eq9sxCc91sPK74hoEU1wK9fr3cD155ADxdaf2/iZenmiVdcT 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)(10201501046)(3002001)(100000703101)(100105400095)(6041248)(20161123564025)(20161123560025)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0301MB2139; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0301MB2139; X-Forefront-PRVS: 0444EB1997 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(199003)(189002)(189998001)(86362001)(8936002)(97736004)(106356001)(105586002)(50986999)(80792005)(7736002)(305945005)(81166006)(81156014)(33646002)(101416001)(76176999)(8676002)(68736007)(72206003)(5003940100001)(50466002)(5660300001)(2906002)(48376002)(4326008)(53936002)(39060400002)(478600001)(36756003)(6916009)(122856001)(16586007)(2950100002)(6116002)(6666003)(47776003)(316002)(50226002)(3846002)(66066001)(42186006); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0301MB2139; 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; HE1PR0301MB2139; 23:QRZNy9YgrDDsuIBRRzIccbPXs1kaLzvLrgIRq1E?= =?us-ascii?Q?cU+2ecRT9AqO84+PbRzD74IekNw1B7mB11D7DWtjRs+IcY1Mp3wHPieDWM6Z?= =?us-ascii?Q?adz9ajVYt31eaqov29VQs2UqOoJD4vs6rVQAnr1lHhELGgRsSqxTAZDB+vm1?= =?us-ascii?Q?fP2ngn7AL1JDVi05pS5LsWGKAA3rjWZWj+jQfc00ujN2PBjZTJhaN+CxvuHe?= =?us-ascii?Q?LfaUP2CAENA0TkF2dkS5f87zZG35wZeeuLE/uoRREG9M1BiffzuwXe2IKs/X?= =?us-ascii?Q?cTJ89a9J5DutUB0XvuNy575RfvXy151nw4paw6Mfdyh9jUAR5LkiaV7+o3a2?= =?us-ascii?Q?p4EwTYk11Am3AgVAKGldR5yz3DrIh6n0L0TrKtKpkgjsW0+DhpmXHTgTCgIc?= =?us-ascii?Q?3C4ale8HqADaaK2JMkWTrBkOj+CZhXYtQGLly12qxoG8phC5AF1h+E2uyplh?= =?us-ascii?Q?7phV3WmXgTljIktozb2ekWU0vNw3uO1WatP8OCAJ8P/wa9Tvky2i0udkw6Ac?= =?us-ascii?Q?in/D+TeqQaQxk+cFEHh5clRabUMf0ECxYj9k7LDzW+rH0VhQgoINcaFRk69h?= =?us-ascii?Q?YlangnR4rwxijAeqyWJfdf0A1EW5/UUqMTdTM3ma5JuL8grVYIk7VCJ3q6wC?= =?us-ascii?Q?ENOZHP1/FouotyFO5LzPMGvzpbK69BkEh7IqWGcsnb4RM4JQxPmuEr0JBm4o?= =?us-ascii?Q?gs0EgYJysAAnXR9ryGRw9hev+puG5kDjvlcm4qsr1Zs9Sr64+DmPblMKGktr?= =?us-ascii?Q?KsJW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tC5nJa2juNXY4L6mmRHvp9YAIokXzom/7dcbwJDvWdJzF9kyRpCqCkOQy/Opg3LVU2e18skYHZtEcUGTWHPJAU/aDZME0tk/8gs9BTvfyE09AnpvOneW/vkv8+iMBga4g+ltFMWu9LWGPm4X0WSKo//p3t3Sh53Mbm30YKnBM2/MIB60F7HNWH6WoMDhBCjMk86E2VvNZ0CGw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2017 18:05:20.1646 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0301MB2139 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170928_110546_130027_716E0638 X-CRM114-Status: GOOD ( 12.45 ) 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 This change adds ops for shm_(un)register functions in tee interface. Client application can use these functions to (un)register an own shared buffer in OP-TEE address space. This allows zero copy data sharing between Normal and Secure Worlds. Please note that while those functions were added to optee code, it does not report to userspace that those functions are available. OP-TEE code does not set TEE_GEN_CAP_REG_MEM flag. This flag will be enabled only after all other features of dynamic shared memory will be implemented in subsequent patches. Signed-off-by: Volodymyr Babchuk --- drivers/tee/optee/call.c | 64 +++++++++++++++++++++++++++++++++++++++ drivers/tee/optee/core.c | 2 ++ drivers/tee/optee/optee_private.h | 4 +++ 3 files changed, 70 insertions(+) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index f8e044d..ec53dca 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -490,3 +490,67 @@ void optee_free_pages_array(void *array, size_t num_entries) free_pages_exact(array, get_pages_array_size(num_entries)); } +int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm, + struct page **pages, size_t num_pages) +{ + struct tee_shm *shm_arg = NULL; + struct optee_msg_arg *msg_arg; + u64 *pages_array; + phys_addr_t msg_parg; + int rc = 0; + + if (!num_pages) + return -EINVAL; + + pages_array = optee_allocate_pages_array(num_pages); + if (!pages_array) + return -ENOMEM; + + shm_arg = get_msg_arg(ctx, 1, &msg_arg, &msg_parg); + if (IS_ERR(shm_arg)) { + rc = PTR_ERR(shm_arg); + goto out; + } + + optee_fill_pages_list(pages_array, pages, num_pages); + + msg_arg->cmd = OPTEE_MSG_CMD_REGISTER_SHM; + msg_arg->params->attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT | + OPTEE_MSG_ATTR_NONCONTIG; + msg_arg->params->u.tmem.shm_ref = (unsigned long)shm; + msg_arg->params->u.tmem.size = tee_shm_get_size(shm); + msg_arg->params->u.tmem.buf_ptr = virt_to_phys(pages_array) | + tee_shm_get_page_offset(shm); + + if (optee_do_call_with_arg(ctx, msg_parg) || + msg_arg->ret != TEEC_SUCCESS) + rc = -EINVAL; + + tee_shm_free(shm_arg); +out: + optee_free_pages_array(pages_array, num_pages); + return rc; +} + +int optee_shm_unregister(struct tee_context *ctx, struct tee_shm *shm) +{ + struct tee_shm *shm_arg; + struct optee_msg_arg *msg_arg; + phys_addr_t msg_parg; + int rc = 0; + + shm_arg = get_msg_arg(ctx, 1, &msg_arg, &msg_parg); + if (IS_ERR(shm_arg)) + return PTR_ERR(shm_arg); + + msg_arg->cmd = OPTEE_MSG_CMD_UNREGISTER_SHM; + + msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; + msg_arg->params[0].u.rmem.shm_ref = (unsigned long)shm; + + if (optee_do_call_with_arg(ctx, msg_parg) || + msg_arg->ret != TEEC_SUCCESS) + rc = -EINVAL; + tee_shm_free(shm_arg); + return rc; +} diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 7952357..4d448bf 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -267,6 +267,8 @@ static const struct tee_driver_ops optee_ops = { .close_session = optee_close_session, .invoke_func = optee_invoke_func, .cancel_req = optee_cancel_req, + .shm_register = optee_shm_register, + .shm_unregister = optee_shm_unregister, }; static const struct tee_desc optee_desc = { diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index caa3c04..3ea7f7a 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -160,6 +160,10 @@ int optee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session); void optee_enable_shm_cache(struct optee *optee); void optee_disable_shm_cache(struct optee *optee); +int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm, + struct page **pages, size_t num_pages); +int optee_shm_unregister(struct tee_context *ctx, struct tee_shm *shm); + int optee_from_msg_param(struct tee_param *params, size_t num_params, const struct optee_msg_param *msg_params); int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params,