usb: dwc2: add missing SLAB_CACHE_DMA flag for desc_hsisoc_cache
Subsystems (2)
PATCH v2 1/1 usb: dwc2: add missing SLAB_CACHE_DMA flag for desc_hsisoc_cache
The desc_hsisoc_cache kmem_cache is used to allocate DMA descriptors for High-Speed isochronous transfers. These descriptors are passed to the hardware via dma_map_single() in dwc2_desc_list_alloc().
The desc_gen_cache, which serves the same purpose for other transfer types, correctly specifies SLAB_CACHE_DMA. However, desc_hsisoc_cache was created without this flag, despite both caches being used identically for DMA descriptor allocation.
Add the missing SLAB_CACHE_DMA flag to desc_hsisoc_cache for consistency and correctness on platforms with DMA zone restrictions. This also protects against future allocations from this cache that might omit GFP_DMA.
---
v2: Resend with proper formatting (previous was corrupted by email client)
--- drivers/usb/dwc2/hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc2/hcd.c +1 -1
@@ -5273,7 +5273,7 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg) hsotg->desc_hsisoc_cache =kmem_cache_create ("dwc2-hsisoc-desc" ,sizeof (struct dwc2_dma_desc ) * -MAX_DMA_DESC_NUM_HS_ISOC ,512 ,0 ,NULL ); +MAX_DMA_DESC_NUM_HS_ISOC ,512 ,SLAB_CACHE_DMA ,NULL );if (!hsotg->desc_hsisoc_cache) {dev_err (hsotg->dev,"unable to create dwc2 hs isoc desc cache\n" );
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 9 lines · Karthikeyan K S
The
desc_hsisoc_cachekmem_cacheis used to allocate DMA descriptors for High-Speed isochronous transfers. These descriptors are passed to the hardware viadma_map_single()indwc2_desc_list_alloc().The
desc_gen_cache, which serves the same purpose for other transfer types, correctly specifiesSLAB_CACHE_DMA. However,desc_hsisoc_cachewas created without this flag, despite both caches being used identically for DMA descriptor allocation.
Quoted 8 lines
Add the missing
SLAB_CACHE_DMAflag todesc_hsisoc_cachefor consistency and correctness on platforms with DMA zone restrictions. This also protects against future allocations from this cache that might omitGFP_DMA.Fixes 3b5fcc9ac2f4 ("usb: dwc2: host: use kmem cache to allocate descriptors")Signed-off-by Karthikeyan K S <[email protected]>
Nit, no blank line needed after the Fixes: line and before your s-o-b line.
Also, should this go to stable kernels?
But:
Quoted 11 lines
---
v2: Resend with proper formatting (previous was corrupted by email client)--- drivers/usb/dwc2/hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/dwc2/hcd.c +0
-0
drivers/usb/dwc2/hcd.c int dwc2_hcd_init(struct dwc2_hsotg *hsotg) · line 5276
Quoted 5 lines
drivers/usb/dwc2/hcd.c +1
-1@@ -5273,7 +5273,7 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg) hsotg->desc_hsisoc_cache =kmem_cache_create ("dwc2-hsisoc-desc" ,sizeof (struct dwc2_dma_desc ) * -MAX_DMA_DESC_NUM_HS_ISOC ,512 ,0 ,NULL ); +MAX_DMA_DESC_NUM_HS_ISOC ,512 ,SLAB_CACHE_DMA ,NULL );
Are you sure this is ok? You are now taking from a _very_ limited chunk of memory for this controller. What platform is this that requires this, and what changed to suddenly need this to be this way? The driver has been working for a very long time without this, and I am loath to change this now as it might hit many existing systems that have a very limited GFP_DMA memory range that did not expect a new allocation there now.
So I would like to find out why this is needed now, all these years later. What caused this to show up at this point in time?
thanks,
greg k-h
Hi Greg,
Thanks for the detailed review.
Quoted 2 lines
Are you sure this is ok? You are now taking from a _very_ limited chunk of memory for this controller.
All current allocation sites already pass GFP_DMA, so DMA-zone memory is already being consumed today. That said, I fully understand the concern about further constraining allocations at the cache level.
Quoted 2 lines
What platform is this that requires this, and what changed to suddenly need this to be this way?
No specific platform requires this, and nothing is broken. I noticed this during code review, as desc_gen_cache uses SLAB_CACHE_DMA while desc_hsisoc_cache does not, despite both being used for DMA descriptors.
Quoted 2 lines
So I would like to find out why this is needed now, all these years later. What caused this to show up at this point in time?
There is no functional need. The current code works correctly because GFP_DMA is always passed at allocation time. This was only a consistency cleanup, and using a Fixes tag here was incorrect.
Given that this is long-working code with no real-world issue, I agree this change is not justified and I will withdraw the patch and not resend it.
Quoted 1 line
Also, should this go to stable kernels?
No, since no bug is being fixed.
Regards,
Karthikeyan
Quoted 58 lines · Greg KH
Quoted 9 lines · Karthikeyan K S
The
desc_hsisoc_cachekmem_cacheis used to allocate DMA descriptors for High-Speed isochronous transfers. These descriptors are passed to the hardware viadma_map_single()indwc2_desc_list_alloc().The
desc_gen_cache, which serves the same purpose for other transfer types, correctly specifiesSLAB_CACHE_DMA. However,desc_hsisoc_cachewas created without this flag, despite both caches being used identically for DMA descriptor allocation.Quoted 8 lines
Add the missing
SLAB_CACHE_DMAflag todesc_hsisoc_cachefor consistency and correctness on platforms with DMA zone restrictions. This also protects against future allocations from this cache that might omitGFP_DMA.Fixes 3b5fcc9ac2f4 ("usb: dwc2: host: use kmem cache to allocate descriptors")Signed-off-by Karthikeyan K S <[email protected]>Nit, no blank line needed after the Fixes: line and before your s-o-b line.
Also, should this go to stable kernels?
But:
Quoted 11 lines
---
v2: Resend with proper formatting (previous was corrupted by email client)--- drivers/usb/dwc2/hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/dwc2/hcd.c +0
-0drivers/usb/dwc2/hcd.c int dwc2_hcd_init(struct dwc2_hsotg *hsotg) · line 5276
Quoted 5 lines
drivers/usb/dwc2/hcd.c +1
-1@@ -5273,7 +5273,7 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg) hsotg->desc_hsisoc_cache =kmem_cache_create ("dwc2-hsisoc-desc" ,sizeof (struct dwc2_dma_desc ) * -MAX_DMA_DESC_NUM_HS_ISOC ,512 ,0 ,NULL ); +MAX_DMA_DESC_NUM_HS_ISOC ,512 ,SLAB_CACHE_DMA ,NULL );Are you sure this is ok? You are now taking from a _very_ limited chunk of memory for this controller. What platform is this that requires this, and what changed to suddenly need this to be this way? The driver has been working for a very long time without this, and I am loath to change this now as it might hit many existing systems that have a very limited
GFP_DMAmemory range that did not expect a new allocation there now.So I would like to find out why this is needed now, all these years later. What caused this to show up at this point in time?
thanks,
greg k-h