diff options
| author | riastradh <riastradh@NetBSD.org> | 2023-04-09 20:41:28 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2023-04-09 20:41:28 +0000 |
| commit | 8952ed0af0594edd8c00010fe7f92adc95f64b6a (patch) | |
| tree | c98499d28ae789fb5bd35ccdb81c0a01bfbd8904 | |
| parent | 700f23f78f5c2bbea16a2c713a570f700d855273 (diff) | |
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.
XXX pullup-9
XXX pullup-10
| -rw-r--r-- | sys/dev/usb/xhci.c | 23 | ||||
| -rw-r--r-- | sys/dev/usb/xhcivar.h | 3 |
2 files changed, 22 insertions, 4 deletions
diff --git a/sys/dev/usb/xhci.c b/sys/dev/usb/xhci.c index c64b51580fb..96b6d69efb1 100644 --- a/sys/dev/usb/xhci.c +++ b/sys/dev/usb/xhci.c @@ -1,4 +1,4 @@ -/* $NetBSD: xhci.c,v 1.176 2023/04/07 09:39:48 riastradh Exp $ */ +/* $NetBSD: xhci.c,v 1.177 2023/04/09 20:41:28 riastradh Exp $ */ /* * Copyright (c) 2013 Jonathan A. Kollasch @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.176 2023/04/07 09:39:48 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.177 2023/04/09 20:41:28 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -700,6 +700,7 @@ xhci_suspend(device_t self, const pmf_qual_t *qual) */ mutex_enter(&sc->sc_lock); KASSERT(sc->sc_suspender == NULL); + KASSERT(!sc->sc_suspendresume_failed); sc->sc_suspender = curlwp; while (sc->sc_command_addr != 0) cv_wait(&sc->sc_cmdbusy_cv, &sc->sc_lock); @@ -895,11 +896,13 @@ xhci_suspend(device_t self, const pmf_qual_t *qual) 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 +920,18 @@ xhci_resume(device_t self, const pmf_qual_t *qual) 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 +1125,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 +3232,8 @@ xhci_do_command_locked(struct xhci_softc * const sc, 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, diff --git a/sys/dev/usb/xhcivar.h b/sys/dev/usb/xhcivar.h index 54681d6dcef..b0f1705b2ce 100644 --- a/sys/dev/usb/xhcivar.h +++ b/sys/dev/usb/xhcivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: xhcivar.h,v 1.23 2023/04/07 09:39:48 riastradh Exp $ */ +/* $NetBSD: xhcivar.h,v 1.24 2023/04/09 20:41:29 riastradh 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 *); |
