Thread (26 messages) 26 messages, 6 authors, 2022-01-25

Re: earlyprintk=xdbc seems broken

From: Greg KH <gregkh@linuxfoundation.org>
Date: 2021-12-20 15:08:50
Also in: lkml

On Mon, Dec 20, 2021 at 03:40:17PM +0100, Peter Zijlstra wrote:
quoted hunk ↗ jump to hunk
On Fri, Dec 17, 2021 at 04:19:20PM +0100, Greg KH wrote:
quoted
On Fri, Dec 17, 2021 at 02:55:07PM +0100, Peter Zijlstra wrote:
quoted
On Fri, Dec 17, 2021 at 01:01:43PM +0200, Mathias Nyman wrote:
quoted
I can reproduce this.
Looks like problems started when driver converted to readl_poll_timeout_atomic() in:

796eed4b2342 usb: early: convert to readl_poll_timeout_atomic()
I can confirm, reverting that solves the boot hang, things aren't quite
working for me though.
quoted
Seems to hang when read_poll_timeout_atomic() calls ktime_* functions.
Maybe  it's too early for ktime.
It certainly is, using ktime for delay loops sounds daft to me anyhow.
It was a "find a pattern and replace it with a function call" type of
cleanup series.  It's obviously wrong, I will go revert it now.
796eed4b2342 is definitely wrong, but instead of a straight up revert,
perhaps do something like this ?

---
Subject: usb: early: Revert from readl_poll_timeout_atomic()

Reverts commit 796eed4b2342 ("usb: early: convert to
readl_poll_timeout_atomic()") and puts in a comment to avoid the same
happening again.

Specifically that commit is wrong because readl_poll_timeout_atomic()
relies on ktime() working while this earlyprintk driver should be usable
long before that.

Fixes: 796eed4b2342 ("usb: early: convert to readl_poll_timeout_atomic()")
Debugged-by: Mathias Nyman [off-list ref]
Signed-off-by: Peter Zijlstra (Intel) <redacted>
---
 drivers/usb/early/xhci-dbc.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
index 933d77ad0a64..ff279a830653 100644
--- a/drivers/usb/early/xhci-dbc.c
+++ b/drivers/usb/early/xhci-dbc.c
@@ -14,7 +14,6 @@
 #include <linux/pci_ids.h>
 #include <linux/memblock.h>
 #include <linux/io.h>
-#include <linux/iopoll.h>
 #include <asm/pci-direct.h>
 #include <asm/fixmap.h>
 #include <linux/bcd.h>
@@ -136,9 +135,20 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done, int wait, int delay)
 {
 	u32 result;
 
-	return readl_poll_timeout_atomic(ptr, result,
-					 ((result & mask) == done),
-					 delay, wait);
+	/*
+	 * This must not be readl_poll_timeout_atomic(), as this is used
+	 * *early*, before ktime lives.
+	 */
+	do {
+		result = readl(ptr);
+		result &= mask;
+		if (result == done)
+			return 0;
+		udelay(delay);
+		wait -= delay;
+	} while (wait > 0);
+
+	return -ETIMEDOUT;
 }
 
 static void __init xdbc_bios_handoff(void)
Please see c4d936efa46d ("Revert "usb: early: convert to
readl_poll_timeout_atomic()"") in Linus's tree.  I already added a
comment much like yours.  If that's not sufficient, I'll be glad to
re-word it.

thanks,

greg k-h
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help