NetBSD Problem Report #59180

From www@netbsd.org  Sat Mar 15 20:46:16 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id C355B1A923C
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 15 Mar 2025 20:46:15 +0000 (UTC)
Message-Id: <20250315204614.782D81A923E@mollari.NetBSD.org>
Date: Sat, 15 Mar 2025 20:46:14 +0000 (UTC)
From: swaggboi@gangstalking.agency
Reply-To: swaggboi@gangstalking.agency
To: gnats-bugs@NetBSD.org
Subject: System reboots instead of shutting down
X-Send-Pr-Version: www-1.0

>Number:         59180
>Category:       port-amd64
>Synopsis:       System reboots instead of shutting down
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-amd64-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 15 20:50:00 +0000 2025
>Last-Modified:  Mon Mar 31 14:50:07 +0000 2025
>Originator:     Daniel Bowling
>Release:        10.1
>Organization:
>Environment:
NetBSD ubuntu 10.1 NetBSD 10.1 (GENERIC) #0: Mon Dec 16 13:08:11 UTC 2024  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
When I enter shutdown -h now, my system performs a reboot instead of shutting down. Riastradh on IRC suggested I create a PR for this:

https://mirror.swagg.net/misc/irc_convo.txt

Here is my dmesg output:

https://mirror.swagg.net/misc/dmesg_output.txt

They noted this picture would be relevant:

https://mirror.swagg.net/Pictures/NetBSD/IMG_0846.jpeg

Here's some other photos I took in case I linked the wrong one:

https://mirror.swagg.net/Pictures/NetBSD/
>How-To-Repeat:
Enter shutdown -h now as root user
>Fix:

