Skip to contentSkip to conversation

usb: stop generic OHCI and EHCI at OS handoff

PATCH Superseded khaliforce 4 participants 20 messages Oct 6 – Nov 3

Subsystems (3)
lore
Share & tools
lore

khaliforce

author
#0 lore raw

PATCH 1/1 usb: stop generic OHCI and EHCI at OS handoff

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_OS_PREPARE. Consequently, their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing memory previously occupied by U-Boot. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_OS_PREPARE on both drivers so that their existing remove callbacks stop the controllers during OS preparation.

---
Tested on a MangoPi MQ Pro with U-Boot v2026.10 and Linux 6.1:

- Started USB and accessed a 64 GB FAT32 USB storage device.
- Read 4096 bytes in U-Boot and verified that their CRC32 matched the same data read under Linux.
- Booted Linux without manually running "usb stop".
- Confirmed USB storage access and Wi-Fi/SSH after the handoff.
- Observed no panic or Bad page errors in the kernel log.

The hardware test used the downstream D1/MangoPi port.

The standalone patch also builds on current upstream main for RISC-V64, ARM64 and ARM32. Checkpatch reports no errors or warnings.

 drivers/usb/host/ehci-generic.c | 2 +-
 drivers/usb/host/ohci-generic.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..8075fb069f1 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
 	.remove = ehci_usb_remove,
 	.ops	= &ehci_usb_ops,
 	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_OS_PREPARE,
 };
drivers/usb/host/ohci-generic.c +2 -1
index cc44226f5e0..6cc26e2d3c0 100644
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
 	.remove = ohci_usb_remove,
 	.ops	= &ohci_usb_ops,
 	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_OS_PREPARE,
 };
#1 lore raw
Quoted 10 lines · khaliforce

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_OS_PREPARE. Consequently, their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing memory previously occupied by U-Boot. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_OS_PREPARE on both drivers so that their existing remove callbacks stop the controllers during OS preparation.

So while they actually have the same behavior, the DM_FLAG_ACTIVE_DMA is exactly what you want.

Neil

Quoted 44 lines

---
Tested on a MangoPi MQ Pro with U-Boot v2026.10 and Linux 6.1:

- Started USB and accessed a 64 GB FAT32 USB storage device.
- Read 4096 bytes in U-Boot and verified that their CRC32 matched the same data read under Linux.
- Booted Linux without manually running "usb stop".
- Confirmed USB storage access and Wi-Fi/SSH after the handoff.
- Observed no panic or Bad page errors in the kernel log.

The hardware test used the downstream D1/MangoPi port.

The standalone patch also builds on current upstream main for RISC-V64, ARM64 and ARM32. Checkpatch reports no errors or warnings.

  drivers/usb/host/ehci-generic.c | 2 +-
  drivers/usb/host/ohci-generic.c | 3 ++-
  2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..8075fb069f1 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
  	.remove = ehci_usb_remove,
  	.ops	= &ehci_usb_ops,
  	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_OS_PREPARE,
  };
drivers/usb/host/ohci-generic.c +2 -1
index cc44226f5e0..6cc26e2d3c0 100644
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
  	.remove = ohci_usb_remove,
  	.ops	= &ohci_usb_ops,
  	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_OS_PREPARE,
  };
author
#2 lore raw

PATCH v2 1/1 usb: stop generic OHCI and EHCI at OS handoff

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_ACTIVE_DMA. Their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing U-Boot memory. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_ACTIVE_DMA on both drivers so their existing remove callbacks stop the controllers during OS preparation.

---
Changes in v2:
- Use DM_FLAG_ACTIVE_DMA as suggested by Neil Armstrong.

Retested on MangoPi MQ Pro with the downstream D1 port based on U-Boot v2026.10 and Linux 6.1:
- Read a 64 GB FAT32 USB device in U-Boot.
- Verified a 4096-byte read against Linux using CRC32.
- Booted Linux without running "usb stop".
- Confirmed USB reads, Wi-Fi and SSH after the handoff.
- Observed no panic, Bad page or failed services.

