From: Volodymyr Babchuk <volodymyr_babchuk@epam.com> To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Jens Wiklander <jens.wiklander@linaro.org> Cc: Volodymyr Babchuk <vlad.babchuk@gmail.com>, volodymyr_babchuk@epam.com Subject: [RESEND PATCH v2 07/14] tee: optee: add shared buffer registration functions Date: Wed, 29 Nov 2017 14:48:31 +0200 [thread overview] Message-ID: <1511959718-5421-8-git-send-email-volodymyr_babchuk@epam.com> (raw) In-Reply-To: <1511959718-5421-1-git-send-email-volodymyr_babchuk@epam.com> From: Volodymyr Babchuk <vlad.babchuk@gmail.com> 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. Of course user can ignore presence of TEE_GEN_CAP_REG_MEM flag and try do call those functions. This is okay, driver will register shared buffer in OP-TEE, but any attempts to use this shared buffer will fail. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> --- drivers/tee/optee/call.c | 69 +++++++++++++++++++++++++++++++++++++++ drivers/tee/optee/core.c | 2 ++ drivers/tee/optee/optee_private.h | 4 +++ 3 files changed, 75 insertions(+) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index 4db52fe..89116a0 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -533,3 +533,72 @@ void optee_free_pages_list(void *list, size_t num_entries) free_pages_exact(list, get_pages_list_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_list; + phys_addr_t msg_parg; + int rc = 0; + + if (!num_pages) + return -EINVAL; + + pages_list = optee_allocate_pages_list(num_pages); + if (!pages_list) + 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_list, pages, num_pages, + tee_shm_get_page_offset(shm)); + + 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); + /* + * In the least bits of msg_arg->params->u.tmem.buf_ptr we + * store buffer offset from 4k page, as described in OP-TEE ABI. + */ + msg_arg->params->u.tmem.buf_ptr = virt_to_phys(pages_list) | + (tee_shm_get_page_offset(shm) & (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1)); + + 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_list(pages_list, 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 b63213d..d7bc77d 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, -- 2.7.4
WARNING: multiple messages have this Message-ID (diff)
From: volodymyr_babchuk@epam.com (Volodymyr Babchuk) To: linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v2 07/14] tee: optee: add shared buffer registration functions Date: Wed, 29 Nov 2017 14:48:31 +0200 [thread overview] Message-ID: <1511959718-5421-8-git-send-email-volodymyr_babchuk@epam.com> (raw) In-Reply-To: <1511959718-5421-1-git-send-email-volodymyr_babchuk@epam.com> From: Volodymyr Babchuk <vlad.babchuk@gmail.com> 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. Of course user can ignore presence of TEE_GEN_CAP_REG_MEM flag and try do call those functions. This is okay, driver will register shared buffer in OP-TEE, but any attempts to use this shared buffer will fail. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> --- drivers/tee/optee/call.c | 69 +++++++++++++++++++++++++++++++++++++++ drivers/tee/optee/core.c | 2 ++ drivers/tee/optee/optee_private.h | 4 +++ 3 files changed, 75 insertions(+) diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index 4db52fe..89116a0 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -533,3 +533,72 @@ void optee_free_pages_list(void *list, size_t num_entries) free_pages_exact(list, get_pages_list_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_list; + phys_addr_t msg_parg; + int rc = 0; + + if (!num_pages) + return -EINVAL; + + pages_list = optee_allocate_pages_list(num_pages); + if (!pages_list) + 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_list, pages, num_pages, + tee_shm_get_page_offset(shm)); + + 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); + /* + * In the least bits of msg_arg->params->u.tmem.buf_ptr we + * store buffer offset from 4k page, as described in OP-TEE ABI. + */ + msg_arg->params->u.tmem.buf_ptr = virt_to_phys(pages_list) | + (tee_shm_get_page_offset(shm) & (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1)); + + 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_list(pages_list, 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 b63213d..d7bc77d 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, -- 2.7.4
next prev parent reply other threads:[~2017-11-29 12:49 UTC|newest] Thread overview: 128+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-09-28 18:03 [PATCH v1 00/14] tee: optee: add dynamic shared memory support Volodymyr Babchuk 2017-09-28 18:03 ` Volodymyr Babchuk 2017-09-28 18:03 ` [PATCH v1 01/14] tee: flexible shared memory pool creation Volodymyr Babchuk 2017-09-28 18:03 ` Volodymyr Babchuk 2017-09-28 18:03 ` [PATCH v1 02/14] tee: add register user memory Volodymyr Babchuk 2017-09-28 18:03 ` Volodymyr Babchuk 2017-09-29 10:53 ` Mark Rutland 2017-09-29 10:53 ` Mark Rutland 2017-09-29 15:19 ` Volodymyr Babchuk 2017-09-29 15:19 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 03/14] tee: shm: add accessors for buffer size and page offset Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 04/14] tee: shm: add page accessor functions Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 22:14 ` Yury Norov 2017-09-28 22:14 ` Yury Norov 2017-09-29 10:17 ` Volodymyr Babchuk 2017-09-29 10:17 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 05/14] tee: optee: Update protocol definitions Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 06/14] tee: optee: add page list manipulation functions Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-29 0:23 ` Yury Norov 2017-09-29 0:23 ` Yury Norov 2017-09-29 10:34 ` Volodymyr Babchuk 2017-09-29 10:34 ` Volodymyr Babchuk 2017-09-29 16:23 ` Yury Norov 2017-09-29 16:23 ` Yury Norov 2017-09-29 13:00 ` Mark Rutland 2017-09-29 13:00 ` Mark Rutland 2017-09-28 18:04 ` [PATCH v1 07/14] tee: optee: add shared buffer registration functions Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-29 13:06 ` Mark Rutland 2017-09-29 13:06 ` Mark Rutland 2017-09-29 15:37 ` Volodymyr Babchuk 2017-09-29 15:37 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 08/14] tee: optee: add registered shared parameters handling Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 09/14] tee: optee: add registered buffers handling into RPC calls Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 10/14] tee: optee: store OP-TEE capabilities in private data Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 11/14] tee: optee: add optee-specific shared pool implementation Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 12/14] tee: optee: enable dynamic SHM support Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-10-03 16:06 ` [Tee-dev] " Stuart Yoder 2017-10-03 16:06 ` Stuart Yoder 2017-10-04 11:49 ` Jens Wiklander 2017-10-04 11:49 ` Jens Wiklander 2017-09-28 18:04 ` [PATCH v1 13/14] tee: use reference counting for tee_context Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-28 18:04 ` [PATCH v1 14/14] tee: shm: inline tee_shm getter functions Volodymyr Babchuk 2017-09-28 18:04 ` Volodymyr Babchuk 2017-09-29 0:50 ` Yury Norov 2017-09-29 0:50 ` Yury Norov 2017-09-29 10:31 ` [PATCH v1 00/14] tee: optee: add dynamic shared memory support Mark Rutland 2017-09-29 10:31 ` Mark Rutland 2017-09-29 10:51 ` Volodymyr Babchuk 2017-09-29 10:51 ` Volodymyr Babchuk 2017-10-03 16:05 ` [Tee-dev] " Stuart Yoder 2017-10-03 16:05 ` Stuart Yoder 2017-10-04 17:23 ` Volodymyr Babchuk 2017-10-04 17:23 ` Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 01/14] tee: flexible shared memory pool creation Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 02/14] tee: add register user memory Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 03/14] tee: shm: add accessors for buffer size and page offset Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 04/14] tee: shm: add page accessor functions Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 05/14] tee: optee: Update protocol definitions Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 06/14] tee: optee: add page list manipulation functions Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 07/14] tee: optee: add shared buffer registration functions Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 08/14] tee: optee: add registered shared parameters handling Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 09/14] tee: optee: add registered buffers handling into RPC calls Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 10/14] tee: optee: store OP-TEE capabilities in private data Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 11/14] tee: optee: add optee-specific shared pool implementation Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 12/14] tee: optee: enable dynamic SHM support Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 13/14] tee: use reference counting for tee_context Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:32 ` [PATCH v1 14/14] tee: shm: inline tee_shm_get_id() Volodymyr Babchuk 2017-10-13 19:32 ` Volodymyr Babchuk 2017-10-13 19:40 ` [PATCH v1 00/14] tee: optee: add dynamic shared memory support Volodymyr Babchuk 2017-10-13 19:40 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 " Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 01/14] tee: flexible shared memory pool creation Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 02/14] tee: add register user memory Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 03/14] tee: shm: add accessors for buffer size and page offset Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 04/14] tee: shm: add page accessor functions Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 05/14] tee: optee: Update protocol definitions Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 06/14] tee: optee: add page list manipulation functions Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk [this message] 2017-11-29 12:48 ` [RESEND PATCH v2 07/14] tee: optee: add shared buffer registration functions Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 08/14] tee: optee: add registered shared parameters handling Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 09/14] tee: optee: add registered buffers handling into RPC calls Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 10/14] tee: optee: store OP-TEE capabilities in private data Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 11/14] tee: optee: add optee-specific shared pool implementation Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 12/14] tee: optee: enable dynamic SHM support Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 13/14] tee: use reference counting for tee_context Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-11-29 12:48 ` [RESEND PATCH v2 14/14] tee: shm: inline tee_shm_get_id() Volodymyr Babchuk 2017-11-29 12:48 ` Volodymyr Babchuk 2017-12-06 14:32 ` [RESEND PATCH v2 00/14] tee: optee: add dynamic shared memory support Jens Wiklander 2017-12-06 14:32 ` Jens Wiklander
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1511959718-5421-8-git-send-email-volodymyr_babchuk@epam.com \ --to=volodymyr_babchuk@epam.com \ --cc=jens.wiklander@linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=tee-dev@lists.linaro.org \ --cc=vlad.babchuk@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.