Skip to content

Commit 9dc34d6

Browse files
committed
firmware: arm_scmi: Check if platform has released shmem before using
Sometimes platfom may take too long to respond to the command and OS might timeout before platform transfer the ownership of the shared memory region to the OS with the response. Since the mailbox channel associated with the channel is freed and new commands are dispatch on the same channel, OS needs to wait until it gets back the ownership. If not, either OS may end up overwriting the platform response for the last command(which is fine as OS timed out that command) or platform might overwrite the payload for the next command with the response for the old. The latter is problematic as platform may end up interpretting the response as the payload. In order to avoid such race, let's wait until the OS gets back the ownership before we prepare the shared memory with the payload for the next command. Reported-by: Jim Quinlan <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent 5b65af8 commit 9dc34d6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/firmware/arm_scmi/driver.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)
265265
struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
266266
struct scmi_shared_mem __iomem *mem = cinfo->payload;
267267

268+
/*
269+
* Ideally channel must be free by now unless OS timeout last
270+
* request and platform continued to process the same, wait
271+
* until it releases the shared memory, otherwise we may endup
272+
* overwriting its response with new message payload or vice-versa
273+
*/
274+
spin_until_cond(ioread32(&mem->channel_status) &
275+
SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
268276
/* Mark channel busy + clear error */
269277
iowrite32(0x0, &mem->channel_status);
270278
iowrite32(t->hdr.poll_completion ? 0 : SCMI_SHMEM_FLAG_INTR_ENABLED,

0 commit comments

Comments
 (0)