Standalone builds pass for RISC-V64, ARM64 and ARM32 on upstream main. RISC-V64 QEMU boots. Checkpatch reports no errors or warnings.

 drivers/usb/host/ehci-generic.c | 2 +-
 drivers/usb/host/ohci-generic.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..57f1bcbd9c0 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
 	.remove = ehci_usb_remove,
 	.ops	= &ehci_usb_ops,
 	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
 };
drivers/usb/host/ohci-generic.c +2 -1
index cc44226f5e0..7493750f8d1 100644
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
 	.remove = ohci_usb_remove,
 	.ops	= &ohci_usb_ops,
 	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
 };
#3 lore raw
Quoted 47 lines · khaliforce

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_ACTIVE_DMA. Their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing U-Boot memory. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_ACTIVE_DMA on both drivers so their existing remove callbacks stop the controllers during OS preparation.

---
Changes in v2:
- Use DM_FLAG_ACTIVE_DMA as suggested by Neil Armstrong.

Retested on MangoPi MQ Pro with the downstream D1 port based on U-Boot v2026.10 and Linux 6.1:
- Read a 64 GB FAT32 USB device in U-Boot.
- Verified a 4096-byte read against Linux using CRC32.
- Booted Linux without running "usb stop".
- Confirmed USB reads, Wi-Fi and SSH after the handoff.
- Observed no panic, Bad page or failed services.

Standalone builds pass for RISC-V64, ARM64 and ARM32 on upstream main. RISC-V64 QEMU boots. Checkpatch reports no errors or warnings.

 drivers/usb/host/ehci-generic.c | 2 +-
 drivers/usb/host/ohci-generic.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..57f1bcbd9c0 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
 	.remove = ehci_usb_remove,
 	.ops	= &ehci_usb_ops,
 	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
 };
drivers/usb/host/ohci-generic.c +0 -0
index cc44226f5e0..7493750f8d1 100644

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 115

Quoted 7 lines
drivers/usb/host/ohci-generic.c +2 -1
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
 	.remove = ohci_usb_remove,
 	.ops	= &ohci_usb_ops,
 	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
 };

Ah. Perhaps this is also what Romain needs for fixing the problem they see on an Apple platform, and would be more palatable to Marek to apply generally to USB host drivers (and switch the ones that use DM_FLAG_OS_PREPARE today?) ?

Signature · 1 line
Tom
#4 lore raw
Quoted 46 lines · Tom Rini
Quoted 44 lines · khaliforce

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_ACTIVE_DMA. Their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing U-Boot memory. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_ACTIVE_DMA on both drivers so their existing remove callbacks stop the controllers during OS preparation.

---
Changes in v2:
- Use DM_FLAG_ACTIVE_DMA as suggested by Neil Armstrong.

Retested on MangoPi MQ Pro with the downstream D1 port based on U-Boot v2026.10 and Linux 6.1:
- Read a 64 GB FAT32 USB device in U-Boot.
- Verified a 4096-byte read against Linux using CRC32.
- Booted Linux without running "usb stop".
- Confirmed USB reads, Wi-Fi and SSH after the handoff.
- Observed no panic, Bad page or failed services.

Standalone builds pass for RISC-V64, ARM64 and ARM32 on upstream main. RISC-V64 QEMU boots. Checkpatch reports no errors or warnings.

  drivers/usb/host/ehci-generic.c | 2 +-
  drivers/usb/host/ohci-generic.c | 3 ++-
  2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..57f1bcbd9c0 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
  	.remove = ehci_usb_remove,
  	.ops	= &ehci_usb_ops,
  	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
  };
drivers/usb/host/ohci-generic.c +0 -0
index cc44226f5e0..7493750f8d1 100644
Quoted 8 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 113

