-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tee_client_api: register user memory #72
Conversation
why registering the shared memory to the optee secure world ? |
@etienne-lms, Idea is not to use preshared pool. There are many reasons:
If client can use part of own memory for shared buffers, than all issues above can be solved easily. |
ok, i see your idea. And it is true that many buffer parameters can be provided to TAs without copies to the current single physically contiguous 'non secure shared memory area'. I wonder why nonsecure should register shared buffers to the secure side. If non-secure wishes to check if a buffer is ok to be used as shared mem, then it's fine, but this is not mandatory and waste cpu cycles. Non-secure could simply invoke the secure side with the memref parameters. On secure side, we don't care if non-secure presents a shared memory area as "non-secure". Secure side will simply verify the shared memory area conformance against TA memref permissions. And maps it accordingly. As far a nonsecure handle shared memory allocation, it is nonsecure world responsibility to track these memref, not the secure side. |
For a one shot invocation it's more efficient to do as you say @etienne-lms, but then for a single invocation performance isn't as critical as there's so much else that eats CPU time, checking the RSA signature of the TA for instance. If we make multiple invocations it quickly pays off to have the shared memory registered in advance as it's represented by a single handle instead of a long list of physical pages. Another advantage with always using registered memory is that we then can get rid of yet another way of describing a chunk of memory. |
@etienne-lms And, speaking about my benchmarking task it's kind of a life saver. I can easily, with minimum amount of code changes, move to this SHM API instead of using GP params :) |
|
late feedback... nice indeed. |
Same here, late reply, all good. But I'd be nice to have our https://github.com/OP-TEE/optee_os/blob/master/documentation/optee_design.md#7-shared-memory updated to reflect the changes (and the current implementation).
|
Hi @lorc, would you please rebase this patch on top of the current master branch and add the R-b tags so that I can pick it up? |
@jforissier I planed to wait till corresponding patches to OP-TEE kernel and OP-TEE driver will be ready for merge. But, actually you are right. This patch can be merged at any time. It is rebased on current |
@lorc thanks for rebasing. Actually, I'm not sure I want to merge this immediately since it depends on PRs that are still pending in optee_os and the linux driver. I'd rather wait until all 3 PRs are reviewed. Sorry I didn't realize this when I wrote the above ;) |
Hello. I have rebased it again. Also I have added new patch that makes supplicant to register own memory instead of allocating it thru SHM pool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 main potential issue to crosscheck: closing a fd on a
minor: typo in the commit message of the 2nd commit:
-If OP-TEE and kernel supports registereted shared memory
+If OP-TEE and kernel support registered shared memory
tee-supplicant/src/tee_supplicant.c
Outdated
if (munmap(shm->p, shm->size) != 0) { | ||
EMSG("munmap(%p, %zu) failed - Error = %s", | ||
shm->p, shm->size, strerror(errno)); | ||
free(shm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should also close(shm->fd);
tee-supplicant/src/tee_supplicant.c
Outdated
@@ -99,6 +101,8 @@ static struct tee_shm *shm_head; | |||
|
|||
static const char *ta_dir; | |||
|
|||
static uint32_t gen_caps = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: useless init
tee-supplicant/src/tee_supplicant.c
Outdated
if (num_params != 1 || get_value(num_params, params, 0, &val)) | ||
return TEEC_ERROR_BAD_PARAMETERS; | ||
|
||
if (gen_caps & TEE_GEN_CAP_REG_MEM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be possible to rely on ctx->reg_mem
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenswi-linaro I'm not sure that I understood you. ctx->reg_mem
is a kernel thing, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry is was confusing this with how we use TEEC_Context
in libteec.
Using global variables should in general be avoided, this gen_caps
should be stored together with the file descriptor as gen_caps
is holds information specific for this file descriptor.
75049dc
to
190409b
Compare
@jenswi-linaro, I want ask you about interface between optee client and kernel driver. |
So the difference between Why would we need |
Exactly.
Because current |
Why do we need a way for userspace to control if buffers passed to secure world are registered in secure world or not? |
I thought that |
OK, if I understand it correctly it's something that doesn't need to be done now. It sounds like some optimization that could be useful but we need to know that it's actually is needed before we do something about it as it complicates things further a tiny bit. But we should right now make sure that if we choose to implement this later that the current ABI can be easily extended to deal with it. The flags field in |
Ah, I see. Yes. You can think about this as an optimization. It needs extensions in I have tested ABI between NW and SW and it supports this use-case. I can share my patches for client library, kernel driver and |
Right now I'd like to focus on getting the current stuff in place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 minor comments
libteec/include/linux/tee.h
Outdated
@@ -145,6 +146,36 @@ struct tee_ioctl_shm_register_fd_data { | |||
struct tee_ioctl_shm_register_fd_data) | |||
|
|||
/** | |||
* struct tee_shm_register_data - Shared memory register argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/tee_shm_register_data
/tee_ioctl_shm_register_data
/
libteec/src/tee_client_api.c
Outdated
@@ -34,6 +34,7 @@ | |||
#include <fcntl.h> | |||
#include <limits.h> | |||
#include <pthread.h> | |||
#include <stdlib.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: move after stdbool.h. Can you fix order of these #include <stXXX.h>
.
Hello. I rebased this PR onto current master. There was conflicts in Also I have addressed @jenswi-linaro's comment regarding global |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With or without my comment addressed
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
libteec/src/tee_client_api.c
Outdated
if (fd >= 0) { | ||
ctx->fd = fd; | ||
ctx->reg_mem = !!(gen_caps & TEE_GEN_CAP_REG_MEM); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to normalize the bool
explicitly as the compiler already is required to do that.
289b1f7
to
6cd81d5
Compare
Pushed fix for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some more...
r-b applies anyway...
@@ -49,6 +49,7 @@ | |||
#define TEE_MAX_ARG_SIZE 1024 | |||
|
|||
#define TEE_GEN_CAP_GP (1 << 0)/* GlobalPlatform compliant TEE */ | |||
#define TEE_GEN_CAP_REG_MEM (1 << 2)/* Supports registering shared memory */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you are so patient, would you mind adding a tabulation before these comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do this in a separate patch, okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you like. (sorry to ask you to :)
libteec/include/linux/tee.h
Outdated
}; | ||
|
||
/** | ||
* TEE_IOC_SHM_REGISTER - Register shared memory argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: remove argument
tee-supplicant/src/tee_supplicant.c
Outdated
shm = alloc_shm(arg->fd, val->b); | ||
|
||
if (!shm) { | ||
return TEEC_ERROR_OUT_OF_MEMORY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: remove {
/}
?
Addressed @etienne-lms's comments. Added separate patch that fixes comments in BTW, I'm sorry that my English is far from perfect. Feel free to correct me, especially if my mistakes are terrible :) |
Same with me, so do not hesitate to contradict/correct me. |
r-b on the whole. |
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Igor Opaniuk <igor.opaniuk@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
If OP-TEE and kernel support registereted shared memory, then supplicant will use this feature instead of using shared memory pool. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Thanks, @etienne-lms. I have squashed all fixes and added your r-b tag. |
Later is fine with me a least. |
Okay, so I dropped this patch for now. Will push it as a separate PR after this one will be merged. |
This patch is the userspace part of dynamic shared memory in OP-TEE (refer to OP-TEE/optee_os#1232). This patch is authred by @jenswi-linaro, I just tidied it a bit and rebased on current master.
This patch utilizes new ioctl that allows client application to share any buffer with OP-TEE.