* [PATCH] usb: stop generic OHCI and EHCI at OS handoff
@ 2026-10-06 11:13 khaliforce
2026-10-06 13:22 ` Neil Armstrong
0 siblings, 1 reply; 9+ messages in thread
From: khaliforce @ 2026-10-06 11:13 UTC (permalink / raw)
To: u-boot; +Cc: Marek Vasut, Tom Rini
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.
Signed-off-by: khaliforce <kforce@gmail.com>
---
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(-)
diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
index 1ae3619ce25..8075fb069f1 100644
--- a/drivers/usb/host/ehci-generic.c
+++ b/drivers/usb/host/ehci-generic.c
@@ -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,
};
diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
index cc44226f5e0..6cc26e2d3c0 100644
--- a/drivers/usb/host/ohci-generic.c
+++ b/drivers/usb/host/ohci-generic.c
@@ -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,
};
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] usb: stop generic OHCI and EHCI at OS handoff
2026-10-06 11:13 [PATCH] usb: stop generic OHCI and EHCI at OS handoff khaliforce
@ 2026-10-06 13:22 ` Neil Armstrong
2026-10-06 15:58 ` [PATCH v2] " khaliforce
0 siblings, 1 reply; 9+ messages in thread
From: Neil Armstrong @ 2026-10-06 13:22 UTC (permalink / raw)
To: u-boot
On 10/6/26 13:13, khaliforce wrote:
> 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
>
> Signed-off-by: khaliforce <kforce@gmail.com>
> ---
> 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(-)
>
> diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
> index 1ae3619ce25..8075fb069f1 100644
> --- a/drivers/usb/host/ehci-generic.c
> +++ b/drivers/usb/host/ehci-generic.c
> @@ -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,
> };
> diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
> index cc44226f5e0..6cc26e2d3c0 100644
> --- a/drivers/usb/host/ohci-generic.c
> +++ b/drivers/usb/host/ohci-generic.c
> @@ -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,
> };
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] usb: stop generic OHCI and EHCI at OS handoff
2026-10-06 13:22 ` Neil Armstrong
@ 2026-10-06 15:58 ` khaliforce
2026-10-06 16:10 ` Tom Rini
0 siblings, 1 reply; 9+ messages in thread
From: khaliforce @ 2026-10-06 15:58 UTC (permalink / raw)
To: u-boot; +Cc: Neil Armstrong, Marek Vasut, Tom Rini
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.
Signed-off-by: khaliforce <kforce@gmail.com>
---
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(-)
diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
index 1ae3619ce25..57f1bcbd9c0 100644
--- a/drivers/usb/host/ehci-generic.c
+++ b/drivers/usb/host/ehci-generic.c
@@ -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,
};
diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
index cc44226f5e0..7493750f8d1 100644
--- a/drivers/usb/host/ohci-generic.c
+++ b/drivers/usb/host/ohci-generic.c
@@ -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,
};
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] usb: stop generic OHCI and EHCI at OS handoff
2026-10-06 15:58 ` [PATCH v2] " khaliforce
@ 2026-10-06 16:10 ` Tom Rini
2026-10-11 15:16 ` Marek Vasut
0 siblings, 1 reply; 9+ messages in thread
From: Tom Rini @ 2026-10-06 16:10 UTC (permalink / raw)
To: khaliforce, Romain Beauxis; +Cc: u-boot, Neil Armstrong, Marek Vasut
[-- Attachment #1: Type: text/plain, Size: 2597 bytes --]
On Wed, Oct 07, 2026 at 12:58:33AM +0900, khaliforce wrote:
> 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.
>
> Signed-off-by: khaliforce <kforce@gmail.com>
> ---
> 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(-)
>
> diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
> index 1ae3619ce25..57f1bcbd9c0 100644
> --- a/drivers/usb/host/ehci-generic.c
> +++ b/drivers/usb/host/ehci-generic.c
> @@ -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,
> };
> diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
> index cc44226f5e0..7493750f8d1 100644
> --- a/drivers/usb/host/ohci-generic.c
> +++ b/drivers/usb/host/ohci-generic.c
> @@ -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?) ?
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] usb: stop generic OHCI and EHCI at OS handoff
2026-10-06 16:10 ` Tom Rini
@ 2026-10-11 15:16 ` Marek Vasut
2026-10-11 22:03 ` Tom Rini
2026-10-12 2:32 ` khaliforce
0 siblings, 2 replies; 9+ messages in thread
From: Marek Vasut @ 2026-10-11 15:16 UTC (permalink / raw)
To: Tom Rini, khaliforce, Romain Beauxis; +Cc: u-boot, Neil Armstrong
On 10/6/26 6:10 PM, Tom Rini wrote:
> On Wed, Oct 07, 2026 at 12:58:33AM +0900, khaliforce wrote:
>
>> 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.
>>
>> Signed-off-by: khaliforce <kforce@gmail.com>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
>> index 1ae3619ce25..57f1bcbd9c0 100644
>> --- a/drivers/usb/host/ehci-generic.c
>> +++ b/drivers/usb/host/ehci-generic.c
>> @@ -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,
>> };
>> diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
>> index cc44226f5e0..7493750f8d1 100644
>> --- a/drivers/usb/host/ohci-generic.c
>> +++ b/drivers/usb/host/ohci-generic.c
>> @@ -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 ?
>> + .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 ?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] usb: stop generic OHCI and EHCI at OS handoff
2026-10-11 15:16 ` Marek Vasut
@ 2026-10-11 22:03 ` Tom Rini
2026-10-11 22:24 ` Marek Vasut
2026-10-12 2:32 ` khaliforce
1 sibling, 1 reply; 9+ messages in thread
From: Tom Rini @ 2026-10-11 22:03 UTC (permalink / raw)
To: Marek Vasut; +Cc: khaliforce, Romain Beauxis, u-boot, Neil Armstrong
[-- Attachment #1: Type: text/plain, Size: 3297 bytes --]
On Sun, Oct 11, 2026 at 05:16:41PM +0200, Marek Vasut wrote:
> On 10/6/26 6:10 PM, Tom Rini wrote:
> > On Wed, Oct 07, 2026 at 12:58:33AM +0900, khaliforce wrote:
> >
> > > 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.
> > >
> > > Signed-off-by: khaliforce <kforce@gmail.com>
> > > ---
> > > 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(-)
> > >
> > > diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
> > > index 1ae3619ce25..57f1bcbd9c0 100644
> > > --- a/drivers/usb/host/ehci-generic.c
> > > +++ b/drivers/usb/host/ehci-generic.c
> > > @@ -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,
> > > };
> > > diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
> > > index cc44226f5e0..7493750f8d1 100644
> > > --- a/drivers/usb/host/ohci-generic.c
> > > +++ b/drivers/usb/host/ohci-generic.c
> > > @@ -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 ?
>
> > > + .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 ?
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.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] usb: stop generic OHCI and EHCI at OS handoff
2026-10-11 22:03 ` Tom Rini
@ 2026-10-11 22:24 ` Marek Vasut
2026-10-11 22:31 ` Tom Rini
0 siblings, 1 reply; 9+ messages in thread
From: Marek Vasut @ 2026-10-11 22:24 UTC (permalink / raw)
To: Tom Rini; +Cc: khaliforce, Romain Beauxis, u-boot, Neil Armstrong
On 10/12/26 12:03 AM, Tom Rini wrote:
> On Sun, Oct 11, 2026 at 05:16:41PM +0200, Marek Vasut wrote:
>> On 10/6/26 6:10 PM, Tom Rini wrote:
>>> On Wed, Oct 07, 2026 at 12:58:33AM +0900, khaliforce wrote:
>>>
>>>> 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.
>>>>
>>>> Signed-off-by: khaliforce <kforce@gmail.com>
>>>> ---
>>>> 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(-)
>>>>
>>>> diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
>>>> index 1ae3619ce25..57f1bcbd9c0 100644
>>>> --- a/drivers/usb/host/ehci-generic.c
>>>> +++ b/drivers/usb/host/ehci-generic.c
>>>> @@ -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,
>>>> };
>>>> diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
>>>> index cc44226f5e0..7493750f8d1 100644
>>>> --- a/drivers/usb/host/ohci-generic.c
>>>> +++ b/drivers/usb/host/ohci-generic.c
>>>> @@ -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 ?
>>
>>>> + .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 ?
>
> 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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] usb: stop generic OHCI and EHCI at OS handoff
2026-10-11 22:24 ` Marek Vasut
@ 2026-10-11 22:31 ` Tom Rini
0 siblings, 0 replies; 9+ messages in thread
From: Tom Rini @ 2026-10-11 22:31 UTC (permalink / raw)
To: Marek Vasut; +Cc: khaliforce, Romain Beauxis, u-boot, Neil Armstrong
[-- Attachment #1: Type: text/plain, Size: 4162 bytes --]
On Mon, Oct 12, 2026 at 12:24:38AM +0200, Marek Vasut wrote:
> On 10/12/26 12:03 AM, Tom Rini wrote:
> > On Sun, Oct 11, 2026 at 05:16:41PM +0200, Marek Vasut wrote:
> > > On 10/6/26 6:10 PM, Tom Rini wrote:
> > > > On Wed, Oct 07, 2026 at 12:58:33AM +0900, khaliforce wrote:
> > > >
> > > > > 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.
> > > > >
> > > > > Signed-off-by: khaliforce <kforce@gmail.com>
> > > > > ---
> > > > > 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(-)
> > > > >
> > > > > diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c
> > > > > index 1ae3619ce25..57f1bcbd9c0 100644
> > > > > --- a/drivers/usb/host/ehci-generic.c
> > > > > +++ b/drivers/usb/host/ehci-generic.c
> > > > > @@ -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,
> > > > > };
> > > > > diff --git a/drivers/usb/host/ohci-generic.c b/drivers/usb/host/ohci-generic.c
> > > > > index cc44226f5e0..7493750f8d1 100644
> > > > > --- a/drivers/usb/host/ohci-generic.c
> > > > > +++ b/drivers/usb/host/ohci-generic.c
> > > > > @@ -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 ?
> > >
> > > > > + .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 ?
> >
> > 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.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] usb: stop generic OHCI and EHCI at OS handoff
2026-10-11 15:16 ` Marek Vasut
2026-10-11 22:03 ` Tom Rini
@ 2026-10-12 2:32 ` khaliforce
1 sibling, 0 replies; 9+ messages in thread
From: khaliforce @ 2026-10-12 2:32 UTC (permalink / raw)
To: Marek Vasut, Tom Rini, Romain Beauxis; +Cc: u-boot, Neil Armstrong
Hi Marek,
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-10-12 2:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-06 11:13 [PATCH] usb: stop generic OHCI and EHCI at OS handoff khaliforce
2026-10-06 13:22 ` Neil Armstrong
2026-10-06 15:58 ` [PATCH v2] " khaliforce
2026-10-06 16:10 ` Tom Rini
2026-10-11 15:16 ` Marek Vasut
2026-10-11 22:03 ` Tom Rini
2026-10-11 22:24 ` Marek Vasut
2026-10-11 22:31 ` Tom Rini
2026-10-12 2:32 ` khaliforce
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.