Quoted 8 lines
drivers/usb/host/ohci-generic.c +1 -1
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
  	.remove = ohci_usb_remove,
  	.ops	= &ohci_usb_ops,
  	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */

HCCA is communication area ?

Quoted 7 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 115

Quoted 2 lines
drivers/usb/host/ohci-generic.c +1 -0
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
  };

Ah. Perhaps this is also what Romain needs for fixing the problem they see on an Apple platform, and would be more palatable to Marek to apply generally to USB host drivers (and switch the ones that use DM_FLAG_OS_PREPARE today?) ?

This works, but maybe we should instead unconditionally call usb_stop() before booting ?

#5 lore raw
Quoted 65 lines · Marek Vasut
Quoted 46 lines · Tom Rini
Quoted 44 lines · khaliforce

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_ACTIVE_DMA. Their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing U-Boot memory. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_ACTIVE_DMA on both drivers so their existing remove callbacks stop the controllers during OS preparation.

---
Changes in v2:
- Use DM_FLAG_ACTIVE_DMA as suggested by Neil Armstrong.

Retested on MangoPi MQ Pro with the downstream D1 port based on U-Boot v2026.10 and Linux 6.1:
- Read a 64 GB FAT32 USB device in U-Boot.
- Verified a 4096-byte read against Linux using CRC32.
- Booted Linux without running "usb stop".
- Confirmed USB reads, Wi-Fi and SSH after the handoff.
- Observed no panic, Bad page or failed services.

Standalone builds pass for RISC-V64, ARM64 and ARM32 on upstream main. RISC-V64 QEMU boots. Checkpatch reports no errors or warnings.

  drivers/usb/host/ehci-generic.c | 2 +-
  drivers/usb/host/ohci-generic.c | 3 ++-
  2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..57f1bcbd9c0 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
  	.remove = ehci_usb_remove,
  	.ops	= &ehci_usb_ops,
  	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
  };
drivers/usb/host/ohci-generic.c +0 -0
index cc44226f5e0..7493750f8d1 100644
Quoted 8 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 113

Quoted 8 lines
drivers/usb/host/ohci-generic.c +1 -1
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
  	.remove = ohci_usb_remove,
  	.ops	= &ohci_usb_ops,
  	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */

HCCA is communication area ?

Quoted 7 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 115

Quoted 2 lines
drivers/usb/host/ohci-generic.c +1 -0
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
  };

Ah. Perhaps this is also what Romain needs for fixing the problem they see on an Apple platform, and would be more palatable to Marek to apply generally to USB host drivers (and switch the ones that use DM_FLAG_OS_PREPARE today?) ?

Quoted 2 lines

This works, but maybe we should instead unconditionally call usb_stop() before booting ?

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

Signature · 1 line
Tom
#6 lore raw
Quoted 66 lines · Tom Rini
Quoted 65 lines · Marek Vasut
Quoted 46 lines · Tom Rini
Quoted 44 lines · khaliforce

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_ACTIVE_DMA. Their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing U-Boot memory. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_ACTIVE_DMA on both drivers so their existing remove callbacks stop the controllers during OS preparation.

---
Changes in v2:
- Use DM_FLAG_ACTIVE_DMA as suggested by Neil Armstrong.

Retested on MangoPi MQ Pro with the downstream D1 port based on U-Boot v2026.10 and Linux 6.1:
- Read a 64 GB FAT32 USB device in U-Boot.
- Verified a 4096-byte read against Linux using CRC32.
- Booted Linux without running "usb stop".
- Confirmed USB reads, Wi-Fi and SSH after the handoff.
- Observed no panic, Bad page or failed services.

Standalone builds pass for RISC-V64, ARM64 and ARM32 on upstream main. RISC-V64 QEMU boots. Checkpatch reports no errors or warnings.

   drivers/usb/host/ehci-generic.c | 2 +-
   drivers/usb/host/ohci-generic.c | 3 ++-
   2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..57f1bcbd9c0 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
   	.remove = ehci_usb_remove,
   	.ops	= &ehci_usb_ops,
   	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
   };
