Received: by 10.223.164.202 with SMTP id h10csp4397901wrb; Wed, 29 Nov 2017 05:52:40 -0800 (PST) X-Google-Smtp-Source: AGs4zMa0NEiLwJo1GQ7X5w0e/CXXlUkoabTT7YU1Uc221Wp380ylT+/Vnq6cv2hEA7XQkZNp7sqg X-Received: by 10.159.214.146 with SMTP id n18mr3077669plp.310.1511963560352; Wed, 29 Nov 2017 05:52:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511963560; cv=none; d=google.com; s=arc-20160816; b=PWuEZJRbZwbsDVITe5+rcj6RGm1ikZK6sMX0Z5Bqo95vGqXFwXUXUlwT2VINdoO4kU GdTfne7PeS1YLwoW3/5dXwu7NVEvAj4oYzYWd/XepBpFhnaGi5R+aDKkP+iEMpRbMjns yaD/HSMdo20ccTuS2JAmv5FIP6XxfRWbEmR5pJTWtrbFDfz9RpX0oT34JLMwDif//xkG vgewoEjmLvNUTQ9pfKn9lDbEzs5vPbYIZLmcPap6cWQA1xSNWv6QjL1PY/SZYkoyPfRv kuYek5fMmgL/R2pbHit1asi6Ym/Ml+2FDd8afh28fmQR0DSbpOtE5MeSlhDAzZ468jx7 5nLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=PmCK4uOSDv5zFeniOWetwJtF/1gazVrnF91cdjraSvw=; b=Wd91+F02sCb6j2VIUbR2KYZw5bssQcFjFP/mBJ8KTWW0N39ksXVWCkQD6RlF30FQsB 0KE0q1TPVP3IB39VHebWfC0gkCdpOUM+KsQGu+lFS/bghs9KGjleHyIu7Dskd/nnixV9 7GX5RZ2czYAcE8KmLfEqYUg5hQqWqhjg9mUChh7U4quIEZ5PiS4B8ofz+ZtlSYh+Menh jkLcq4NSUIWP8zxnAnTudJVAt5aK2NlU4dQhcGcVbIC2pLfqi+hwQIhG7hNhIxpRkubN K9LCQJh4//UwjqWQrSSdy+0WeeobYB987kfk6ow9JNjlN2Wa+yI5QomOZQdXMdb/U50F 7q9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@epam.com header.s=selector1 header.b=bQjkST31; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10si1292035pgc.772.2017.11.29.05.52.29; Wed, 29 Nov 2017 05:52:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@epam.com header.s=selector1 header.b=bQjkST31; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754926AbdK2MvG (ORCPT + 70 others); Wed, 29 Nov 2017 07:51:06 -0500 Received: from mail-eopbgr20086.outbound.protection.outlook.com ([40.107.2.86]:50720 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754890AbdK2Mts (ORCPT ); Wed, 29 Nov 2017 07:49:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PmCK4uOSDv5zFeniOWetwJtF/1gazVrnF91cdjraSvw=; b=bQjkST31f3CZmKrQKb3UMxvrQb22bbFDo6a+iMBiBqIR0PK4wJ9WeFWpY2s4xqGHhuFse3sYq2Uw+fEsV8iU5kpeoG5K/ejIzwFxVWPaRghNcLm5Kro4RZ+UhkrWiwTqLYMcs8q4w+VlFgNVQvNVQdo8yWu0hyXtRKDHrSi687I= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by HE1PR03MB1771.eurprd03.prod.outlook.com (2a01:111:e400:7be8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Wed, 29 Nov 2017 12:49:43 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Wed, 29 Nov 2017 14:49:39 +0200 From: Volodymyr Babchuk To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Jens Wiklander Cc: Volodymyr Babchuk , volodymyr_babchuk@epam.com Subject: [RESEND PATCH v2 09/14] tee: optee: add registered buffers handling into RPC calls Date: Wed, 29 Nov 2017 14:48:33 +0200 Message-Id: <1511959718-5421-10-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511959718-5421-1-git-send-email-volodymyr_babchuk@epam.com> References: <1507923164-12796-1-git-send-email-volodymyr_babchuk@epam.com> <1511959718-5421-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: VI1PR0102CA0035.eurprd01.prod.exchangelabs.com (2603:10a6:802::48) To HE1PR03MB1771.eurprd03.prod.outlook.com (2a01:111:e400:7be8::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b365e0e-4796-4696-b4e9-08d53727aa62 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(2017052603270);SRVR:HE1PR03MB1771; X-Microsoft-Exchange-Diagnostics: 1;HE1PR03MB1771;3:BLE98JrtIycUtSQoF1aC1pGGQ3DCt/4DRlrHjAi9MWPtFl0EWpL5gWs/8yifnHCoTFHm4764niO1wURTL/YFkwwhwd2meR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+wgqfYaNq+LEkykwBYygXstxleHC1OYN2FgkEZ/1lMMpFQK41VRM9fF8oARNHfOdjBALpn0n/BaulC+/c0DpVbk8Q5kT4LbmCSZ4z7TQlFtrqZ641/QI/Z485jcM/wtY9sSVRTfBWDio5kNsuDsTLY+8dfe9STrR7McwS4wwiMuXL8Yo5ixjK/R2V8qewqNDHgNwy2eOHJSp5qgY8qMzRj7bF2B6Bb3l6RO56N5Wc3jGL3QYWCkAROuTn/Cqp7IgOE9ngiJN8L/DJ;4:SQvNh8GPMH+zBvvw/96a/5RfUTd6o8DV+vjD+xndQP5/rg1c5hq02Y7Pu+TqKxkzZrh8aVihqwsbmbsa8WJzZDyOmilCVJ6sy5V5BqCnMIknHzIGo9OsmK25unVtzpvzluFMTDmbHhTuuWMg+vkICx/HBJBwvWlxnzsl3arRoaUZkjhB+6I/SFHoCZeH/sV2/FCHv7IYcxGACi3BdNNsAIBFfTGKEUxeOZ5OQvtDgHhy/nxhduTcn1ccuwGV+5gLOzmtmvVVcO8P6j/BD+fxZg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(3002001)(3231022)(93006095)(93001095)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(20161123562025)(20161123558100)(20161123560025)(6072148)(201708071742011);SRVR:HE1PR03MB1771;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:HE1PR03MB1771; X-Forefront-PRVS: 05066DEDBB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(366004)(376002)(346002)(199003)(189002)(48376002)(55236003)(76176999)(52116002)(478600001)(50466002)(68736007)(6116002)(3846002)(47776003)(107886003)(81156014)(36756003)(16586007)(50226002)(66066001)(4326008)(51416003)(8676002)(33646002)(72206003)(50986999)(81166006)(39060400002)(8936002)(305945005)(122856001)(189998001)(5660300001)(316002)(2906002)(7736002)(42186006)(80792005)(101416001)(105586002)(53936002)(2950100002)(97736004)(6666003)(86362001)(106356001)(6916009)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR03MB1771;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) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Volodymyr_Babchuk@epam.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR03MB1771;23:2c+IDY2sW/+NaKDMokRFAO21T1WnqTTwi41sKRTwA?= =?us-ascii?Q?y5QH16ZVHC7idsgYdnKwRUnjTH8egHceTDcGDAoOJGEIESMpuA9Jf7CAfImn?= =?us-ascii?Q?sSoXPjK+Fi4vDIadHHwEHjvgZRbHzOaPPAeaXSA5iSKwYVaNY7MhuKQLZNAq?= =?us-ascii?Q?XtZ4uv+h0rupAPeBQBpr21dYxD+wRIvZbtHzELqK2uAAOJp17oyhaVfKunQ1?= =?us-ascii?Q?miM7yzmxt7nKcVjr/WDJFqI+SpiaEDXjVlxFo3HCJWqJMrf64MDrkwfjRpWo?= =?us-ascii?Q?ZyF/HdpfQY6DsLEH5DoxoK2K8pzeKFbOjZmaO1pxW7lgeJ9I9W6JeU9+L4On?= =?us-ascii?Q?fe/eG6WAaK/LPi3QtmcWjsW+74aG5YVDGN2/HNJZYR7tlsQsSZhw+PMu88iC?= =?us-ascii?Q?1Vn0cFuQ5JHNsBqGjvDn7t3ZNPguXy2L5Yi/JRXephx47rfQ9MEOLh+2F2IY?= =?us-ascii?Q?pYLu64rnooyTcucSq6oYXi3hQ517afY5DtC1xB3jyxk/hqmDSQtU4F/iMJXi?= =?us-ascii?Q?1RwUDouzkHkcYZEjQvA5qLtoN0sJiydM8Oavlxym1fq1stL1O6dSKMFpFP4V?= =?us-ascii?Q?uGON3Dsiym6nXCcmZlilXurD9zHVrX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zJwZnwushyecELqA=;5:uqxPYSs9PNaJOvFdIAo21eNyV/HqxZwo/6/RIgiLVSjizBapKpWm2GouyuAQH+sXo3rvtHJJU07+cDbdlQuF9P5uCwEP57out7zhUkgsFElNdOW3WrpjvwZtwCuIRR5mvh724IBwOmN48qKElU8lJzRb98HJ+gq9vBTPSaKWevw=;24:YiogWpi9JCAFdbkB/tFicU7fUdOn8ze9DqYiCS7C6KuVvyTYJrtVc2XclChA4G9vBqrmn8+5YZnSb6+76ca9gk4M2LokGbC0sLMORRw7/TA=;7:kNQZkz0jsWz3f3CjDBUawddqEp599WVTGQFZEL3sc4qJbKVybyDkIKHlOpxlrVl5rrdJWnb7dXuck+Vq9IiGBSBx4ScLWXh6stkIL4mj2OiwQ1T7A59x2ZsUoH80UuMhiQal4ntB35kp2P6/5tNNWQd8EA8K7si1tf24vAxTrGQsLMNTSRYvaoUqchs1uCRhy67xYwuPwYYsQSAVeFlmzY6/GRcAMIRAD+NeLIhQe0nCXTwhq5QC2X4UZ1QPeoMF SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2017 12:49:43.7609 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b365e0e-4796-4696-b4e9-08d53727aa62 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR03MB1771 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Volodymyr Babchuk With latest changes to OP-TEE we can use any buffers as a shared memory. Thus, it is possible for supplicant to provide part of own memory when OP-TEE asks to allocate a shared buffer. This patch adds support for such feature into RPC handling code. Now when OP-TEE asks supplicant to allocate shared buffer, supplicant can use TEE_IOC_SHM_REGISTER to provide such buffer. RPC handler is aware of this, so it will pass list of allocated pages to OP-TEE. Signed-off-by: Volodymyr Babchuk --- drivers/tee/optee/call.c | 19 +++++++++- drivers/tee/optee/core.c | 2 + drivers/tee/optee/optee_private.h | 15 +++++++- drivers/tee/optee/rpc.c | 77 ++++++++++++++++++++++++++++++++++----- 4 files changed, 102 insertions(+), 11 deletions(-) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index 89116a0..969045b 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -136,6 +136,7 @@ u32 optee_do_call_with_arg(struct tee_context *ctx, phys_addr_t parg) struct optee *optee = tee_get_drvdata(ctx->teedev); struct optee_call_waiter w; struct optee_rpc_param param = { }; + struct optee_call_ctx call_ctx = { }; u32 ret; param.a0 = OPTEE_SMC_CALL_WITH_ARG; @@ -160,13 +161,14 @@ u32 optee_do_call_with_arg(struct tee_context *ctx, phys_addr_t parg) param.a1 = res.a1; param.a2 = res.a2; param.a3 = res.a3; - optee_handle_rpc(ctx, ¶m); + optee_handle_rpc(ctx, ¶m, &call_ctx); } else { ret = res.a0; break; } } + optee_rpc_finalize_call(&call_ctx); /* * We're done with our thread in secure world, if there's any * thread waiters wake up one. @@ -602,3 +604,18 @@ int optee_shm_unregister(struct tee_context *ctx, struct tee_shm *shm) tee_shm_free(shm_arg); return rc; } + +int optee_shm_register_supp(struct tee_context *ctx, struct tee_shm *shm, + struct page **pages, size_t num_pages) +{ + /* + * We don't want to register supplicant memory in OP-TEE. + * Instead information about it will be passed in RPC code. + */ + return 0; +} + +int optee_shm_unregister_supp(struct tee_context *ctx, struct tee_shm *shm) +{ + return 0; +} diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 3729ebb..d22433c 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -331,6 +331,8 @@ static const struct tee_driver_ops optee_supp_ops = { .release = optee_release, .supp_recv = optee_supp_recv, .supp_send = optee_supp_send, + .shm_register = optee_shm_register_supp, + .shm_unregister = optee_shm_unregister_supp, }; static const struct tee_desc optee_supp_desc = { diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index d7bc77d..61a0052 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -130,7 +130,16 @@ struct optee_rpc_param { u32 a7; }; -void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param); +/* Holds context that is preserved during one STD call */ +struct optee_call_ctx { + /* information about pages list used in last allocation */ + void *pages_list; + size_t num_entries; +}; + +void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param, + struct optee_call_ctx *call_ctx); +void optee_rpc_finalize_call(struct optee_call_ctx *call_ctx); void optee_wait_queue_init(struct optee_wait_queue *wq); void optee_wait_queue_exit(struct optee_wait_queue *wq); @@ -164,6 +173,10 @@ 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_shm_register_supp(struct tee_context *ctx, struct tee_shm *shm, + struct page **pages, size_t num_pages); +int optee_shm_unregister_supp(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, diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c index cef417f..7bd18e3 100644 --- a/drivers/tee/optee/rpc.c +++ b/drivers/tee/optee/rpc.c @@ -200,7 +200,8 @@ static struct tee_shm *cmd_alloc_suppl(struct tee_context *ctx, size_t sz) } static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx, - struct optee_msg_arg *arg) + struct optee_msg_arg *arg, + struct optee_call_ctx *call_ctx) { phys_addr_t pa; struct tee_shm *shm; @@ -245,10 +246,49 @@ static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx, goto bad; } - arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT; - arg->params[0].u.tmem.buf_ptr = pa; - arg->params[0].u.tmem.size = sz; - arg->params[0].u.tmem.shm_ref = (unsigned long)shm; + sz = tee_shm_get_size(shm); + + if (tee_shm_is_registered(shm)) { + struct page **pages; + u64 *pages_list; + size_t page_num; + + pages = tee_shm_get_pages(shm, &page_num); + if (!pages || !page_num) { + arg->ret = TEEC_ERROR_OUT_OF_MEMORY; + goto bad; + } + + pages_list = optee_allocate_pages_list(page_num); + if (!pages_list) { + arg->ret = TEEC_ERROR_OUT_OF_MEMORY; + goto bad; + } + + call_ctx->pages_list = pages_list; + call_ctx->num_entries = page_num; + + arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT | + OPTEE_MSG_ATTR_NONCONTIG; + /* + * In the least bits of u.tmem.buf_ptr we store buffer offset + * from 4k page, as described in OP-TEE ABI. + */ + arg->params[0].u.tmem.buf_ptr = virt_to_phys(pages_list) | + (tee_shm_get_page_offset(shm) & + (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1)); + arg->params[0].u.tmem.size = tee_shm_get_size(shm); + arg->params[0].u.tmem.shm_ref = (unsigned long)shm; + + optee_fill_pages_list(pages_list, pages, page_num, + tee_shm_get_page_offset(shm)); + } else { + arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT; + arg->params[0].u.tmem.buf_ptr = pa; + arg->params[0].u.tmem.size = sz; + arg->params[0].u.tmem.shm_ref = (unsigned long)shm; + } + arg->ret = TEEC_SUCCESS; return; bad: @@ -307,8 +347,24 @@ static void handle_rpc_func_cmd_shm_free(struct tee_context *ctx, arg->ret = TEEC_SUCCESS; } +static void free_pages_list(struct optee_call_ctx *call_ctx) +{ + if (call_ctx->pages_list) { + optee_free_pages_list(call_ctx->pages_list, + call_ctx->num_entries); + call_ctx->pages_list = NULL; + call_ctx->num_entries = 0; + } +} + +void optee_rpc_finalize_call(struct optee_call_ctx *call_ctx) +{ + free_pages_list(call_ctx); +} + static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee, - struct tee_shm *shm) + struct tee_shm *shm, + struct optee_call_ctx *call_ctx) { struct optee_msg_arg *arg; @@ -329,7 +385,8 @@ static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee, handle_rpc_func_cmd_wait(arg); break; case OPTEE_MSG_RPC_CMD_SHM_ALLOC: - handle_rpc_func_cmd_shm_alloc(ctx, arg); + free_pages_list(call_ctx); + handle_rpc_func_cmd_shm_alloc(ctx, arg, call_ctx); break; case OPTEE_MSG_RPC_CMD_SHM_FREE: handle_rpc_func_cmd_shm_free(ctx, arg); @@ -343,10 +400,12 @@ static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee, * optee_handle_rpc() - handle RPC from secure world * @ctx: context doing the RPC * @param: value of registers for the RPC + * @call_ctx: call context. Preserved during one OP-TEE invocation * * Result of RPC is written back into @param. */ -void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param) +void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param, + struct optee_call_ctx *call_ctx) { struct tee_device *teedev = ctx->teedev; struct optee *optee = tee_get_drvdata(teedev); @@ -381,7 +440,7 @@ void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param) break; case OPTEE_SMC_RPC_FUNC_CMD: shm = reg_pair_to_ptr(param->a1, param->a2); - handle_rpc_func_cmd(ctx, optee, shm); + handle_rpc_func_cmd(ctx, optee, shm, call_ctx); break; default: pr_warn("Unknown RPC func 0x%x\n", -- 2.7.4 From 1581172285425972346@xxx Fri Oct 13 19:36:38 +0000 2017 X-GM-THRID: 1579807681650156014 X-Gmail-Labels: Inbox,Category Forums