GCC/Release: Compiler optimizes tfm_core_ns_ipc_request() too much
Open, HighPublic

Description

tfm_core_ns_ipc_request() in tfm_psa_api_client.c has an inline assembly block which calls SVC with the arguments inside a descriptor struct.
In GCC release the compiler optimizes the code (probably ignores the inline assembly code) and throws the part where the arguments are set inside the descriptor struct.
The result is that the descriptor is all zeroes and sent to the SVC via r0.

Eventually in the SVC handler tfm_psa_veneer_sanity_check() is called which returns TFM_ERROR_INVALID_PARAMETER (becasue desc_ptr->ns_caller is 0).

mikisch81 created this task.Feb 5 2019, 7:58 AM
mikisch81 added a subscriber: KenLSoft.

A workaround for us which fixed this issue was setting the descriptor struct volatile:

volatile struct tfm_sfn_req_s desc;
struct tfm_sfn_req_s *desc_ptr = &desc;
adeaarm claimed this task.Wed, Apr 17, 9:22 AM
adeaarm triaged this task as High priority.Wed, Apr 17, 9:42 AM

This is currently merged in the master branch. I am keeping the issue open for some more time in case any other external party needs to report/track the issue in their platforms/setup, I will then close if if no more occurrences of this are reported.