-
Notifications
You must be signed in to change notification settings - Fork 1.5k
drivers/misc/optee: expand RPC suppport for IMX9 #16734
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
Conversation
e899675 to
6197ac9
Compare
|
@tkaratapanis have you run nuttx on Cortex-A55 on i.MX95 EVB successfully? |
No, currently I am working only on i.MX93 |
d7521a6 to
556c844
Compare
jerpelea
left a comment
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.
please add a commit message on the
"drivers/misc/optee: Add virtual and physical address to sturct optee_shm " patch
556c844 to
81cf557
Compare
81cf557 to
370cc0f
Compare
e4adaf4 to
b3caa99
Compare
de9d22a to
46c9da8
Compare
9e9d0e9 to
cb36095
Compare
The VA -> PA translation must be performed once, at allocation time, while the caller's virtual address space is known. If a second process later tries to translate the same VA from a different mapping, the calculated physical address can be wrong. Signed-off-by: Theodore Karatapanis <tkaratapanis@census-labs.com>
cb36095 to
ed827de
Compare
ed827de to
a2fd80c
Compare
a2fd80c to
838d596
Compare
The previous approach with memfd has 3 problems: 1) The close operation on the memfd isn't tied with optee_shm_close, therefore close(fd) doesn't free the optee_shm struct allocated by the kernel. 2) The kernel unnecessarily maps the file descriptor to its memory, however only userspace should need to do that. 3) Since the kernel doesn't need to map the file descriptor we don't need to unmap it. To use anonymous mapping, the prototype of map_anonymous() was moved from fs/mmap/fs_anonmap.h to include/nuttx/fs/fs.h. Since fs_anonmap.h didn't contain any other information it is deleted. A type from fs/mmap/fs_rammap.h was moved to the public : include/nuttx/fs/fs.h as well. Signed-off-by: Theodore Karatapanis <tkaratapanis@census-labs.com>
9183ece to
53c043b
Compare
This commit expands RPC support for the OP-TEE driver using 2 files:
1) drivers/misc/optee_rpc.c
* Add support for RPCs that can be handled directly by the kernel.
* Can delegate RPC handling to optee_supplicant.c for RPCs that
need userspace interaction.
2) drivers/misc/optee_supplicant.c
* Enable communication between the userspace TEE supplicant and the
kernel driver.
Additional changes were needed to the following files:
1) drivers/misc/optee.c
* Add ioctls used SOLELY by the userspace TEE supplicant.
* Register /dev/teepriv0 if the supplicant is enabled in Kconfig
* Add OPTEE_ROLE_CA and OPTEE_ROLE_SUPPLICANT conditionals to
differentiate paths, between a normal Client Application (CA)
and the TEE supplicant.
* Change some functions from static to "public" to reuse them
in other C files.
* Adjust optee_to/from_msg_param() to work with RPCs.
2) drivers/misc/optee_smc.c
* Call the RPC handler from optee_rpc.c
3) drivers/misc/optee_msg.h
* Add definition needed for RPCs
4) drivers/misc/tee.h
* Add ioctl definitions
* Add TEE_SHM_SUPP flag, checked when unregistering supplicant
memory.
5) Documentation/guides/optee.rs
* Add documentation for RPCs and the supplicant.
6) drivers/misc/{CMakeLists.txt, Make.defs}
* Account for the new files.
7) drivers/misc/Kconfig
* Add DEV_OPTEE_SUPPLICANT option to enable/disable the supplicant
driver.
Signed-off-by: Theodore Karatapanis <tkaratapanis@census-labs.com>
This commit simplifies sending errors back to OP-TEE and avoids code duplication when handling errno values. Signed-off-by: Theodore Karatapanis <tkaratapanis@census-labs.com>
53c043b to
dab4af3
Compare
Summary
Currently the OP-TEE driver has bare minimum support of RPCs (Invokations of nuttx from OP-TEE), just enough to establish sessions. This PR aims to handle a group of RPCs
OPTEE_SMC_RPC_FUNC_CMD, presently ignored.The newly supported RPCs can be handled either directly by the kernel and the code in
./drivers/misc/optee_rpc.cor they might be delegated to userspace through./drivers/misc/optee_supplicant.c.The userspace support requires 2 extra commands to be handled by the ioctl handler,
TEE_IOC_SUPPL_RECVandTEE_IOC_SUPPL_SEND. These commands must be invoked only by the TEE supplicant and not a regular nuttx Client Application (CA). A system can have multiple CAs (opens/dev/tee0) but only one TEE supplicant (opens/dev/teepriv0).The newly supported RPCs provide:
To support the supplicant, a new device (
/dev/teepriv0) is registered by the OP-TEE driver ifCONFIG_DEV_OPTEE_SUPPLICANTis enabled. This device can be opened only by one user or it returns-EBUSY, it maintains a separate shared memory list and its entries can be queried by other CAs.The introduction of the supplicant logic, also requires to maintain in the
struct optee_shmboth the virtual address.vaddrand physical.paddr. The translation happens by the process who allocates that memory, since a CA and the supplicant have different memory mappings (different processes).Impact
If
CONFIG_DEV_OPTEE_SUPPLICANTis disabled (default) the code should work as it works now with the addition of kernel handled RPCs by./driver/misc/optee_rpc.c(1-4 as listed in the summary section).If
CONFIG_DEV_OPTEE_SUPPLICANTis enabled and nuttx can run a TEE supplicant then services like secure storage can be provided to OP-TEE.Testing
The tests happened in a custom imx9 board that runs TF-A (bl31) and OP-TEE (bl32) together with nuttx (bl33).
Since there is minimal support for OP-TEE interacting applications, the existing functionality was tested by running the
optee_gpexample:To test the supplicant functionality the code from https://github.com/OP-TEE/optee_client/tree/master/tee-supplicant was integrated with nuttx in a private fork. Also a testing CA (nuttx) and TA (OP-TEE) were developed that worked in unison to test secure storage. The test scenario is as follows:
145f361e-40f3-11ee-be56-0242ac120002to create a file and write a known payload to it ("Secure OP-TEE data").The files created by OP-TEE are encrypted (with a key only known to OP-TEE) under the directory we provided the TEE supplicant:
/data/tee. We can however list the created files (besidesdirf.dbother OP-TEE filenames are not really known to nuttx):