linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 1/1] firmware: arm_scmi: Fix possible deadlock in shmem_tx_prepare()
@ 2022-09-30  2:14 Yaxiong Tian
  2022-10-03 11:57 ` Cristian Marussi
  0 siblings, 1 reply; 8+ messages in thread
From: Yaxiong Tian @ 2022-09-30  2:14 UTC (permalink / raw)
  To: sudeep.holla, cristian.marussi, linux-arm-kernel, linux-kernel
  Cc: Yaxiong Tian, stable, Jim Quinlan

From: Yaxiong Tian <tianyaxiong@kylinos.cn>

In shmem_tx_prepare() ,it use spin_until_cond() to wait the chanel to be
free. Though it can avoid risk about overwriting the old command.But
when the platform has some problem in setting the chanel to free(such as
Improper initialization ),it can lead to the chanel never to be free.So
the os is sticked in it.In addition when shmem_tx_prepare() called,this
indicates that the previous transfer has commpleted or timed out.It
unsuitable for unconditional waiting the chanel to be free.

So for system stablility,we can add timeout condition in waiting the
chanel to be free.

Fixes: 9dc34d635c67 ("firmware: arm_scmi: Check if platform has released shmem before using")
Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
Cc: stable@vger.kernel.org
Cc: Sudeep Holla <sudeep.holla@arm.com>
Cc: Jim Quinlan <james.quinlan@broadcom.com>
---
 drivers/firmware/arm_scmi/shmem.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/arm_scmi/shmem.c b/drivers/firmware/arm_scmi/shmem.c
index 0e3eaea5d852..ae6110a81855 100644
--- a/drivers/firmware/arm_scmi/shmem.c
+++ b/drivers/firmware/arm_scmi/shmem.c
@@ -8,6 +8,7 @@
 #include <linux/io.h>
 #include <linux/processor.h>
 #include <linux/types.h>
+#include <linux/ktime.h>
 
 #include "common.h"
 
@@ -29,17 +30,27 @@ struct scmi_shared_mem {
 	u8 msg_payload[];
 };
 
+#define SCMI_MAX_TX_PREPARE_TIMEOUT_MS 30
+
 void shmem_tx_prepare(struct scmi_shared_mem __iomem *shmem,
 		      struct scmi_xfer *xfer)
 {
+	ktime_t stop = ktime_add_ms(ktime_get(), SCMI_MAX_TX_PREPARE_TIMEOUT_MS);
 	/*
 	 * Ideally channel must be free by now unless OS timeout last
 	 * request and platform continued to process the same, wait
 	 * until it releases the shared memory, otherwise we may endup
 	 * overwriting its response with new message payload or vice-versa
 	 */
-	spin_until_cond(ioread32(&shmem->channel_status) &
-			SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
+	spin_until_cond((ioread32(&shmem->channel_status) &
+			SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE) ||
+			ktime_after(ktime_get(), stop));
+
+	if (unlikely(ktime_after(ktime_get(), stop))) {
+		pr_err("timed out in shmem_tx_prepare(caller: %pS).\n",
+					(void *)_RET_IP_);
+	}
+
 	/* Mark channel busy + clear error */
 	iowrite32(0x0, &shmem->channel_status);
 	iowrite32(xfer->hdr.poll_completion ? 0 : SCMI_SHMEM_FLAG_INTR_ENABLED,
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-10-28 14:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30  2:14 [PATCH -next 1/1] firmware: arm_scmi: Fix possible deadlock in shmem_tx_prepare() Yaxiong Tian
2022-10-03 11:57 ` Cristian Marussi
     [not found]   ` <tencent_38B168A1B211AC1C3F5BAACEB5DF9992E107@qq.com>
2022-10-11 14:14     ` Cristian Marussi
2022-10-13  7:05       ` YaxiongTian
2022-10-13 16:02         ` Cristian Marussi
2022-10-14 11:56           ` Sudeep Holla
2022-10-14 12:23             ` Cristian Marussi
2022-10-28 14:14               ` Cristian Marussi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).