mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dmaengine: pl330: Bound UNTIL loop
@ 2026-11-04 21:45 Eugen Hristev
  0 siblings, 0 replies; only message in thread
From: Eugen Hristev @ 2026-11-04 21:45 UTC (permalink / raw)
  To: Vinod Koul, Frank Li; +Cc: dmaengine, linux-kernel, Eugen Hristev

Bound UNTIL loop with a timeout.
It may happen that by accident pl330 will read/write a wrong address
and generate a bus fault. In such cases it will not complete the
condition that UNTIL waits for. To have the driver continue and not
hang, use a timeout.

Assisted-by: Github Copilot
Signed-off-by: Eugen Hristev <ehristev@kernel.org>
---
 drivers/dma/pl330.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index c2d0b473b8f4..9ced60fef9ff 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -248,8 +248,15 @@ enum pl330_byteswap {
  */
 #define MCODE_BUFF_PER_REQ	256
 
-/* Use this _only_ to wait on transient states */
-#define UNTIL(t, s)	while (!(_state(t) & (s))) cpu_relax();
+/* returns true if state reached within loop budget */
+#define UNTIL(t, s, loops) \
+	({ \
+		unsigned long _l = (loops); \
+		while (!(_state(t) & (s)) && _l) { \
+			cpu_relax(); _l--; \
+		 } \
+		!!(_state(t) & (s)); \
+	 })
 
 #ifdef PL330_DEBUG_MCGEN
 static unsigned cmd_line;
@@ -979,7 +986,8 @@ static void _stop(struct pl330_thread *thrd)
 	u32 inten = readl(regs + INTEN);
 
 	if (_state(thrd) == PL330_STATE_FAULT_COMPLETING)
-		UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
+		UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING,
+		      msecs_to_loops(5));
 
 	/* Return if nothing needs to be done */
 	if (_state(thrd) == PL330_STATE_COMPLETING
@@ -1059,12 +1067,24 @@ static bool _trigger(struct pl330_thread *thrd)
 
 static bool pl330_start_thread(struct pl330_thread *thrd)
 {
+	/* msecs_to_loops(5) gives the same budget used by _until_dmac_idle */
+	const unsigned long tout = msecs_to_loops(5);
+
 	switch (_state(thrd)) {
 	case PL330_STATE_FAULT_COMPLETING:
-		UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
+		if (!UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING,
+			   tout)) {
+			dev_err(thrd->dmac->ddma.dev,
+				"pl330: thread stuck in FAULT_COMPLETING\n");
+			return false;
+		}
 
 		if (_state(thrd) == PL330_STATE_KILLING)
-			UNTIL(thrd, PL330_STATE_STOPPED)
+			if (!UNTIL(thrd, PL330_STATE_STOPPED, tout)) {
+				dev_err(thrd->dmac->ddma.dev,
+					"pl330: thread stuck KILLING->STOPPED\n");
+				return false;
+			}
 		fallthrough;
 
 	case PL330_STATE_FAULTING:
@@ -1073,7 +1093,11 @@ static bool pl330_start_thread(struct pl330_thread *thrd)
 
 	case PL330_STATE_KILLING:
 	case PL330_STATE_COMPLETING:
-		UNTIL(thrd, PL330_STATE_STOPPED)
+		if (!UNTIL(thrd, PL330_STATE_STOPPED, tout)) {
+			dev_err(thrd->dmac->ddma.dev,
+				"pl330: thread stuck, not reaching STOPPED\n");
+			return false;
+		}
 		fallthrough;
 
 	case PL330_STATE_STOPPED:

---
base-commit: 6d0933ae9d46674a6ea63a87e9e9ab4e662670c9
change-id: 20261104-b4-pl330-until-8a287981ed5d

Best regards,
--  
Eugen Hristev <ehristev@kernel.org>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-04 21:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 21:45 [PATCH] dmaengine: pl330: Bound UNTIL loop Eugen Hristev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®