From 36bd6bfdd104983c12bbe2d282f61f9cc5a8b8e5 Mon Sep 17 00:00:00 2001 From: Manorit Chawdhry Date: Wed, 16 Oct 2024 11:48:29 +0530 Subject: [PATCH] plat-k3: drivers: Track current_sequence in secure proxy 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 --- core/arch/arm/plat-k3/drivers/ti_sci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/arch/arm/plat-k3/drivers/ti_sci.c b/core/arch/arm/plat-k3/drivers/ti_sci.c index 84a986b1342..db8d4ad8914 100644 --- a/core/arch/arm/plat-k3/drivers/ti_sci.c +++ b/core/arch/arm/plat-k3/drivers/ti_sci.c @@ -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; @@ -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); @@ -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) {