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> Subject: [PATCH v1 08/14] tee: optee: add registered shared parameters handling Date: Thu, 28 Sep 2017 21:04:05 +0300 [thread overview] Message-ID: <1506621851-6929-9-git-send-email-volodymyr_babchuk@epam.com> (raw) In-Reply-To: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> From: Volodymyr Babchuk <vlad.babchuk@gmail.com> Now, when client applications can register own shared buffers in OP-TEE, we need to extend ABI for parameter passing to/from OP-TEE. So, if OP-TEE core detects that parameter belongs to registered shared memory, it will use corresponding parameter attribute. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> --- drivers/tee/optee/core.c | 86 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 4d448bf..a962f60 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -97,6 +97,33 @@ int optee_from_msg_param(struct tee_param *params, size_t num_params, return rc; } break; + case OPTEE_MSG_ATTR_TYPE_RMEM_INPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_INOUT: + p->attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT + + attr - OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; + p->u.memref.size = mp->u.rmem.size; + shm = (struct tee_shm *)(unsigned long) + mp->u.rmem.shm_ref; + + if (!shm) { + p->u.memref.shm_offs = 0; + p->u.memref.shm = NULL; + break; + } + p->u.memref.shm_offs = mp->u.rmem.offs; + p->u.memref.shm = shm; + + /* Check that the memref is covered by the shm object */ + if (p->u.memref.size) { + size_t o = p->u.memref.shm_offs + + p->u.memref.size; + + if (o > tee_shm_get_size(shm)) + return -EINVAL; + } + break; + default: return -EINVAL; } @@ -104,6 +131,46 @@ int optee_from_msg_param(struct tee_param *params, size_t num_params, return 0; } +static int to_msg_param_tmp_mem(struct optee_msg_param *mp, + const struct tee_param *p) +{ + int rc; + phys_addr_t pa; + + mp->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT + p->attr - + TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + + mp->u.tmem.shm_ref = (unsigned long)p->u.memref.shm; + mp->u.tmem.size = p->u.memref.size; + + if (!p->u.memref.shm) { + mp->u.tmem.buf_ptr = 0; + return 0; + } + + rc = tee_shm_get_pa(p->u.memref.shm, p->u.memref.shm_offs, &pa); + if (rc) + return rc; + + mp->u.tmem.buf_ptr = pa; + mp->attr |= OPTEE_MSG_ATTR_CACHE_PREDEFINED << + OPTEE_MSG_ATTR_CACHE_SHIFT; + + return 0; +} + +static int to_msg_param_reg_mem(struct optee_msg_param *mp, + const struct tee_param *p) +{ + mp->attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT + p->attr - + TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + + mp->u.rmem.shm_ref = (unsigned long)p->u.memref.shm; + mp->u.rmem.size = p->u.memref.size; + mp->u.rmem.offs = p->u.memref.shm_offs; + return 0; +} + /** * optee_to_msg_param() - convert from struct tee_params to OPTEE_MSG parameters * @msg_params: OPTEE_MSG parameters @@ -116,7 +183,6 @@ int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params, { int rc; size_t n; - phys_addr_t pa; for (n = 0; n < num_params; n++) { const struct tee_param *p = params + n; @@ -139,22 +205,12 @@ int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params, case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: - mp->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT + - p->attr - - TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; - mp->u.tmem.shm_ref = (unsigned long)p->u.memref.shm; - mp->u.tmem.size = p->u.memref.size; - if (!p->u.memref.shm) { - mp->u.tmem.buf_ptr = 0; - break; - } - rc = tee_shm_get_pa(p->u.memref.shm, - p->u.memref.shm_offs, &pa); + if (tee_shm_is_registered(p->u.memref.shm)) + rc = to_msg_param_reg_mem(mp, p); + else + rc = to_msg_param_tmp_mem(mp, p); if (rc) return rc; - mp->u.tmem.buf_ptr = pa; - mp->attr |= OPTEE_MSG_ATTR_CACHE_PREDEFINED << - OPTEE_MSG_ATTR_CACHE_SHIFT; break; default: return -EINVAL; -- 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: [PATCH v1 08/14] tee: optee: add registered shared parameters handling Date: Thu, 28 Sep 2017 21:04:05 +0300 [thread overview] Message-ID: <1506621851-6929-9-git-send-email-volodymyr_babchuk@epam.com> (raw) In-Reply-To: <1506621851-6929-1-git-send-email-volodymyr_babchuk@epam.com> From: Volodymyr Babchuk <vlad.babchuk@gmail.com> Now, when client applications can register own shared buffers in OP-TEE, we need to extend ABI for parameter passing to/from OP-TEE. So, if OP-TEE core detects that parameter belongs to registered shared memory, it will use corresponding parameter attribute. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> --- drivers/tee/optee/core.c | 86 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 4d448bf..a962f60 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -97,6 +97,33 @@ int optee_from_msg_param(struct tee_param *params, size_t num_params, return rc; } break; + case OPTEE_MSG_ATTR_TYPE_RMEM_INPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_INOUT: + p->attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT + + attr - OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; + p->u.memref.size = mp->u.rmem.size; + shm = (struct tee_shm *)(unsigned long) + mp->u.rmem.shm_ref; + + if (!shm) { + p->u.memref.shm_offs = 0; + p->u.memref.shm = NULL; + break; + } + p->u.memref.shm_offs = mp->u.rmem.offs; + p->u.memref.shm = shm; + + /* Check that the memref is covered by the shm object */ + if (p->u.memref.size) { + size_t o = p->u.memref.shm_offs + + p->u.memref.size; + + if (o > tee_shm_get_size(shm)) + return -EINVAL; + } + break; + default: return -EINVAL; } @@ -104,6 +131,46 @@ int optee_from_msg_param(struct tee_param *params, size_t num_params, return 0; } +static int to_msg_param_tmp_mem(struct optee_msg_param *mp, + const struct tee_param *p) +{ + int rc; + phys_addr_t pa; + + mp->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT + p->attr - + TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + + mp->u.tmem.shm_ref = (unsigned long)p->u.memref.shm; + mp->u.tmem.size = p->u.memref.size; + + if (!p->u.memref.shm) { + mp->u.tmem.buf_ptr = 0; + return 0; + } + + rc = tee_shm_get_pa(p->u.memref.shm, p->u.memref.shm_offs, &pa); + if (rc) + return rc; + + mp->u.tmem.buf_ptr = pa; + mp->attr |= OPTEE_MSG_ATTR_CACHE_PREDEFINED << + OPTEE_MSG_ATTR_CACHE_SHIFT; + + return 0; +} + +static int to_msg_param_reg_mem(struct optee_msg_param *mp, + const struct tee_param *p) +{ + mp->attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT + p->attr - + TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + + mp->u.rmem.shm_ref = (unsigned long)p->u.memref.shm; + mp->u.rmem.size = p->u.memref.size; + mp->u.rmem.offs = p->u.memref.shm_offs; + return 0; +} + /** * optee_to_msg_param() - convert from struct tee_params to OPTEE_MSG parameters * @msg_params: OPTEE_MSG parameters @@ -116,7 +183,6 @@ int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params, { int rc; size_t n; - phys_addr_t pa; for (n = 0; n < num_params; n++) { const struct tee_param *p = params + n; @@ -139,22 +205,12 @@ int optee_to_msg_param(struct optee_msg_param *msg_params, size_t num_params, case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: - mp->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT + - p->attr - - TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; - mp->u.tmem.shm_ref = (unsigned long)p->u.memref.shm; - mp->u.tmem.size = p->u.memref.size; - if (!p->u.memref.shm) { - mp->u.tmem.buf_ptr = 0; - break; - } - rc = tee_shm_get_pa(p->u.memref.shm, - p->u.memref.shm_offs, &pa); + if (tee_shm_is_registered(p->u.memref.shm)) + rc = to_msg_param_reg_mem(mp, p); + else + rc = to_msg_param_tmp_mem(mp, p); if (rc) return rc; - mp->u.tmem.buf_ptr = pa; - mp->attr |= OPTEE_MSG_ATTR_CACHE_PREDEFINED << - OPTEE_MSG_ATTR_CACHE_SHIFT; break; default: return -EINVAL; -- 2.7.4
next prev parent reply other threads:[~2017-09-28 18:05 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 ` Volodymyr Babchuk [this message] 2017-09-28 18:04 ` [PATCH v1 08/14] tee: optee: add registered shared parameters handling 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 ` [RESEND PATCH v2 07/14] tee: optee: add shared buffer registration functions Volodymyr Babchuk 2017-11-29 12:48 ` 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=1506621851-6929-9-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.