usb: ehci: do not invalidate a NULL buffer
Subsystems (2)
RFC PATCH 1/1 usb: ehci: do not invalidate a NULL buffer
Its a valid use case to call ehci_submit_async() with a NULL buffer with length 0. E.g. from usb_set_configuration().
As invalidate_dcache_range() isn't able to judge if the address NULL is valid or not (depending on the SoC hardware configuration it might be valid) do the check in ehci_submit_async() as here we know that we don't have to invalidate such a buffer.
---
Notes:
This was found on an older vendor specific U-Boot on an ARMv8 SoC with a MMU configuration where address 0x00000000 is invalid.
The callstack I've seen is
usb_set_configuration(), calls
-> usb_control_msg() with *data == NULL and size == 0
-> submit_control_msg()
-> _ehci_submit_control_msg()
-> ehci_submit_async()
ehci_submit_async() called __asm_invalidate_dcache_range() from arch/arm/cpu/armv8/cache.S, then. Resulting in an exception trying to use address 0 in x0 (dc ivac, x0).
I'm slightly unsure why this hasn't been catched or complained about previously, already. Maybe I missed anything while working with an older vendor U-Boot? Sorry in this case.
Best regards
Dirk
--- drivers/usb/host/ehci-hcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-hcd.c +3 -2
@@ -595,8 +595,9 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,* dangerous operation, it's responsibility of the calling * code to make sure enough space is reserved. */ -invalidate_dcache_range ((unsigned long )buffer, -ALIGN ((unsigned long )buffer + length,ARCH_DMA_MINALIGN )); +if (buffer !=NULL && length >0 ) +invalidate_dcache_range ((unsigned long )buffer, +ALIGN ((unsigned long )buffer + length,ARCH_DMA_MINALIGN ));/* Check that the TD processing happened */ if (QT_TOKEN_GET_STATUS (token) &QT_TOKEN_STATUS_ACTIVE )
Signature · 1 line
2.14.1
RFC PATCH 1/1 usb: ehci: do not invalidate a NULL buffer
Quoted 9 lines · Dirk Behme
Its a valid use case to call
ehci_submit_async()with a NULL buffer with length 0. E.g. fromusb_set_configuration().As
invalidate_dcache_range()isn't able to judge if the address NULL is valid or not (depending on the SoC hardware configuration it might be valid) do the check inehci_submit_async()as here we know that we don't have to invalidate such a buffer.Signed-off-by Dirk Behme <[email protected]>
Looks OK, what about the other cache ops in EHCI, are they also affected?
Quoted 46 lines
---
Notes:This was found on an older vendor specific U-Boot on an ARMv8 SoC with a MMU configuration where address
0x00000000is invalid.The callstack I've seen is
usb_set_configuration(), calls
->usb_control_msg()with *data == NULL and size == 0
->submit_control_msg()
->_ehci_submit_control_msg()-> ehci_submit_async()
ehci_submit_async()called__asm_invalidate_dcache_range()fromarch/arm/cpu/armv8/cache.S, then. Resulting in an exception trying to use address 0 in x0 (dc ivac, x0).I'm slightly unsure why this hasn't been catched or complained about previously, already. Maybe I missed anything while working with an older vendor U-Boot? Sorry in this case.
Best regards
Dirk
--- drivers/usb/host/ehci-hcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/usb/host/ehci-hcd.c +3
-2@@ -595,8 +595,9 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,* dangerous operation, it's responsibility of the calling * code to make sure enough space is reserved. */ -invalidate_dcache_range ((unsigned long )buffer, -ALIGN ((unsigned long )buffer + length,ARCH_DMA_MINALIGN )); +if (buffer !=NULL && length >0 ) +invalidate_dcache_range ((unsigned long )buffer, +ALIGN ((unsigned long )buffer + length,ARCH_DMA_MINALIGN ));/* Check that the TD processing happened */ if (QT_TOKEN_GET_STATUS (token) &QT_TOKEN_STATUS_ACTIVE )
Signature · 2 lines
Best regards, Marek Vasut
RFC PATCH 1/1 usb: ehci: do not invalidate a NULL buffer
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Dirk Behme
Its a valid use case to call
ehci_submit_async()with a NULL buffer with length 0. E.g. fromusb_set_configuration().
Quoted 8 lines
Quoted 6 lines
As
invalidate_dcache_range()isn't able to judge if the address NULL is valid or not (depending on the SoC hardware configuration it might be valid) do the check inehci_submit_async()as here we know that we don't have to invalidate such a buffer.Signed-off-by Dirk Behme <[email protected]>Looks OK,
Ok, thanks, I'll drop the RFC, then.
Quoted 1 line
what about the other cache ops in EHCI, are they also affected?
This was found based on a MMU configuration excluding address 0x00000000. Fixing this one location made a usb start and reading from an USB stick work.
So either only this location is affected, or above use case doesn't cover all relevant path. In latter case I don't have enough USB knowledge to evaluate all path by review.
Best regards
Dirk
Quoted 46 lines
Quoted 46 lines
---
Notes:This was found on an older vendor specific U-Boot on an ARMv8 SoC with a MMU configuration where address
0x00000000is invalid.The callstack I've seen is
usb_set_configuration(), calls
->usb_control_msg()with *data == NULL and size == 0
->submit_control_msg()-> _ehci_submit_control_msg() -> ehci_submit_async()
ehci_submit_async()called__asm_invalidate_dcache_range()fromarch/arm/cpu/armv8/cache.S, then. Resulting in an exception trying to use address 0 in x0 (dc ivac, x0).I'm slightly unsure why this hasn't been catched or complained about previously, already. Maybe I missed anything while working with an older vendor U-Boot? Sorry in this case.
Best regards
Dirk
--- drivers/usb/host/ehci-hcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/usb/host/ehci-hcd.c +3
-2@@ -595,8 +595,9 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,* dangerous operation, it's responsibility of the calling * code to make sure enough space is reserved. */ -invalidate_dcache_range ((unsigned long )buffer, -ALIGN ((unsigned long )buffer + length,ARCH_DMA_MINALIGN )); +if (buffer !=NULL && length >0 ) +invalidate_dcache_range ((unsigned long )buffer, +ALIGN ((unsigned long )buffer + length,ARCH_DMA_MINALIGN ));/* Check that the TD processing happened */ if (QT_TOKEN_GET_STATUS (token) &QT_TOKEN_STATUS_ACTIVE )
Marek Vasut
AppliedRFC PATCH 1/1 usb: ehci: do not invalidate a NULL buffer
Quoted 21 lines · Dirk Behme
Quoted 4 lines · Marek Vasut
Quoted 3 lines · Dirk Behme
Its a valid use case to call
ehci_submit_async()with a NULL buffer with length 0. E.g. fromusb_set_configuration().Quoted 8 lines
Quoted 6 lines
As
invalidate_dcache_range()isn't able to judge if the address NULL is valid or not (depending on the SoC hardware configuration it might be valid) do the check inehci_submit_async()as here we know that we don't have to invalidate such a buffer.Signed-off-by Dirk Behme <[email protected]>Looks OK,
Ok, thanks, I'll drop the RFC, then.
Quoted 1 line
what about the other cache ops in EHCI, are they also affected?
Quoted 7 lines
This was found based on a MMU configuration excluding address
0x00000000. Fixing this one location made a usb start and reading from an USB stick work.So either only this location is affected, or above use case doesn't cover all relevant path. In latter case I don't have enough USB knowledge to evaluate all path by review.
Well, I skimmed through the rest of the function and this seems to be the only spot where it could be problematic if length == 0 , so this is the correct fix.
Applied, thanks.
Quoted 51 lines
Best regards
Dirk
Quoted 46 lines
Quoted 46 lines
---
Notes:This was found on an older vendor specific U-Boot on an ARMv8 SoC with a MMU configuration where address
0x00000000is invalid.The callstack I've seen is
usb_set_configuration(), calls
->usb_control_msg()with *data == NULL and size == 0 ->submit_control_msg()
->_ehci_submit_control_msg()
->ehci_submit_async()
ehci_submit_async()called__asm_invalidate_dcache_range()fromarch/arm/cpu/armv8/cache.S, then. Resulting in an exception trying to use address 0 in x0 (dc ivac, x0).I'm slightly unsure why this hasn't been catched or complained about previously, already. Maybe I missed anything while working with an older vendor U-Boot? Sorry in this case.
Best regards
Dirk
---
drivers/usb/host/ehci-hcd.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)drivers/usb/host/ehci-hcd.c +3
-2@@ -595,8 +595,9 @@ ehci_submit_async(struct usb_device *dev,unsigned long pipe, void *buffer, * dangerous operation, it's responsibility of the calling * code to make sure enough space is reserved. */ - invalidate_dcache_range((unsigned long)buffer, - ALIGN((unsigned long)buffer + length, ARCH_DMA_MINALIGN)); + if (buffer != NULL && length > 0) + invalidate_dcache_range((unsigned long)buffer, + ALIGN((unsigned long)buffer + length, ARCH_DMA_MINALIGN)); /* Check that the TD processing happened */ if (QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE)
Signature · 2 lines
Best regards, Marek Vasut