Module Name: src
Committed By: martin
Date: Tue Aug 1 16:49:54 UTC 2023
Modified Files:
src/sys/dev/usb [netbsd-10]: xhci.c xhcivar.h
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #281):
sys/dev/usb/xhci.c: revision 1.177
sys/dev/usb/xhci.c: revision 1.180
sys/dev/usb/xhcivar.h: revision 1.24
xhci(4): Avoid crash in suspend/resume/resume if first resume fails.
Rather than try to recover from this, just make new commands fail so
at least we don't deadlock.
xhci(4): Don't panic on suspend if previous suspend/resume failed.
Trying to resume again probably won't make the situation much worse,
but panicking can definitely make it worse.
To generate a diff of this commit:
cvs rdiff -u -r1.175.2.1 -r1.175.2.2 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.22.2.1 -r1.22.2.2 src/sys/dev/usb/xhcivar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.175.2.1 src/sys/dev/usb/xhci.c:1.175.2.2
--- src/sys/dev/usb/xhci.c:1.175.2.1 Tue Aug 1 13:43:34 2023
+++ src/sys/dev/usb/xhci.c Tue Aug 1 16:49:54 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci.c,v 1.175.2.1 2023/08/01 13:43:34 martin Exp $ */
+/* $NetBSD: xhci.c,v 1.175.2.2 2023/08/01 16:49:54 martin Exp $ */
/*
* Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.175.2.1 2023/08/01 13:43:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.175.2.2 2023/08/01 16:49:54 martin Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -895,11 +895,13 @@ xhci_suspend(device_t self, const pmf_qu
out: mutex_exit(&sc->sc_rhlock);
if (!ok) {
/*
- * If suspend failed, resume command issuance.
+ * If suspend failed, stop holding up command issuance
+ * and make it fail instead.
*/
mutex_enter(&sc->sc_lock);
KASSERT(sc->sc_suspender == curlwp);
sc->sc_suspender = NULL;
+ sc->sc_suspendresume_failed = true;
cv_broadcast(&sc->sc_cmdbusy_cv);
mutex_exit(&sc->sc_lock);
}
@@ -917,7 +919,18 @@ xhci_resume(device_t self, const pmf_qua
XHCIHIST_FUNC(); XHCIHIST_CALLED();
+ /*
+ * If resume had previously failed, just try again. Can't make
+ * things worse, probably.
+ */
+ mutex_enter(&sc->sc_lock);
+ if (sc->sc_suspendresume_failed) {
+ KASSERT(sc->sc_suspender == NULL);
+ sc->sc_suspender = curlwp;
+ sc->sc_suspendresume_failed = false;
+ }
KASSERT(sc->sc_suspender);
+ mutex_exit(&sc->sc_lock);
/*
* Block roothub xfers which might touch portsc registers until
@@ -1111,6 +1124,7 @@ out: /*
mutex_enter(&sc->sc_lock);
KASSERT(sc->sc_suspender);
sc->sc_suspender = NULL;
+ sc->sc_suspendresume_failed = !ok;
cv_broadcast(&sc->sc_cmdbusy_cv);
mutex_exit(&sc->sc_lock);
@@ -3217,6 +3231,8 @@ xhci_do_command_locked(struct xhci_softc
while (sc->sc_command_addr != 0 ||
(sc->sc_suspender != NULL && sc->sc_suspender != curlwp))
cv_wait(&sc->sc_cmdbusy_cv, &sc->sc_lock);
+ if (sc->sc_suspendresume_failed)
+ return USBD_IOERROR;
/*
* If enqueue pointer points at last of ring, it's Link TRB,
Index: src/sys/dev/usb/xhcivar.h
diff -u src/sys/dev/usb/xhcivar.h:1.22.2.1 src/sys/dev/usb/xhcivar.h:1.22.2.2
--- src/sys/dev/usb/xhcivar.h:1.22.2.1 Tue Aug 1 13:43:34 2023
+++ src/sys/dev/usb/xhcivar.h Tue Aug 1 16:49:54 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: xhcivar.h,v 1.22.2.1 2023/08/01 13:43:34 martin Exp $ */
+/* $NetBSD: xhcivar.h,v 1.22.2.2 2023/08/01 16:49:54 martin Exp $ */
/*
* Copyright (c) 2013 Jonathan A. Kollasch
@@ -140,6 +140,7 @@ struct xhci_softc {
bool sc_resultpending;
bool sc_dying;
+ bool sc_suspendresume_failed;
struct lwp *sc_suspender;
void (*sc_vendor_init)(struct xhci_softc *);