mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-17 10:04:26 +00:00
Merge changes from topic "ffa_el3_spmc_fixes" into integration
* changes: fix(tsp): fix destination ID in direct request fix(el3-spm): fix LSP direct message response fix(el3-spm): improve direct messaging validation
This commit is contained in:
commit
0ad935f72a
5 changed files with 103 additions and 8 deletions
|
@ -91,7 +91,7 @@ static int ffa_test_relay(uint64_t arg0,
|
|||
smc_args_t ffa_forward_result;
|
||||
ffa_endpoint_id16_t receiver = arg5;
|
||||
|
||||
ffa_forward_result = ffa_msg_send_direct_req(ffa_endpoint_source(arg1),
|
||||
ffa_forward_result = ffa_msg_send_direct_req(tsp_id,
|
||||
receiver,
|
||||
FF_A_ECHO_MESSAGE, arg4,
|
||||
0, 0, 0);
|
||||
|
|
|
@ -27,6 +27,7 @@ static uint64_t handle_ffa_direct_request(uint32_t smc_fid, bool secure_origin,
|
|||
void *handle, uint64_t flags)
|
||||
{
|
||||
uint64_t ret;
|
||||
uint32_t src_dst;
|
||||
|
||||
/* Determine if we have a 64 or 32 direct request. */
|
||||
if (smc_fid == FFA_MSG_SEND_DIRECT_REQ_SMC32) {
|
||||
|
@ -36,18 +37,22 @@ static uint64_t handle_ffa_direct_request(uint32_t smc_fid, bool secure_origin,
|
|||
} else {
|
||||
panic(); /* Unknown SMC. */
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle the incoming request. For testing purposes we echo the
|
||||
* incoming message.
|
||||
*/
|
||||
INFO("Logical Partition: Received Direct Request from %s world!\n",
|
||||
secure_origin ? "Secure" : "Normal");
|
||||
INFO("LSP: Received Direct Request from %s world (0x%x)\n",
|
||||
secure_origin ? "Secure" : "Normal", ffa_endpoint_source(x1));
|
||||
|
||||
/* Populate the source and destination IDs. */
|
||||
src_dst = (uint32_t) LP_PARTITION_ID << FFA_DIRECT_MSG_SOURCE_SHIFT |
|
||||
ffa_endpoint_source(x1) << FFA_DIRECT_MSG_DESTINATION_SHIFT;
|
||||
/*
|
||||
* Logical SP's must always send a direct response so we can populate
|
||||
* our response directly.
|
||||
*/
|
||||
SMC_RET8(handle, ret, 0, 0, x4, 0, 0, 0, 0);
|
||||
SMC_RET8(handle, ret, src_dst, 0, x4, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* Register logical partition */
|
||||
|
|
|
@ -131,6 +131,9 @@ struct sp_exec_ctx {
|
|||
|
||||
/* Track the current runtime model of the SP. */
|
||||
enum sp_runtime_model rt_model;
|
||||
|
||||
/* Track the source partition ID to validate a direct response. */
|
||||
uint16_t dir_req_origin_id;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -259,6 +259,65 @@ static inline bool direct_msg_validate_arg2(uint64_t x2)
|
|||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Helper function to validate the destination ID of a direct response.
|
||||
******************************************************************************/
|
||||
static bool direct_msg_validate_dst_id(uint16_t dst_id)
|
||||
{
|
||||
struct secure_partition_desc *sp;
|
||||
|
||||
/* Check if we're targeting a normal world partition. */
|
||||
if (ffa_is_normal_world_id(dst_id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Or directed to the SPMC itself.*/
|
||||
if (dst_id == FFA_SPMC_ID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Otherwise ensure the SP exists. */
|
||||
sp = spmc_get_sp_ctx(dst_id);
|
||||
if (sp != NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Helper function to validate the response from a Logical Partition.
|
||||
******************************************************************************/
|
||||
static bool direct_msg_validate_lp_resp(uint16_t origin_id, uint16_t lp_id,
|
||||
void *handle)
|
||||
{
|
||||
/* Retrieve populated Direct Response Arguments. */
|
||||
uint64_t x1 = SMC_GET_GP(handle, CTX_GPREG_X1);
|
||||
uint64_t x2 = SMC_GET_GP(handle, CTX_GPREG_X2);
|
||||
uint16_t src_id = ffa_endpoint_source(x1);
|
||||
uint16_t dst_id = ffa_endpoint_destination(x1);
|
||||
|
||||
if (src_id != lp_id) {
|
||||
ERROR("Invalid EL3 LP source ID (0x%x).\n", src_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the destination ID is valid and ensure the LP is responding to
|
||||
* the original request.
|
||||
*/
|
||||
if ((!direct_msg_validate_dst_id(dst_id)) || (dst_id != origin_id)) {
|
||||
ERROR("Invalid EL3 LP destination ID (0x%x).\n", dst_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!direct_msg_validate_arg2(x2)) {
|
||||
ERROR("Invalid EL3 LP message encoding.\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Handle direct request messages and route to the appropriate destination.
|
||||
******************************************************************************/
|
||||
|
@ -272,6 +331,7 @@ static uint64_t direct_req_smc_handler(uint32_t smc_fid,
|
|||
void *handle,
|
||||
uint64_t flags)
|
||||
{
|
||||
uint16_t src_id = ffa_endpoint_source(x1);
|
||||
uint16_t dst_id = ffa_endpoint_destination(x1);
|
||||
struct el3_lp_desc *el3_lp_descs;
|
||||
struct secure_partition_desc *sp;
|
||||
|
@ -283,14 +343,29 @@ static uint64_t direct_req_smc_handler(uint32_t smc_fid,
|
|||
FFA_ERROR_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
/* Validate Sender is either the current SP or from the normal world. */
|
||||
if ((secure_origin && src_id != spmc_get_current_sp_ctx()->sp_id) ||
|
||||
(!secure_origin && !ffa_is_normal_world_id(src_id))) {
|
||||
ERROR("Invalid direct request source ID (0x%x).\n", src_id);
|
||||
return spmc_ffa_error_return(handle,
|
||||
FFA_ERROR_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
el3_lp_descs = get_el3_lp_array();
|
||||
|
||||
/* Check if the request is destined for a Logical Partition. */
|
||||
for (unsigned int i = 0U; i < MAX_EL3_LP_DESCS_COUNT; i++) {
|
||||
if (el3_lp_descs[i].sp_id == dst_id) {
|
||||
return el3_lp_descs[i].direct_req(
|
||||
smc_fid, secure_origin, x1, x2, x3, x4,
|
||||
cookie, handle, flags);
|
||||
uint64_t ret = el3_lp_descs[i].direct_req(
|
||||
smc_fid, secure_origin, x1, x2,
|
||||
x3, x4, cookie, handle, flags);
|
||||
if (!direct_msg_validate_lp_resp(src_id, dst_id,
|
||||
handle)) {
|
||||
panic();
|
||||
}
|
||||
|
||||
/* Message checks out. */
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,6 +407,7 @@ static uint64_t direct_req_smc_handler(uint32_t smc_fid,
|
|||
*/
|
||||
sp->ec[idx].rt_state = RT_STATE_RUNNING;
|
||||
sp->ec[idx].rt_model = RT_MODEL_DIR_REQ;
|
||||
sp->ec[idx].dir_req_origin_id = src_id;
|
||||
return spmc_smc_return(smc_fid, secure_origin, x1, x2, x3, x4,
|
||||
handle, cookie, flags, dst_id);
|
||||
}
|
||||
|
@ -370,7 +446,7 @@ static uint64_t direct_resp_smc_handler(uint32_t smc_fid,
|
|||
* Check that the response is either targeted to the Normal world or the
|
||||
* SPMC e.g. a PM response.
|
||||
*/
|
||||
if ((dst_id != FFA_SPMC_ID) && ffa_is_secure_world_id(dst_id)) {
|
||||
if (!direct_msg_validate_dst_id(dst_id)) {
|
||||
VERBOSE("Direct response to invalid partition ID (0x%x).\n",
|
||||
dst_id);
|
||||
return spmc_ffa_error_return(handle,
|
||||
|
@ -397,9 +473,18 @@ static uint64_t direct_resp_smc_handler(uint32_t smc_fid,
|
|||
return spmc_ffa_error_return(handle, FFA_ERROR_DENIED);
|
||||
}
|
||||
|
||||
if (sp->ec[idx].dir_req_origin_id != dst_id) {
|
||||
WARN("Invalid direct resp partition ID 0x%x != 0x%x on core%u.\n",
|
||||
dst_id, sp->ec[idx].dir_req_origin_id, idx);
|
||||
return spmc_ffa_error_return(handle, FFA_ERROR_DENIED);
|
||||
}
|
||||
|
||||
/* Update the state of the SP execution context. */
|
||||
sp->ec[idx].rt_state = RT_STATE_WAITING;
|
||||
|
||||
/* Clear the ongoing direct request ID. */
|
||||
sp->ec[idx].dir_req_origin_id = INV_SP_ID;
|
||||
|
||||
/*
|
||||
* If the receiver is not the SPMC then forward the response to the
|
||||
* Normal world.
|
||||
|
|
|
@ -83,6 +83,7 @@ static void spmc_cpu_on_finish_handler(u_register_t unused)
|
|||
/* Update the runtime model and state of the partition. */
|
||||
ec->rt_model = RT_MODEL_INIT;
|
||||
ec->rt_state = RT_STATE_RUNNING;
|
||||
ec->dir_req_origin_id = INV_SP_ID;
|
||||
|
||||
INFO("SP (0x%x) init start on core%u.\n", sp->sp_id, linear_id);
|
||||
|
||||
|
@ -132,6 +133,7 @@ static int32_t spmc_send_pm_msg(uint8_t pm_msg_type,
|
|||
/* Update the runtime model and state of the partition. */
|
||||
ec->rt_model = RT_MODEL_DIR_REQ;
|
||||
ec->rt_state = RT_STATE_RUNNING;
|
||||
ec->dir_req_origin_id = FFA_SPMC_ID;
|
||||
|
||||
rc = spmc_sp_synchronous_entry(ec);
|
||||
if (rc != 0ULL) {
|
||||
|
|
Loading…
Add table
Reference in a new issue