Skip to content

Commit 2e7d3b6

Browse files
ivecerakuba-moo
authored andcommitted
net: atlantic: Fix DMA mapping for PTP hwts ring
Function aq_ring_hwts_rx_alloc() maps extra AQ_CFG_RXDS_DEF bytes for PTP HWTS ring but then generic aq_ring_free() does not take this into account. Create and use a specific function to free HWTS ring to fix this issue. Trace: [ 215.351607] ------------[ cut here ]------------ [ 215.351612] DMA-API: atlantic 0000:4b:00.0: device driver frees DMA memory with different size [device address=0x00000000fbdd0000] [map size=34816 bytes] [unmap size=32768 bytes] [ 215.351635] WARNING: CPU: 33 PID: 10759 at kernel/dma/debug.c:988 check_unmap+0xa6f/0x2360 ... [ 215.581176] Call Trace: [ 215.583632] <TASK> [ 215.585745] ? show_trace_log_lvl+0x1c4/0x2df [ 215.590114] ? show_trace_log_lvl+0x1c4/0x2df [ 215.594497] ? debug_dma_free_coherent+0x196/0x210 [ 215.599305] ? check_unmap+0xa6f/0x2360 [ 215.603147] ? __warn+0xca/0x1d0 [ 215.606391] ? check_unmap+0xa6f/0x2360 [ 215.610237] ? report_bug+0x1ef/0x370 [ 215.613921] ? handle_bug+0x3c/0x70 [ 215.617423] ? exc_invalid_op+0x14/0x50 [ 215.621269] ? asm_exc_invalid_op+0x16/0x20 [ 215.625480] ? check_unmap+0xa6f/0x2360 [ 215.629331] ? mark_lock.part.0+0xca/0xa40 [ 215.633445] debug_dma_free_coherent+0x196/0x210 [ 215.638079] ? __pfx_debug_dma_free_coherent+0x10/0x10 [ 215.643242] ? slab_free_freelist_hook+0x11d/0x1d0 [ 215.648060] dma_free_attrs+0x6d/0x130 [ 215.651834] aq_ring_free+0x193/0x290 [atlantic] [ 215.656487] aq_ptp_ring_free+0x67/0x110 [atlantic] ... [ 216.127540] ---[ end trace 6467e5964dd2640b ]--- [ 216.132160] DMA-API: Mapped at: [ 216.132162] debug_dma_alloc_coherent+0x66/0x2f0 [ 216.132165] dma_alloc_attrs+0xf5/0x1b0 [ 216.132168] aq_ring_hwts_rx_alloc+0x150/0x1f0 [atlantic] [ 216.132193] aq_ptp_ring_alloc+0x1bb/0x540 [atlantic] [ 216.132213] aq_nic_init+0x4a1/0x760 [atlantic] Fixes: 94ad945 ("net: aquantia: add PTP rings infrastructure") Signed-off-by: Ivan Vecera <ivecera@redhat.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Link: https://lore.kernel.org/r/20240201094752.883026-1-ivecera@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent ba5e127 commit 2e7d3b6

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

drivers/net/ethernet/aquantia/atlantic/aq_ptp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ int aq_ptp_ring_alloc(struct aq_nic_s *aq_nic)
993993
return 0;
994994

995995
err_exit_hwts_rx:
996-
aq_ring_free(&aq_ptp->hwts_rx);
996+
aq_ring_hwts_rx_free(&aq_ptp->hwts_rx);
997997
err_exit_ptp_rx:
998998
aq_ring_free(&aq_ptp->ptp_rx);
999999
err_exit_ptp_tx:
@@ -1011,7 +1011,7 @@ void aq_ptp_ring_free(struct aq_nic_s *aq_nic)
10111011

10121012
aq_ring_free(&aq_ptp->ptp_tx);
10131013
aq_ring_free(&aq_ptp->ptp_rx);
1014-
aq_ring_free(&aq_ptp->hwts_rx);
1014+
aq_ring_hwts_rx_free(&aq_ptp->hwts_rx);
10151015

10161016
aq_ptp_skb_ring_release(&aq_ptp->skb_ring);
10171017
}

drivers/net/ethernet/aquantia/atlantic/aq_ring.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,19 @@ void aq_ring_free(struct aq_ring_s *self)
919919
}
920920
}
921921

922+
void aq_ring_hwts_rx_free(struct aq_ring_s *self)
923+
{
924+
if (!self)
925+
return;
926+
927+
if (self->dx_ring) {
928+
dma_free_coherent(aq_nic_get_dev(self->aq_nic),
929+
self->size * self->dx_size + AQ_CFG_RXDS_DEF,
930+
self->dx_ring, self->dx_ring_pa);
931+
self->dx_ring = NULL;
932+
}
933+
}
934+
922935
unsigned int aq_ring_fill_stats_data(struct aq_ring_s *self, u64 *data)
923936
{
924937
unsigned int count;

drivers/net/ethernet/aquantia/atlantic/aq_ring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int aq_ring_rx_fill(struct aq_ring_s *self);
210210
int aq_ring_hwts_rx_alloc(struct aq_ring_s *self,
211211
struct aq_nic_s *aq_nic, unsigned int idx,
212212
unsigned int size, unsigned int dx_size);
213+
void aq_ring_hwts_rx_free(struct aq_ring_s *self);
213214
void aq_ring_hwts_rx_clean(struct aq_ring_s *self, struct aq_nic_s *aq_nic);
214215

215216
unsigned int aq_ring_fill_stats_data(struct aq_ring_s *self, u64 *data);

0 commit comments

Comments
 (0)