-
Notifications
You must be signed in to change notification settings - Fork 7
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
drivers: tee: optee: Use arch_page_phys_get for address conversion #83
drivers: tee: optee: Use arch_page_phys_get for address conversion #83
Conversation
ec20348
to
a2781b4
Compare
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.
You can't met a problem, but you can face it.
I am not sure that you need CONFIG_MMU
checks. OP-TEE driver will not work correctly without it anyways.
drivers/tee/optee/optee.c
Outdated
static uintptr_t optee_mem_phys_addr(void *virt) | ||
{ | ||
uintptr_t phys; | ||
uint32_t offt = (uintptr_t)virt % CONFIG_MMU_PAGE_SIZE; |
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.
It's a pity that zephyr does not provide PAGE_MASK
. I just hope that compiller will be smart enough to replace division with bitwise AND.
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.
fixed
drivers/tee/optee/optee.c
Outdated
unsigned long a4, unsigned long a5, unsigned long a6, unsigned long a7, | ||
struct arm_smccc_res *res) | ||
static void | ||
optee_smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3, |
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.
Spurious change
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.
removed
drivers/tee/optee/optee.c
Outdated
@@ -1113,7 +1146,7 @@ static int optee_suppl_send(const struct device *dev, unsigned int ret, unsigned | |||
break; | |||
case TEE_PARAM_ATTR_TYPE_MEMREF_OUTPUT: | |||
case TEE_PARAM_ATTR_TYPE_MEMREF_INOUT: | |||
LOG_WRN("Memref params are not fully tested"); | |||
/* LOG_WRN("Memcpyref params are not fully tested"); */ |
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.
Spurious change
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.
remove
dc6441d
to
dcf0c67
Compare
|
8fdb182
to
26502a4
Compare
According to the description of z_mem_phys_addr it uses Z_MEM_VM_OFFSET to make a conversion from virtual to physical address. And these macros are intended for assembly, linker code, and static initializers. So when external libraries, such as PICOLIBC or NEWLIB_LIBC uses internal mappings for dynamic memory allocation z_mem_phys_addr may not work properly and return wrong physical address. We encountered this problem while testing the generation of a certificate using PKCS11 in libckteec with MBEDTLS. Mbedtls allocates buffer dynamically and ivokes tee command to request certificate from PKCS11 TA which should place result to the allocated buffer. The result is the MBEDTLS is used with minimal libc - then everything works fine. But when CONFIG_PICOLIBC or CONFIG_NEWLIB_LIBC is enabled - it returns empty buffer. This happens because z_mem_phys_addr returns incorrect physical address. Signed-off-by: Oleksii Moisieiev <[email protected]> Reviewed-by: Volodymyr Babchuk <[email protected]>
26502a4
to
81cbffd
Compare
According to the description of z_mem_phys_addr it uses Z_MEM_VM_OFFSET to make a conversion from virtual to physical address. And these macros are intended for assembly, linker code, and static initializers.
So when external libraries, such as PICOLIBC or NEWLIB_LIBC uses internal mappings for dynamic memory allocation z_mem_phys_addr may not work properly and return wrong physical address.
We have met this problem when testing work with MBEDTLS to generate certificate using PKCS11 in libckteec.
Mbedtls allocates buffer dynamically and ivokes tee command to request certificate from PKCS11 TA which should place result to the allocated buffer.
The result is the MBEDTLS is used with minimal libc - then everything works fine. But when CONFIG_PICOLIBC or CONFIG_NEWLIB_LIBC is enabled