linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ethernet: cxgb4: Fix dma_unmap_sg() nents value
@ 2025-06-23 12:25 Thomas Fourier
  2025-06-24 15:17 ` Potnuri Bharat Teja
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Fourier @ 2025-06-23 12:25 UTC (permalink / raw)
  Cc: Thomas Fourier, Potnuri Bharat Teja, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Santosh Rastapur,
	Arjun Vynipadath, Michael Werner, Ganesh GR, netdev, linux-kernel

The dma_unmap_sg() functions should be called with the same nents as the
dma_map_sg(), not the value the map function returned.

Fixes: 8b4e6b3ca2ed ("cxgb4: Add HMA support")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 51395c96b2e9..73bb1f413761 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -3998,7 +3998,7 @@ static void adap_free_hma_mem(struct adapter *adapter)
 
 	if (adapter->hma.flags & HMA_DMA_MAPPED_FLAG) {
 		dma_unmap_sg(adapter->pdev_dev, adapter->hma.sgt->sgl,
-			     adapter->hma.sgt->nents, DMA_BIDIRECTIONAL);
+			     adapter->hma.sgt->orig_nents, DMA_BIDIRECTIONAL);
 		adapter->hma.flags &= ~HMA_DMA_MAPPED_FLAG;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] ethernet: cxgb4: Fix dma_unmap_sg() nents value
  2025-06-23 12:25 [PATCH net] ethernet: cxgb4: Fix dma_unmap_sg() nents value Thomas Fourier
@ 2025-06-24 15:17 ` Potnuri Bharat Teja
  2025-06-25 13:27   ` Thomas Fourier
  0 siblings, 1 reply; 3+ messages in thread
From: Potnuri Bharat Teja @ 2025-06-24 15:17 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On Monday, June 06/23/25, 2025 at 14:25:55 +0200, Thomas Fourier wrote:
> The dma_unmap_sg() functions should be called with the same nents as the
> dma_map_sg(), not the value the map function returned.
> 
> Fixes: 8b4e6b3ca2ed ("cxgb4: Add HMA support")
> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
> ---
>  drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> index 51395c96b2e9..73bb1f413761 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> @@ -3998,7 +3998,7 @@ static void adap_free_hma_mem(struct adapter *adapter)
>  
>  	if (adapter->hma.flags & HMA_DMA_MAPPED_FLAG) {
>  		dma_unmap_sg(adapter->pdev_dev, adapter->hma.sgt->sgl,
> -			     adapter->hma.sgt->nents, DMA_BIDIRECTIONAL);
> +			     adapter->hma.sgt->orig_nents, DMA_BIDIRECTIONAL);
>  		adapter->hma.flags &= ~HMA_DMA_MAPPED_FLAG;
>  	}
Thanks for the patch Thomas.
this fix needs below change as well:
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -4000,7 +4000,7 @@ static void adap_free_hma_mem(struct adapter *adapter)
        }

	for_each_sg(adapter->hma.sgt->sgl, iter,	
-                   adapter->hma.sgt->orig_nents, i) {
+                   adapter->hma.sgt->nents, i) {
                page = sg_page(iter);
		if (page)
                        __free_pages(page, HMA_PAGE_ORDER);		
 

> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] ethernet: cxgb4: Fix dma_unmap_sg() nents value
  2025-06-24 15:17 ` Potnuri Bharat Teja
@ 2025-06-25 13:27   ` Thomas Fourier
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Fourier @ 2025-06-25 13:27 UTC (permalink / raw)
  To: Potnuri Bharat Teja
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On 24/06/2025 17:17, Potnuri Bharat Teja wrote:
> On Monday, June 06/23/25, 2025 at 14:25:55 +0200, Thomas Fourier wrote:
>> The dma_unmap_sg() functions should be called with the same nents as the
>> dma_map_sg(), not the value the map function returned.
>>
>> Fixes: 8b4e6b3ca2ed ("cxgb4: Add HMA support")
>> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
>> ---
>>   drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
>> index 51395c96b2e9..73bb1f413761 100644
>> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
>> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
>> @@ -3998,7 +3998,7 @@ static void adap_free_hma_mem(struct adapter *adapter)
>>   
>>   	if (adapter->hma.flags & HMA_DMA_MAPPED_FLAG) {
>>   		dma_unmap_sg(adapter->pdev_dev, adapter->hma.sgt->sgl,
>> -			     adapter->hma.sgt->nents, DMA_BIDIRECTIONAL);
>> +			     adapter->hma.sgt->orig_nents, DMA_BIDIRECTIONAL);
>>   		adapter->hma.flags &= ~HMA_DMA_MAPPED_FLAG;
>>   	}
> Thanks for the patch Thomas.
> this fix needs below change as well:
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> @@ -4000,7 +4000,7 @@ static void adap_free_hma_mem(struct adapter *adapter)
>          }
>
> 	for_each_sg(adapter->hma.sgt->sgl, iter,	
> -                   adapter->hma.sgt->orig_nents, i) {
> +                   adapter->hma.sgt->nents, i) {
>                  page = sg_page(iter);
> 		if (page)
>                          __free_pages(page, HMA_PAGE_ORDER);		
>   

I don't think this change is correct since this loop iterates over all 
the pages

allocated at line 4076, not over the dma mapped pages.

It also seems that when passing the dma addresses to hardware,

the newpage assignment is not used line 4104 and that the dma mapping

length is not given to hardware.  Is that correct?

>> -- 
>> 2.43.0
>>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-25 13:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23 12:25 [PATCH net] ethernet: cxgb4: Fix dma_unmap_sg() nents value Thomas Fourier
2025-06-24 15:17 ` Potnuri Bharat Teja
2025-06-25 13:27   ` Thomas Fourier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).