Skip to content

Commit

Permalink
plat-k3: drivers: Track current_sequence in secure proxy
Browse files Browse the repository at this point in the history
Currently ti_sci_do_xfer layer and ti_sci_setup_xfer both use the same
shared resource message_sequence. However, If ti_sci_setup_xfer and
ti_sci_do_xfer are in different critical sections and the value of
message_sequence can change between both of them causing the message
validation to fail with following.

"Message with Sequence ID <> not expected".

The proper way to handle this would be a queuing model or putting both
of them in single critical section but that would require some major
refactor or require modifying every ti_sci call.

Tracking the message that is being sent over the secure proxy separately
is something that is also doable and would avoid the race condition
without a queuing model.

Extract the message_sequence from the current message being sent over
secure proxy and check that against the receiving response.

Signed-off-by: Manorit Chawdhry <m-chawdhry@ti.com>
  • Loading branch information
manorit2001 committed Oct 23, 2024
1 parent 6df1d28 commit 36bd6bf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/arch/arm/plat-k3/drivers/ti_sci.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ti_sci_protocol.h"

static uint8_t message_sequence;
static uint8_t current_sequence;
static struct mutex ti_sci_mutex_lock = MUTEX_INITIALIZER;
static unsigned int ti_sci_spin_lock = SPINLOCK_UNLOCK;

Expand Down Expand Up @@ -116,7 +117,7 @@ static inline int ti_sci_get_response(struct ti_sci_xfer *xfer)
hdr = (struct ti_sci_msg_hdr *)msg->buf;

/* Sanity check for message response */
if (hdr->seq == message_sequence)
if (hdr->seq == current_sequence)
break;

IMSG("Message with sequence ID %u is not expected", hdr->seq);
Expand Down Expand Up @@ -144,10 +145,14 @@ static inline int ti_sci_get_response(struct ti_sci_xfer *xfer)
static inline int ti_sci_do_xfer(struct ti_sci_xfer *xfer)
{
struct k3_sec_proxy_msg *msg = &xfer->tx_message;
struct ti_sci_msg_hdr *hdr = NULL;
int ret = 0;

mutex_lock(&ti_sci_mutex_lock);

hdr = (struct ti_sci_msg_hdr *)msg->buf;
current_sequence = hdr->seq;

/* Send the message */
ret = k3_sec_proxy_send(msg);
if (ret) {
Expand Down

0 comments on commit 36bd6bf

Please sign in to comment.