Page MenuHomePhabricator

GCC/Release: Compiler optimizes tfm_core_ns_ipc_request() too much
Closed, ResolvedPublic

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).

Event Timeline

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.Apr 17 2019, 9:22 AM
adeaarm triaged this task as High priority.Apr 17 2019, 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.

adeaarm edited projects, added Restricted Project; removed Trusted Firmware M.Apr 24 2019, 7:45 PM
adeaarm moved this task from Restricted Project Column to Restricted Project Column on the Restricted Project board.Apr 24 2019, 7:56 PM
adeaarm moved this task from Restricted Project Column to Restricted Project Column on the Restricted Project board.
adeaarm closed this task as Resolved.Apr 26 2019, 5:14 PM