>Audit-Trail:
From: Taylor R Campbell <riastradh@NetBSD.org>
To: Daniel Bowling <swaggboi@gangstalking.agency>
Cc: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: port-amd64/59180: System reboots instead of shutting down
Date: Sun, 16 Mar 2025 14:38:40 +0000

 This is a multi-part message in MIME format.
 --=_QJyEfqlAfncoM8fB56hLDQdX5vxg3caH

 Can you please try a kernel with the attached patch and see if it
 solves the problem?

 (If you need, I can provide a prebuilt kernel with this patch.)

 --=_QJyEfqlAfncoM8fB56hLDQdX5vxg3caH
 Content-Type: text/plain; charset="ISO-8859-1"; name="pr59180-failedohcidetachpanic-part1"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="pr59180-failedohcidetachpanic-part1.patch"

 # HG changeset patch
 # User Taylor R Campbell <riastradh@NetBSD.org>
 # Date 1742134550 0
 #      Sun Mar 16 14:15:50 2025 +0000
 # Branch trunk
 # Node ID 3f8a61dfed92d463627e7bbf859c24f0255dd5aa
 # Parent  4c220187a0cad6a0dbb2b1ceeda3067ff430b505
 # EXP-Topic riastradh-pr59180-failedohcidetachpanic
 ohci(4): Handle failed attach when we detach.

 PR port-amd64/59180: System reboots instead of shutting down

 diff -r 4c220187a0ca -r 3f8a61dfed92 sys/dev/usb/ohci.c
 --- a/sys/dev/usb/ohci.c	Thu Mar 13 18:41:34 2025 +0000
 +++ b/sys/dev/usb/ohci.c	Sun Mar 16 14:15:50 2025 +0000
 @@ -373,6 +373,9 @@ ohci_detach(struct ohci_softc *sc, int f
  {
  	int rv =3D 0;
 =20
 +	if (!sc->sc_attached)
 +		return 0;
 +
  	if (sc->sc_child !=3D NULL)
  		rv =3D config_detach(sc->sc_child, flags);
 =20
 @@ -1092,6 +1095,7 @@ ohci_init(ohci_softc_t *sc)
  	DPRINTF("enabling %#jx", sc->sc_eintrs | OHCI_MIE, 0, 0, 0);
  	OWRITE4(sc, OHCI_INTERRUPT_ENABLE, sc->sc_eintrs | OHCI_MIE);
 =20
 +	sc->sc_attached =3D true;
  	return 0;
 =20
   bad5:
 diff -r 4c220187a0ca -r 3f8a61dfed92 sys/dev/usb/ohcivar.h
 --- a/sys/dev/usb/ohcivar.h	Thu Mar 13 18:41:34 2025 +0000
 +++ b/sys/dev/usb/ohcivar.h	Sun Mar 16 14:15:50 2025 +0000
 @@ -90,6 +90,7 @@ typedef struct ohci_softc {
  	bus_space_tag_t iot;
  	bus_space_handle_t ioh;
  	bus_size_t sc_size;
 +	bool sc_attached;
 =20
  	kmutex_t sc_lock;
  	kmutex_t sc_intr_lock;

 --=_QJyEfqlAfncoM8fB56hLDQdX5vxg3caH--

From: "swaggboi@gangstalking.agency" <swaggboi@gangstalking.agency>
To: Taylor R Campbell <riastradh@NetBSD.org>
Cc: "gnats-bugs@netbsd.org" <gnats-bugs@NetBSD.org>,
 "netbsd-bugs@netbsd.org" <netbsd-bugs@NetBSD.org>
Subject: Re: port-amd64/59180: System reboots instead of shutting down
Date: Sun, 16 Mar 2025 11:36:08 -0400

 Let me first read the docs and try to compile a kernel; if I cannot =
 figure it out we can try the prebuilt (don=E2=80=99t want to waste your =
 time if it=E2=80=99s something I can DIY.) I=E2=80=99ll report back to =
 you.

 - Dan

 > On Mar 16, 2025, at 10:38, Taylor R Campbell <riastradh@NetBSD.org> =
 wrote:
 >=20
 > Can you please try a kernel with the attached patch and see if it
 > solves the problem?
 >=20
 > (If you need, I can provide a prebuilt kernel with this patch.)
 > <pr59180-failedohcidetachpanic-part1.patch>

From: swagg boi <swaggboi@gangstalking.agency>
To: Taylor R Campbell <riastradh@NetBSD.org>
Cc: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: port-amd64/59180: System reboots instead of shutting down
Date: Mon, 17 Mar 2025 18:13:31 -0400

 Hello, sorry for the delay but I have my little 'build environment' 
 setup with the handy build.sh so I can build kernels nice and easy now.

 I gave the patch a try and still get the reboot but when I set 
 ddb.onpanic=1 the output looks different:

 http://mirror.swagg.net/NetBSD/Pictures/03172025/IMG_0863.jpeg
 http://mirror.swagg.net/NetBSD/Pictures/03172025/IMG_0864.jpeg

 show panic:
 http://mirror.swagg.net/NetBSD/Pictures/03172025/IMG_0865.jpeg

 bt:
 http://mirror.swagg.net/NetBSD/Pictures/03172025/IMG_0866.jpeg

 Here's my dmesg output again just in case you'd like to see that:

 http://mirror.swagg.net/NetBSD/misc/dmesg_output_03172025.txt

 On 3/16/25 10:38, Taylor R Campbell wrote:
 > Can you please try a kernel with the attached patch and see if it
 > solves the problem?
 > 
 > (If you need, I can provide a prebuilt kernel with this patch.)

From: Taylor R Campbell <riastradh@NetBSD.org>
To: swagg boi <swaggboi@gangstalking.agency>
Cc: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: port-amd64/59180: System reboots instead of shutting down
Date: Sun, 30 Mar 2025 20:34:57 +0000

 This is a multi-part message in MIME format.
 --=_tarl6EbRoME+6V+rh/yI3C5H/YL5MT1L

 > Date: Mon, 17 Mar 2025 18:13:31 -0400
 > From: swagg boi <swaggboi@gangstalking.agency>
 > 
 > Hello, sorry for the delay but I have my little 'build environment' 
 > setup with the handy build.sh so I can build kernels nice and easy now.
 > 
 > I gave the patch a try and still get the reboot but when I set 
 > ddb.onpanic=1 the output looks different: [...]

 Thanks, can you revert the patch I gave you before and try this one
 instead?

 --=_tarl6EbRoME+6V+rh/yI3C5H/YL5MT1L
 Content-Type: text/plain; charset="ISO-8859-1"; name="pr59180-ohcidetach-v2"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="pr59180-ohcidetach-v2.patch"

 diff -r 63a5958e843d -r e419e0cd0295 sys/arch/arm/xscale/pxa2x0_ohci.c
 --- a/sys/arch/arm/xscale/pxa2x0_ohci.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/arch/arm/xscale/pxa2x0_ohci.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -123,11 +123,7 @@ pxaohci_attach(device_t parent, device_t
  	}
 =20
  #if 0
 -	sc->sc.sc_powerhook =3D powerhook_establish(device_xname(sc->sc.sc_bus.bd=
 ev),
 -	    pxaohci_power, sc);
 -	if (sc->sc.sc_powerhook =3D=3D NULL) {
 -		aprint_error_dev(sc->sc.sc_dev->sc_bus.bdev, "cannot establish powerhook=
 \n");
 -	}
 +	pmf_device_register1(self, ohci_suspend, ohci_resume, ohci_shutdown);
  #endif
 =20
  	sc->sc.sc_child =3D config_found(self, &sc->sc.sc_bus, usbctlprint,
 @@ -151,27 +147,57 @@ pxaohci_detach(device_t self, int flags)
  	struct pxaohci_softc *sc =3D device_private(self);
  	int error;
 =20
 -	error =3D ohci_detach(&sc->sc, flags);
 +	/*
 +	 * Detach the USB child first.  Disconnects all USB devices and
 +	 * prevents connecting new ones.
 +	 */
 +	error =3D config_detach_children(self, flags);
  	if (error)
  		return error;
 =20
 +	/*
 +	 * Shut down the controller and block interrupts at the device
 +	 * level.  Once we have shut down the controller, the shutdown
 +	 * handler no longer needed -- deregister it from PMF.
 +	 * (Harmless to call ohci_shutdown more than once, so no
 +	 * synchronization needed.)
 +	 */
 +	ohci_shutdown(self, 0);
  #if 0
 -	if (sc->sc.sc_powerhook) {
 -		powerhook_disestablish(sc->sc.sc_powerhook);
 -		sc->sc.sc_powerhook =3D NULL;
 -	}
 +	pmf_device_deregister(self);
  #endif
 =20
 +	/*
 +	 * Interrupts are blocked at the device level by ohci_shutdown.
 +	 * Disestablish the interrupt handler.  This waits for it to
 +	 * complete on all CPUs.
 +	 */
  	if (sc->sc_ih) {
  		pxa2x0_intr_disestablish(sc->sc_ih);
  		sc->sc_ih =3D NULL;
  	}
 =20
 +	/*
 +	 * Free the bus-independent ohci(4) state now that the
 +	 * interrupt handler has ceased to run on all CPUs.
 +	 */
 +	ohci_detach(&sc->sc);
 +
 +	/*
 +	 * Issue a Full Host Reset to disable the host controller
 +	 * interface.
 +	 *
 +	 * XXX Is this necessary or is it redundant with ohci_shutdown?
 +	 * Should it be done in ohci_shutdown as well?
 +	 */
  	pxaohci_disable(sc);
 =20
  	/* stop clock */
  	pxa2x0_clkman_config(CKEN_USBHC, 0);
 =20
 +	/*
 +	 * Unmap the registers now that we're all done with them.
 +	 */
  	if (sc->sc.sc_size) {
  		bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc.sc_size);
  		sc->sc.sc_size =3D 0;
 diff -r 63a5958e843d -r e419e0cd0295 sys/arch/mips/ralink/ralink_ehci.c
 --- a/sys/arch/mips/ralink/ralink_ehci.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/arch/mips/ralink/ralink_ehci.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -57,15 +57,11 @@ static void ralink_ehci_attach(device_t,
  static int  ralink_ehci_detach(device_t, int);
 =20
  CFATTACH_DECL2_NEW(ralink_ehci, sizeof(struct ralink_ehci_softc),
 -	ralink_ehci_match, ralink_ehci_attach, ralink_ehci_detach,
 -	ehci_activate, NULL, ehci_childdet);
 +    ralink_ehci_match, ralink_ehci_attach, ralink_ehci_detach,
 +    ehci_activate, NULL, ehci_childdet);
 =20
  static TAILQ_HEAD(, ralink_usb_hc) ralink_usb_alldevs =3D
 -	TAILQ_HEAD_INITIALIZER(ralink_usb_alldevs);
 -
 -#if 0
 -struct usb_hc_alldevs ralink_usb_alldevs =3D TAILQ_HEAD_INITIALIZER(ralink=
 _usb_alldevs);
 -#endif
 +    TAILQ_HEAD_INITIALIZER(ralink_usb_alldevs);
 =20
  /*
   * ralink_ehci_match
 @@ -144,6 +140,7 @@ ralink_ehci_attach(device_t parent, devi
  	 * have lower function numbers so they should be enumerated already.
  	 */
  	int ncomp =3D 0;
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ralink_usb_alldevs */
  	TAILQ_FOREACH(ruh, &ralink_usb_alldevs, next) {
  		aprint_normal_dev(self, "companion %s\n",
  			device_xname(ruh->usb));
 @@ -207,6 +204,9 @@ ralink_ehci_detach(device_t self, int fl
  void
  ralink_usb_hc_add(struct ralink_usb_hc *ruh, device_t usbp)
  {
 +
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ralink_usb_alldevs */
 +
  	TAILQ_INSERT_TAIL(&ralink_usb_alldevs, ruh, next);
  	ruh->usb =3D usbp;
  }
 @@ -214,5 +214,9 @@ ralink_usb_hc_add(struct ralink_usb_hc *
  void
  ralink_usb_hc_rem(struct ralink_usb_hc *ruh)
  {
 -	TAILQ_REMOVE(&ralink_usb_alldevs, ruh, next);
 +
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ralink_usb_alldevs */
 +
 +	if (ruh->usb)
 +		TAILQ_REMOVE(&ralink_usb_alldevs, ruh, next);
  }
 diff -r 63a5958e843d -r e419e0cd0295 sys/arch/mips/ralink/ralink_ohci.c
 --- a/sys/arch/mips/ralink/ralink_ohci.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/arch/mips/ralink/ralink_ohci.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -162,28 +162,58 @@ static int
  ralink_ohci_detach(device_t self, int flags)
  {
  	struct ralink_ohci_softc *sc =3D device_private(self);
 -	int rv;
 +	int error;
 +
 +	/*
 +	 * Detach the USB child first.  Disconnects all USB devices and
 +	 * prevents connecting new ones.
 +	 */
 +	error =3D config_detach_children(self, flags);
 +	if (error)
 +		return error;
 =20
 +	/*
 +	 * Stop listing this as a possible companion controller for
 +	 * ehci(4).
 +	 */
 +#if NEHCI > 0
 +	ralink_usb_hc_rem(&sc->sc_hc);
 +#endif
 +
 +	/*
 +	 * Shut down the controller and block interrupts at the device
 +	 * level.  Once we have shut down the controller, the shutdown
 +	 * handler no longer needed -- deregister it from PMF.
 +	 * (Harmless to call ohci_shutdown more than once, so no
 +	 * synchronization needed.)
 +	 */
 +	ohci_shutdown(self, 0);
  	pmf_device_deregister(self);
 =20
 -	rv =3D ohci_detach(&sc->sc_ohci, flags);
 -	if (rv !=3D 0)
 -		return rv;
 -
 +	/*
 +	 * Interrupts are blocked at the device level by ohci_shutdown.
 +	 * Disestablish the interrupt handler.  This waits for it to
 +	 * complete on all CPUs.
 +	 */
  	if (sc->sc_ih !=3D NULL) {
  		ra_intr_disestablish(sc->sc_ih);
  		sc->sc_ih =3D NULL;
  	}
 =20
 -	if (sc->sc_ohci.sc_size =3D=3D 0) {
 +	/*
 +	 * Free the bus-independent ohci(4) state now that the
 +	 * interrupt handler has ceased to run on all CPUs.
 +	 */
 +	ohci_detach(&sc->sc_ohci);
 +
 +	/*
 +	 * Unmap the registers now that we're all done with them.
 +	 */
 +	if (sc->sc_ohci.sc_size) {
  		bus_space_unmap(sc->sc_ohci.iot, sc->sc_ohci.ioh,
 -			sc->sc_ohci.sc_size);
 +		    sc->sc_ohci.sc_size);
  		sc->sc_ohci.sc_size =3D 0;
  	}
 =20
 -#if NEHCI > 0
 -	ralink_usb_hc_rem(&sc->sc_hc);
 -#endif
 -
  	return 0;
  }
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/cardbus/ehci_cardbus.c
 --- a/sys/dev/cardbus/ehci_cardbus.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/cardbus/ehci_cardbus.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -82,7 +82,7 @@ CFATTACH_DECL_NEW(ehci_cardbus, sizeof(s
      ehci_activate);
 =20
  static TAILQ_HEAD(, usb_cardbus) ehci_cardbus_alldevs =3D
 -	TAILQ_HEAD_INITIALIZER(ehci_cardbus_alldevs);
 +    TAILQ_HEAD_INITIALIZER(ehci_cardbus_alldevs);
 =20
  int
  ehci_cardbus_match(device_t parent, cfdata_t match, void *aux)
 @@ -175,6 +175,7 @@ ehci_cardbus_attach(device_t parent, dev
  	 * have lower function numbers so they should be enumerated already.
  	 */
  	ncomp =3D 0;
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_cardbus_alldevs */
  	TAILQ_FOREACH(up, &ehci_cardbus_alldevs, next) {
  		if (up->bus =3D=3D ca->ca_bus) {
  			DPRINTF(("ehci_cardbus_attach: companion %s\n",
 @@ -232,6 +233,9 @@ void
  usb_cardbus_add(struct usb_cardbus *up, struct cardbus_attach_args *ca,
      device_t bu)
  {
 +
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_cardbus_alldevs */
 +
  	TAILQ_INSERT_TAIL(&ehci_cardbus_alldevs, up, next);
  	up->bus =3D ca->ca_bus;
  	up->function =3D ca->ca_function;
 @@ -241,5 +245,9 @@ usb_cardbus_add(struct usb_cardbus *up,=20
  void
  usb_cardbus_rem(struct usb_cardbus *up)
  {
 -	TAILQ_REMOVE(&ehci_cardbus_alldevs, up, next);
 +
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_cardbus_alldevs */
 +
 +	if (up->usb)
 +		TAILQ_REMOVE(&ehci_cardbus_alldevs, up, next);
  }
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/cardbus/ohci_cardbus.c
 --- a/sys/dev/cardbus/ohci_cardbus.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/cardbus/ohci_cardbus.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -175,22 +175,58 @@ ohci_cardbus_detach(device_t self, int f
  {
  	struct ohci_cardbus_softc *sc =3D device_private(self);
  	struct cardbus_devfunc *ct =3D sc->sc_ct;
 -	int rv;
 +	int error;
 +
 +	/*
 +	 * Detach the USB child first.  Disconnects all USB devices and
 +	 * prevents connecting new ones.
 +	 */
 +	error =3D config_detach_children(self, flags);
 +	if (error)
 +		return error;
 =20
 -	rv =3D ohci_detach(&sc->sc, flags);
 -	if (rv)
 -		return rv;
 +	/*
 +	 * Stop listing this as a possible companion controller for
 +	 * ehci(4).
 +	 */
 +#if NEHCI_CARDBUS > 0
 +	usb_cardbus_rem(&sc->sc_cardbus);
 +#endif
 +
 +	/*
 +	 * Shut down the controller and block interrupts at the device
 +	 * level.  Once we have shut down the controller, the shutdown
 +	 * handler no longer needed -- deregister it from PMF.
 +	 * (Harmless to call ohci_shutdown more than once, so no
 +	 * synchronization needed.)
 +	 */
 +	ohci_shutdown(self, 0);
 +	pmf_device_deregister(self);
 +
 +	/*
 +	 * Interrupts are blocked at the device level by ohci_shutdown.
 +	 * Disestablish the interrupt handler.  This waits for it to
 +	 * complete on all CPUs.
 +	 */
  	if (sc->sc_ih !=3D NULL) {
  		Cardbus_intr_disestablish(ct, sc->sc_ih);
  		sc->sc_ih =3D NULL;
  	}
 +
 +	/*
 +	 * Free the bus-independent ohci(4) state now that the
 +	 * interrupt handler has ceased to run on all CPUs.
 +	 */
 +	ohci_detach(&sc->sc);
 +
 +	/*
 +	 * Unmap the registers now that we're all done with them.
 +	 */
  	if (sc->sc.sc_size) {
  		Cardbus_mapreg_unmap(ct, PCI_CBMEM, sc->sc.iot,
  		    sc->sc.ioh, sc->sc.sc_size);
  		sc->sc.sc_size =3D 0;
  	}
 -#if NEHCI_CARDBUS > 0
 -	usb_cardbus_rem(&sc->sc_cardbus);
 -#endif
 +
  	return 0;
  }
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/pci/ehci_pci.c
 --- a/sys/dev/pci/ehci_pci.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/pci/ehci_pci.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -243,6 +243,7 @@ ehci_pci_attach(device_t parent, device_
  	const u_int maxncomp =3D EHCI_HCS_N_CC(EREAD4(&sc->sc, EHCI_HCSPARAMS));
  	KASSERT(maxncomp <=3D EHCI_COMPANION_MAX);
  	ncomp =3D 0;
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_pci_alldevs */
  	TAILQ_FOREACH(up, &ehci_pci_alldevs, next) {
  		if (up->bus =3D=3D pa->pa_bus && up->device =3D=3D pa->pa_device &&
  		    !up->claimed) {
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/pci/ohci_pci.c
 --- a/sys/dev/pci/ohci_pci.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/pci/ohci_pci.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -187,33 +187,58 @@ static int
  ohci_pci_detach(device_t self, int flags)
  {
  	struct ohci_pci_softc *sc =3D device_private(self);
 -	int rv;
 +	int error;
 +
 +	/*
 +	 * Detach the USB child first.  Disconnects all USB devices and
 +	 * prevents connecting new ones.
 +	 */
 +	error =3D config_detach_children(self, flags);
 +	if (error)
 +		return error;
 =20
 -	rv =3D ohci_detach(&sc->sc, flags);
 -	if (rv)
 -		return rv;
 +	/*
 +	 * Stop listing this as a possible companion controller for
 +	 * ehci(4).
 +	 */
 +#if NEHCI > 0
 +	usb_pci_rem(&sc->sc_pci);
 +#endif
 =20
 +	/*
 +	 * Shut down the controller and block interrupts at the device
 +	 * level.  Once we have shut down the controller, the shutdown
 +	 * handler no longer needed -- deregister it from PMF.
 +	 * (Harmless to call ohci_shutdown more than once, so no
 +	 * synchronization needed.)
 +	 */
 +	ohci_shutdown(self, 0);
  	pmf_device_deregister(self);
 =20
 -	ohci_shutdown(self, flags);
 -
 -	if (sc->sc.sc_size) {
 -		/* Disable interrupts, so we don't get any spurious ones. */
 -		bus_space_write_4(sc->sc.iot, sc->sc.ioh,
 -				  OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS);
 -	}
 -
 +	/*
 +	 * Interrupts are blocked at the device level by ohci_shutdown.
 +	 * Disestablish the interrupt handler.  This waits for it to
 +	 * complete on all CPUs.
 +	 */
  	if (sc->sc_ih !=3D NULL) {
  		pci_intr_disestablish(sc->sc_pc, sc->sc_ih);
  		sc->sc_ih =3D NULL;
  	}
 +
 +	/*
 +	 * Free the bus-independent ohci(4) state now that the
 +	 * interrupt handler has ceased to run on all CPUs.
 +	 */
 +	ohci_detach(&sc->sc);
 +
 +	/*
 +	 * Unmap the registers now that we're all done with them.
 +	 */
  	if (sc->sc.sc_size) {
  		bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc.sc_size);
  		sc->sc.sc_size =3D 0;
  	}
 -#if NEHCI > 0
 -	usb_pci_rem(&sc->sc_pci);
 -#endif
 +
  	return 0;
  }
 =20
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/pci/usb_pci.c
 --- a/sys/dev/pci/usb_pci.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/pci/usb_pci.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -33,28 +33,31 @@
  __KERNEL_RCSID(0, "$NetBSD: usb_pci.c,v 1.7 2008/04/28 20:23:55 martin Exp=
  $");
 =20
  #include <sys/param.h>
 +#include <sys/kernel.h>
 +#include <sys/proc.h>
 +#include <sys/queue.h>
  #include <sys/systm.h>
 -#include <sys/kernel.h>
 -#include <sys/queue.h>
 -#include <sys/proc.h>
 =20
  #include <dev/pci/pcivar.h>
  #include <dev/pci/usb_pci.h>
 =20
  #include <dev/usb/usb.h>
 +#include <dev/usb/usb_mem.h>
  #include <dev/usb/usbdi.h>
  #include <dev/usb/usbdivar.h>
 -#include <dev/usb/usb_mem.h>
 =20
  #include <dev/usb/ehcireg.h>
  #include <dev/usb/ehcivar.h>
 =20
  struct usb_pci_alldevs ehci_pci_alldevs =3D
 -	TAILQ_HEAD_INITIALIZER(ehci_pci_alldevs);
 +    TAILQ_HEAD_INITIALIZER(ehci_pci_alldevs);
 =20
  void
  usb_pci_add(struct usb_pci *up, struct pci_attach_args *pa, device_t bu)
  {
 +
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_pci_alldevs */
 +
  	TAILQ_INSERT_TAIL(&ehci_pci_alldevs, up, next);
  	up->bus =3D pa->pa_bus;
  	up->device =3D pa->pa_device;
 @@ -65,5 +68,9 @@ usb_pci_add(struct usb_pci *up, struct p
  void
  usb_pci_rem(struct usb_pci *up)
  {
 -	TAILQ_REMOVE(&ehci_pci_alldevs, up, next);
 +
 +	KASSERT(KERNEL_LOCKED_P()); /* XXXSMP ehci_pci_alldevs */
 +
 +	if (up->usb)
 +		TAILQ_REMOVE(&ehci_pci_alldevs, up, next);
  }
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/usb/ohci.c
 --- a/sys/dev/usb/ohci.c	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/usb/ohci.c	Sun Mar 30 20:18:14 2025 +0000
 @@ -368,16 +368,14 @@ ohci_childdet(device_t self, device_t ch
  	sc->sc_child =3D NULL;
  }
 =20
 -int
 -ohci_detach(struct ohci_softc *sc, int flags)
 +void
 +ohci_detach(struct ohci_softc *sc)
  {
 -	int rv =3D 0;
 -
 -	if (sc->sc_child !=3D NULL)
 -		rv =3D config_detach(sc->sc_child, flags);
 -
 -	if (rv !=3D 0)
 -		return rv;
 +
 +	KASSERT(sc->sc_child =3D=3D NULL);
 +
 +	if (!sc->sc_attached)
 +		return;
 =20
  	softint_disestablish(sc->sc_rhsc_si);
 =20
 @@ -391,8 +389,6 @@ ohci_detach(struct ohci_softc *sc, int f
  		usb_freemem(&sc->sc_hccadma);
  	pool_cache_destroy(sc->sc_xferpool);
  	cv_destroy(&sc->sc_abort_cv);
 -
 -	return rv;
  }
 =20
  ohci_soft_ed_t *
 @@ -1092,6 +1088,7 @@ ohci_init(ohci_softc_t *sc)
  	DPRINTF("enabling %#jx", sc->sc_eintrs | OHCI_MIE, 0, 0, 0);
  	OWRITE4(sc, OHCI_INTERRUPT_ENABLE, sc->sc_eintrs | OHCI_MIE);
 =20
 +	sc->sc_attached =3D true;
  	return 0;
 =20
   bad5:
 @@ -1166,6 +1163,9 @@ ohci_shutdown(device_t self, int flags)
 =20
  	OHCIHIST_FUNC(); OHCIHIST_CALLED();
 =20
 +	if (!sc->sc_attached)
 +		return true;
 +
  	DPRINTF("stopping the HC", 0, 0, 0, 0);
  	OWRITE4(sc, OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS);
  	OWRITE4(sc, OHCI_CONTROL, OHCI_SET_HCFS(OHCI_HCFS_RESET));
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/usb/ohcivar.h
 --- a/sys/dev/usb/ohcivar.h	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/usb/ohcivar.h	Sun Mar 30 20:18:14 2025 +0000
 @@ -90,6 +90,7 @@ typedef struct ohci_softc {
  	bus_space_tag_t iot;
  	bus_space_handle_t ioh;
  	bus_size_t sc_size;
 +	bool sc_attached;
 =20
  	kmutex_t sc_lock;
  	kmutex_t sc_intr_lock;
 @@ -172,7 +173,7 @@ struct ohci_xfer {
 =20
  int		ohci_init(ohci_softc_t *);
  int		ohci_intr(void *);
 -int		ohci_detach(ohci_softc_t *, int);
 +void		ohci_detach(ohci_softc_t *);
  bool		ohci_shutdown(device_t, int);
  void		ohci_childdet(device_t, device_t);
  int		ohci_activate(device_t, enum devact);
 diff -r 63a5958e843d -r e419e0cd0295 sys/dev/usb/usbdivar.h
 --- a/sys/dev/usb/usbdivar.h	Sun Mar 30 16:22:37 2025 +0000
 +++ b/sys/dev/usb/usbdivar.h	Sun Mar 30 20:18:14 2025 +0000
 @@ -74,9 +74,11 @@
   *
   */
 =20
 +#include <sys/bus.h>
  #include <sys/callout.h>
  #include <sys/mutex.h>
 -#include <sys/bus.h>
 +
 +#include <dev/usb/usbdi.h>
 =20
  /* From usb_mem.h */
  struct usb_dma_block;

 --=_tarl6EbRoME+6V+rh/yI3C5H/YL5MT1L--

From: Daniel Bowling <swaggboi@gangstalking.agency>
To: Taylor R Campbell <riastradh@NetBSD.org>
Cc: gnats-bugs@NetBSD.org, netbsd-bugs@NetBSD.org
Subject: Re: port-amd64/59180: System reboots instead of shutting down
Date: Sun, 30 Mar 2025 18:34:42 -0400

 This patch appears to work; thank you. I applied the patch and did both 
 a reboot and a normal shutdown with ddb.onpanic=1 set without any issues.

 On 3/30/25 16:34, Taylor R Campbell wrote:
 >> Date: Mon, 17 Mar 2025 18:13:31 -0400
 >> From: swagg boi <swaggboi@gangstalking.agency>
 >>
 >> Hello, sorry for the delay but I have my little 'build environment'
 >> setup with the handy build.sh so I can build kernels nice and easy now.
 >>
 >> I gave the patch a try and still get the reboot but when I set
 >> ddb.onpanic=1 the output looks different: [...]
 > Thanks, can you revert the patch I gave you before and try this one
 > instead?

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59180 CVS commit: src/sys/dev/usb
Date: Mon, 31 Mar 2025 14:45:14 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Mar 31 14:45:14 UTC 2025

 Modified Files:
 	src/sys/dev/usb: usbdivar.h

 Log Message:
 usbdivar.h: Add missing usbdi.h include for usbd_status &c.

 Sort includes while here.

 Prompted by:

 PR port-amd64/59180: System reboots instead of shutting down


 To generate a diff of this commit:
 cvs rdiff -u -r1.138 -r1.139 src/sys/dev/usb/usbdivar.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59180 CVS commit: src/sys
Date: Mon, 31 Mar 2025 14:45:36 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Mar 31 14:45:35 UTC 2025

 Modified Files:
 	src/sys/arch/mips/ralink: ralink_ehci.c
 	src/sys/dev/cardbus: ehci_cardbus.c
 	src/sys/dev/pci: ehci_pci.c usb_pci.c

 Log Message:
 ehci(4): Sprinkle KERNEL_LOCKED_P and KNF on usb_*_add/rem.

 Mark with XXXSMP comments to be fixed later without the kernel lock.

 No functional change intended: callers generally do this from
 autoconf *_attach/detach routines, which run kernel-locked anyway
 (for the moment).

 Cleanup in preparation for:

 PR port-amd64/59180: System reboots instead of shutting down


 To generate a diff of this commit:
 cvs rdiff -u -r1.9 -r1.10 src/sys/arch/mips/ralink/ralink_ehci.c
 cvs rdiff -u -r1.37 -r1.38 src/sys/dev/cardbus/ehci_cardbus.c
 cvs rdiff -u -r1.77 -r1.78 src/sys/dev/pci/ehci_pci.c
 cvs rdiff -u -r1.7 -r1.8 src/sys/dev/pci/usb_pci.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59180 CVS commit: src/sys
Date: Mon, 31 Mar 2025 14:45:57 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Mar 31 14:45:57 UTC 2025

 Modified Files:
 	src/sys/arch/mips/ralink: ralink_ehci.c
 	src/sys/dev/cardbus: ehci_cardbus.c
 	src/sys/dev/pci: usb_pci.c

 Log Message:
 ehci(4): Make usb_*_rem work as noop on zero-initialized input.

 This way, if some *hci_attach function fails before usb_*_add, the
 caller need not maintain boolean state to decide whether to call
 usb_*_rem on detach -- it'll just work without extra effort.

 Cleanup in preparation for:

 PR port-amd64/59180: System reboots instead of shutting down


 To generate a diff of this commit:
 cvs rdiff -u -r1.10 -r1.11 src/sys/arch/mips/ralink/ralink_ehci.c
 cvs rdiff -u -r1.38 -r1.39 src/sys/dev/cardbus/ehci_cardbus.c
 cvs rdiff -u -r1.8 -r1.9 src/sys/dev/pci/usb_pci.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59180 CVS commit: src/sys
Date: Mon, 31 Mar 2025 14:46:42 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Mar 31 14:46:42 UTC 2025

 Modified Files:
 	src/sys/arch/arm/xscale: pxa2x0_ohci.c
 	src/sys/arch/mips/ralink: ralink_ohci.c
 	src/sys/dev/cardbus: ohci_cardbus.c
 	src/sys/dev/pci: ohci_pci.c
 	src/sys/dev/usb: ohci.c ohcivar.h

 Log Message:
 ohci(4): Rework detach logic and justify the ordering.

 Handle failed attach when we detach.

 This changes the signature of the ohci_detach function, but it is
 only ever used by statically linked ohci bus attachments, never by
 modules so far, so no kernel revbump.

 PR port-amd64/59180: System reboots instead of shutting down


 To generate a diff of this commit:
 cvs rdiff -u -r1.13 -r1.14 src/sys/arch/arm/xscale/pxa2x0_ohci.c
 cvs rdiff -u -r1.7 -r1.8 src/sys/arch/mips/ralink/ralink_ohci.c
 cvs rdiff -u -r1.46 -r1.47 src/sys/dev/cardbus/ohci_cardbus.c
 cvs rdiff -u -r1.59 -r1.60 src/sys/dev/pci/ohci_pci.c
 cvs rdiff -u -r1.329 -r1.330 src/sys/dev/usb/ohci.c
 cvs rdiff -u -r1.63 -r1.64 src/sys/dev/usb/ohcivar.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59180 CVS commit: src/sys/dev/pci
Date: Mon, 31 Mar 2025 14:48:50 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Mar 31 14:48:50 UTC 2025

 Modified Files:
 	src/sys/dev/pci: ohci_pci.c

 Log Message:
 ohci@pci: Don't detach on shutdown.

 If there's some USB device that requires detach on shutdown (which
 would be surprising, because USB devices should generally be safe to
 yank at any time, and _storage_ drivers such as ld(4) or sd(4) should
 already be synced at shutdown some other way) then that driver should
 have DVF_DETACH_SHUTDOWN -- not the entire HCI.

 PR port-amd64/59180: System reboots instead of shutting down
 PR kern/59179: DVF_DETACH_SHUTDOWN: audit drivers for unnecessary use


 To generate a diff of this commit:
 cvs rdiff -u -r1.60 -r1.61 src/sys/dev/pci/ohci_pci.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.