patch "usb: dwc2: Fix DMA cache alignment issues" added to usb-linus
Subsystems (3)
This is a note to let you know that I've just added the patch titled
usb: dwc2: Fix DMA cache alignment issues
to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From 4a4863bf2e7932e584a3a462d3c6daf891142ddc Mon Sep 17 00:00:00 2001
From: Martin Schiller <[email protected]>
Date: Mon, 18 Feb 2019 07:37:30 +0100
Subject: usb: dwc2: Fix DMA cache alignment issues
Insert a padding between data and the stored_xfer_buffer pointer to ensure they are not on the same cache line.
Otherwise, the stored_xfer_buffer gets corrupted for IN URBs on non-cache-coherent systems. (In my case: Lantiq xRX200 MIPS)
--- drivers/usb/dwc2/hcd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/dwc2/hcd.c +7 -3
@@ -2480,8 +2480,10 @@ static void dwc2_free_dma_aligned_buffer(struct urb *urb)return ;/* Restore urb->transfer_buffer from the end of the allocated area */ -memcpy (&stored_xfer_buffer, urb->transfer_buffer + - urb->transfer_buffer_length,sizeof (urb->transfer_buffer)); +memcpy (&stored_xfer_buffer, +PTR_ALIGN (urb->transfer_buffer + urb->transfer_buffer_length, +dma_get_cache_alignment ()), +sizeof (urb->transfer_buffer));if (usb_urb_dir_in (urb)) {if (usb_pipeisoc (urb->pipe))
@@ -2513,6 +2515,7 @@ static int dwc2_alloc_dma_aligned_buffer(struct urb *urb, gfp_t mem_flags)* DMA */ kmalloc_size = urb->transfer_buffer_length + + (dma_get_cache_alignment () -1 ) +sizeof (urb->transfer_buffer); kmalloc_ptr =kmalloc (kmalloc_size, mem_flags);
@@ -2523,7 +2526,8 @@ static int dwc2_alloc_dma_aligned_buffer(struct urb *urb, gfp_t mem_flags)* Position value of original urb->transfer_buffer pointer to the end * of allocation for later referencing */ -memcpy (kmalloc_ptr + urb->transfer_buffer_length, +memcpy (PTR_ALIGN (kmalloc_ptr + urb->transfer_buffer_length, +dma_get_cache_alignment ()), &urb->transfer_buffer,sizeof (urb->transfer_buffer));if (usb_urb_dir_out (urb))
Signature · 1 line
2.21.0