drivers/usb/host/ohci-generic.c +0 -0
index cc44226f5e0..7493750f8d1 100644
Quoted 8 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 113

Quoted 8 lines
drivers/usb/host/ohci-generic.c +1 -1
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
   	.remove = ohci_usb_remove,
   	.ops	= &ohci_usb_ops,
   	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */

HCCA is communication area ?

Quoted 7 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 115

Quoted 2 lines
drivers/usb/host/ohci-generic.c +1 -0
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
   };

Ah. Perhaps this is also what Romain needs for fixing the problem they see on an Apple platform, and would be more palatable to Marek to apply generally to USB host drivers (and switch the ones that use DM_FLAG_OS_PREPARE today?) ?

Quoted 6 lines
Quoted 2 lines

This works, but maybe we should instead unconditionally call usb_stop() before booting ?

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

#7 lore raw
Quoted 70 lines · Marek Vasut
Quoted 69 lines · Tom Rini
Quoted 67 lines · Marek Vasut
Quoted 46 lines · Tom Rini
Quoted 44 lines · khaliforce

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_ACTIVE_DMA. Their controllers can remain active when U-Boot hands control to the operating system.

An active controller may continue DMA after the operating system starts reusing U-Boot memory. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_ACTIVE_DMA on both drivers so their existing remove callbacks stop the controllers during OS preparation.

---
Changes in v2:
- Use DM_FLAG_ACTIVE_DMA as suggested by Neil Armstrong.

Retested on MangoPi MQ Pro with the downstream D1 port based on U-Boot v2026.10 and Linux 6.1:
- Read a 64 GB FAT32 USB device in U-Boot.
- Verified a 4096-byte read against Linux using CRC32.
- Booted Linux without running "usb stop".
- Confirmed USB reads, Wi-Fi and SSH after the handoff.
- Observed no panic, Bad page or failed services.

Standalone builds pass for RISC-V64, ARM64 and ARM32 on upstream main. RISC-V64 QEMU boots. Checkpatch reports no errors or warnings.

   drivers/usb/host/ehci-generic.c | 2 +-
   drivers/usb/host/ohci-generic.c | 3 ++-
   2 files changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-generic.c +1 -1
index 1ae3619ce25..57f1bcbd9c0 100644
@@ -167,5 +167,5 @@ U_BOOT_DRIVER(ehci_generic) = {
   	.remove = ehci_usb_remove,
   	.ops	= &ehci_usb_ops,
   	.priv_auto	= sizeof(struct generic_ehci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
   };
drivers/usb/host/ohci-generic.c +0 -0
index cc44226f5e0..7493750f8d1 100644
Quoted 8 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 113

Quoted 8 lines
drivers/usb/host/ohci-generic.c +1 -1
@@ -110,5 +110,6 @@ U_BOOT_DRIVER(ohci_generic) = {
   	.remove = ohci_usb_remove,
   	.ops	= &ohci_usb_ops,
   	.priv_auto	= sizeof(struct generic_ohci),
-	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
+	/* Stop HCCA DMA before Linux reuses the controller memory. */

HCCA is communication area ?

Quoted 7 lines

drivers/usb/host/ohci-generic.c U_BOOT_DRIVER(ohci_generic) = { · line 115

Quoted 2 lines
drivers/usb/host/ohci-generic.c +1 -0
+	.flags	= DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_ACTIVE_DMA,
   };

Ah. Perhaps this is also what Romain needs for fixing the problem they see on an Apple platform, and would be more palatable to Marek to apply generally to USB host drivers (and switch the ones that use DM_FLAG_OS_PREPARE today?) ?

This works, but maybe we should instead unconditionally call usb_stop() before booting ?

Quoted 7 lines
Quoted 3 lines

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

Host or gadget isn't the point here, it's that we used to hard-code the stop function call for the non-DM driver and now we have driver model and flags. Everything should be able to properly unwind with flags being set.

Signature · 1 line
Tom
#8 lore raw

On 10/12/26 12:31 AM, Tom Rini wrote:

[...]

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

Quoted 4 lines

Host or gadget isn't the point here, it's that we used to hard-code the stop function call for the non-DM driver and now we have driver model and flags. Everything should be able to properly unwind with flags being set.

So what needs to be tested is whether the flags are enough to properly stop devices downstream of the controller, or whether we need something more, possibly equivalent of "usb stop" in the USB uclass pre_remove callback or some such thing.

#9 lore raw
Quoted 12 lines · Marek Vasut

On 10/12/26 12:31 AM, Tom Rini wrote:

[...]

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

Quoted 8 lines
Quoted 4 lines

Host or gadget isn't the point here, it's that we used to hard-code the stop function call for the non-DM driver and now we have driver model and flags. Everything should be able to properly unwind with flags being set.

So what needs to be tested is whether the flags are enough to properly stop devices downstream of the controller, or whether we need something more, possibly equivalent of "usb stop" in the USB uclass pre_remove callback or some such thing.

What more testing do we need at this point to see what DM-related-unwinding that usb_stop does that isn't also covered by adding this flag to the controllers that are missing it?

Signature · 1 line
Tom
#10 lore raw
Quoted 17 lines · Tom Rini
Quoted 16 lines · Marek Vasut

On 10/12/26 12:31 AM, Tom Rini wrote:

[...]

Quoted 12 lines
Quoted 7 lines
Quoted 3 lines

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

Host or gadget isn't the point here, it's that we used to hard-code the stop function call for the non-DM driver and now we have driver model and flags. Everything should be able to properly unwind with flags being set.

Quoted 8 lines
Quoted 4 lines

So what needs to be tested is whether the flags are enough to properly stop devices downstream of the controller, or whether we need something more, possibly equivalent of "usb stop" in the USB uclass pre_remove callback or some such thing.

What more testing do we need at this point to see what DM-related-unwinding that usb_stop does that isn't also covered by adding this flag to the controllers that are missing it?

Plug two or more hubs into each other and then into the controller, then connect at least one USB stick into each hub, start booting and see if those devices get removed in the correct order (stick furthest from the controller first, nearest stick one before last, controller last). This is my concern here.

#11 lore raw
Quoted 23 lines · Marek Vasut
Quoted 22 lines · Tom Rini
Quoted 20 lines · Marek Vasut

On 10/12/26 12:31 AM, Tom Rini wrote:

[...]

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

Quoted 4 lines

Host or gadget isn't the point here, it's that we used to hard-code the stop function call for the non-DM driver and now we have driver model and flags. Everything should be able to properly unwind with flags being set.

So what needs to be tested is whether the flags are enough to properly stop devices downstream of the controller, or whether we need something more, possibly equivalent of "usb stop" in the USB uclass pre_remove callback or some such thing.

Quoted 8 lines
Quoted 3 lines

What more testing do we need at this point to see what DM-related-unwinding that usb_stop does that isn't also covered by adding this flag to the controllers that are missing it?

Plug two or more hubs into each other and then into the controller, then connect at least one USB stick into each hub, start booting and see if those devices get removed in the correct order (stick furthest from the controller first, nearest stick one before last, controller last). This is my concern here.

Thanks for elaborating.

Signature · 1 line
Tom
#12 lore raw
Quoted 27 lines · Tom Rini
Quoted 26 lines · Marek Vasut
Quoted 25 lines · Tom Rini
Quoted 12 lines · Marek Vasut

On 10/12/26 12:31 AM, Tom Rini wrote:

[...]

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

Quoted 8 lines
Quoted 4 lines

Host or gadget isn't the point here, it's that we used to hard-code the stop function call for the non-DM driver and now we have driver model and flags. Everything should be able to properly unwind with flags being set.

So what needs to be tested is whether the flags are enough to properly stop devices downstream of the controller, or whether we need something more, possibly equivalent of "usb stop" in the USB uclass pre_remove callback or some such thing.

What more testing do we need at this point to see what DM-related-unwinding that usb_stop does that isn't also covered by adding this flag to the controllers that are missing it?

Quoted 7 lines
Quoted 5 lines

Plug two or more hubs into each other and then into the controller, then connect at least one USB stick into each hub, start booting and see if those devices get removed in the correct order (stick furthest from the controller first, nearest stick one before last, controller last). This is my concern here.

Thanks for elaborating.

Sure. Sorry for the delay.

author
#13 lore raw
In reply to Marek Vasut

Hi Marek, Tom,

I retested v2 on MangoPi MQ Pro using the downstream D1 port based on U-Boot v2026.10.

The boot path was U-Boot -> GRUB EFI -> Linux 7.3.1.

Two USB hubs were cascaded, with one flash drive on each hub:
- Near: 64GB Samsung Flash Drive FIT, attached to the first hub.
- Far: 8GB USB Flash Disk, attached to the second hub.

I added temporary port-path and device-identity traces. I matched the serial numbers against Linux to confirm each drive. No manual "usb stop" command was used.

Relevant excerpts follow, with intermediate lines omitted:

USBTRACE identity path=usb@4200000/0/1/2/3 vid=090c pid=1000 serial=5610050000154305 product="USB Flash Disk"
USBTRACE done path=usb@4200000/0/1/2/3 driver=usb_mass_storage flags=4000 active=0
USBTRACE done path=usb@4200000/0/1/2 driver=usb_hub flags=4000 active=0 USBTRACE identity path=usb@4200000/0/1/3 vid=090c pid=1000 serial=0352315070000417 product="Flash Drive FIT"
USBTRACE done path=usb@4200000/0/1/3 driver=usb_mass_storage flags=4000 active=0 USBTRACE done path=usb@4200000/0/1 driver=usb_hub flags=4000 active=0 USBTRACE done path=usb@4200000/0 driver=usb_hub flags=4000 active=0 USBTRACE ehci_deregister dev=usb@4200000 ret=0
USBTRACE done path=usb@4200000 driver=ehci_generic flags=4600 active=0 USBTRACE ohci_deregister dev=usb@4200400 ret=0

The farther drive was removed before the nearer drive. Children were removed before their parent hubs and the EHCI controller.

Linux booted successfully, detected both drives, and reported no failed services.

Both drives used EHCI. OHCI had no external devices.
I lack suitable hardware to test downstream device removal through OHCI.

Thanks,
khaliforce

Quoted 31 lines · Marek Vasut
Quoted 17 lines · Tom Rini
Quoted 16 lines · Marek Vasut

On 10/12/26 12:31 AM, Tom Rini wrote:

[...]

Quoted 12 lines
Quoted 7 lines
Quoted 3 lines

I believe the answer there is that we have flags to handle this problem generically rather than hard-coding a call in every arch's boot_prep_linux or similar like we had to with the old USB gadget stack.

This is shutting down host, not gadget. And I believe usb_stop() is necessary to correctly shut down the devices on the USB bus, while the DM_FLAG_ACTIVE_DMA flag is necessary to shut down the controller, so both are needed.

Host or gadget isn't the point here, it's that we used to hard-code the stop function call for the non-DM driver and now we have driver model and flags. Everything should be able to properly unwind with flags being set.

Quoted 8 lines
Quoted 4 lines

So what needs to be tested is whether the flags are enough to properly stop devices downstream of the controller, or whether we need something more, possibly equivalent of "usb stop" in the USB uclass pre_remove callback or some such thing.

What more testing do we need at this point to see what DM-related-unwinding that usb_stop does that isn't also covered by adding this flag to the controllers that are missing it?

Plug two or more hubs into each other and then into the controller, then connect at least one USB stick into each hub, start booting and see if those devices get removed in the correct order (stick furthest from the controller first, nearest stick one before last, controller last). This is my concern here.

#14 lore raw
Quoted 31 lines · khaliforce

Hi Marek, Tom,

I retested v2 on MangoPi MQ Pro using the downstream D1 port based on U-Boot v2026.10.

The boot path was U-Boot -> GRUB EFI -> Linux 7.3.1.

Two USB hubs were cascaded, with one flash drive on each hub:
- Near: 64GB Samsung Flash Drive FIT, attached to the first hub.
- Far: 8GB USB Flash Disk, attached to the second hub.

I added temporary port-path and device-identity traces. I matched the serial numbers against Linux to confirm each drive. No manual "usb stop" command was used.

Relevant excerpts follow, with intermediate lines omitted:

USBTRACE identity path=usb@4200000/0/1/2/3 vid=090c pid=1000 serial=5610050000154305 product="USB Flash Disk"
USBTRACE done path=usb@4200000/0/1/2/3 driver=usb_mass_storage flags=4000 active=0
USBTRACE done path=usb@4200000/0/1/2 driver=usb_hub flags=4000 active=0 USBTRACE identity path=usb@4200000/0/1/3 vid=090c pid=1000 serial=0352315070000417 product="Flash Drive FIT"
USBTRACE done path=usb@4200000/0/1/3 driver=usb_mass_storage flags=4000 active=0 USBTRACE done path=usb@4200000/0/1 driver=usb_hub flags=4000 active=0 USBTRACE done path=usb@4200000/0 driver=usb_hub flags=4000 active=0 USBTRACE ehci_deregister dev=usb@4200000 ret=0
USBTRACE done path=usb@4200000 driver=ehci_generic flags=4600 active=0 USBTRACE ohci_deregister dev=usb@4200400 ret=0

Quoted 8 lines

The farther drive was removed before the nearer drive. Children were removed before their parent hubs and the EHCI controller.

Linux booted successfully, detected both drives, and reported no failed services.

Both drives used EHCI. OHCI had no external devices.
I lack suitable hardware to test downstream device removal through OHCI.

That resolves my concern. Thank you for testing.

author
#15 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 1 line

HCCA is communication area ?

Yes, HCCA stands for Host Controller Communications Area. The comment refers to stopping OHCI DMA accesses to that memory before OS handoff.

Thanks,
khaliforce

#17 lore raw
Quoted 3 lines · khaliforce

Hi Marek, Tom,

A gentle ping on this v2 patch.

The plan is to land this in 2027.01 release.

Can you please send a V3 and use your full name in the patch authorship ?

Thank you

author
#18 lore raw

Hi Marek,

For privacy reasons, I prefer to keep using my established pseudonym, khaliforce.

The v2 patch code remains unchanged.
Could you apply v2 with the existing authorship and Signed-off-by, without a v3 resend?

Thanks,
khaliforce

Quoted 9 lines · Marek Vasut
Quoted 3 lines · khaliforce

Hi Marek, Tom,

A gentle ping on this v2 patch.

The plan is to land this in 2027.01 release.

Can you please send a V3 and use your full name in the patch authorship ?

Thank you

#19 lore raw
In reply to khaliforce
Quoted 4 lines · khaliforce

The generic OHCI and EHCI drivers provide remove callbacks, but do not set DM_FLAG_ACTIVE_DMA. Their controllers can remain active when U-Boot hands control to the operating system.

Quoted 8 lines

An active controller may continue DMA after the operating system starts reusing U-Boot memory. In particular, OHCI may continue accessing its HCCA.

Set DM_FLAG_ACTIVE_DMA on both drivers so their existing remove callbacks stop the controllers during OS preparation.

Signature · 1 line
Tom