wifi: ath12k: fix dest ring-buffer corruption
Subsystems (2)
cover wifi: ath12k: fix dest ring-buffer corruption
As a follow up to commit:
b67d2cf14ea ("wifi: ath12k: fix ring-buffer corruption")
add the remaining missing memory barriers to make sure that destination ring descriptors are read after the head pointers to avoid using stale data on weakly ordered architectures like aarch64.
Also switch back to plain accesses for the descriptor fields which is sufficient after the memory barrier.
Johan
Johan Hovold (2):
wifi: ath12k: fix dest ring-buffer corruption
wifi: ath12k: use plain access for descriptor length
drivers/net/wireless/ath/ath12k/dp_mon.c | 3 +++ drivers/net/wireless/ath/ath12k/dp_rx.c | 12 ++++++++++++ drivers/net/wireless/ath/ath12k/dp_tx.c | 3 +++ drivers/net/wireless/ath/ath12k/hal.c | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.49.0
PATCH 1/2 wifi: ath12k: fix dest ring-buffer corruption
Add the missing memory barriers to make sure that destination ring descriptors are read after the head pointers to avoid using stale data on weakly ordered architectures like aarch64.
Note that this may fix the empty descriptor issue recently worked around by commit 51ad34a47e9f ("wifi: ath12k: Add drop descriptor handling for monitor ring").
Tested-on: WCN7850 hw2.0 WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/dp_mon.c | 3 +++ drivers/net/wireless/ath/ath12k/dp_rx.c | 12 ++++++++++++ drivers/net/wireless/ath/ath12k/dp_tx.c | 3 +++ 3 files changed, 18 insertions(+)
drivers/net/wireless/ath/ath12k/dp_mon.c +3 -0
@@ -3258,6 +3258,9 @@ int ath12k_dp_mon_srng_process(struct ath12k *ar, int *budget,spin_lock_bh (&srng->lock);ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (likely (*budget)) { *budget -=1 ; mon_dst_desc =ath12k_hal_srng_dst_peek (ab, srng);
drivers/net/wireless/ath/ath12k/dp_rx.c +12 -0
@@ -2753,6 +2753,9 @@ int ath12k_dp_rx_process(struct ath12k_base *ab, int ring_id, try_again:ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while ((desc =ath12k_hal_srng_dst_get_next_entry (ab, srng))) {struct rx_mpdu_desc *mpdu_info;struct rx_msdu_desc *msdu_info;
@@ -3599,6 +3602,9 @@ int ath12k_dp_rx_process_err(struct ath12k_base *ab, struct napi_struct *napi,ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (budget && (reo_desc =ath12k_hal_srng_dst_get_next_entry (ab, srng))) { drop = false;
@@ -3941,6 +3947,9 @@ int ath12k_dp_rx_process_wbm_err(struct ath12k_base *ab,ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (budget) { rx_desc =ath12k_hal_srng_dst_get_next_entry (ab, srng);if (!rx_desc)
@@ -4122,6 +4131,9 @@ void ath12k_dp_rx_process_reo_status(struct ath12k_base *ab)ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while ((hdr =ath12k_hal_srng_dst_get_next_entry (ab, srng))) { tag =le64_get_bits (hdr->tl,HAL_SRNG_TLV_HDR_TAG );
drivers/net/wireless/ath/ath12k/dp_tx.c +3 -0
@@ -853,6 +853,9 @@ void ath12k_dp_tx_completion_handler(struct ath12k_base *ab, int ring_id)ath12k_hal_srng_access_begin (ab, status_ring); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (ATH12K_TX_COMPL_NEXT (tx_ring->tx_status_head) != tx_ring->tx_status_tail) { desc =ath12k_hal_srng_dst_get_next_entry (ab, status_ring);if (!desc)
Signature · 1 line
2.49.0
Quoted 82 lines · Johan Hovold
Add the missing memory barriers to make sure that destination ring descriptors are read after the head pointers to avoid using stale data on weakly ordered architectures like aarch64.
Note that this may fix the empty descriptor issue recently worked around by commit
51ad34a47e9f("wifi: ath12k: Add drop descriptor handling for monitor ring").Tested-on: WCN7850 hw2.0 WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
Fixes d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices")Cc [email protected] # 6.3Signed-off-by Johan Hovold <[email protected]>--- drivers/net/wireless/ath/ath12k/dp_mon.c | 3 +++ drivers/net/wireless/ath/ath12k/dp_rx.c | 12 ++++++++++++ drivers/net/wireless/ath/ath12k/dp_tx.c | 3 +++ 3 files changed, 18 insertions(+)drivers/net/wireless/ath/ath12k/dp_mon.c +3
-0@@ -3258,6 +3258,9 @@ int ath12k_dp_mon_srng_process(struct ath12k *ar, int *budget,spin_lock_bh (&srng->lock);ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (likely (*budget)) { *budget -=1 ; mon_dst_desc =ath12k_hal_srng_dst_peek (ab, srng);drivers/net/wireless/ath/ath12k/dp_rx.c +12
-0@@ -2753,6 +2753,9 @@ int ath12k_dp_rx_process(struct ath12k_base *ab, int ring_id, try_again:ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while ((desc =ath12k_hal_srng_dst_get_next_entry (ab, srng))) {struct rx_mpdu_desc *mpdu_info;struct rx_msdu_desc *msdu_info;@@ -3599,6 +3602,9 @@ int ath12k_dp_rx_process_err(struct ath12k_base *ab, struct napi_struct *napi,ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (budget && (reo_desc =ath12k_hal_srng_dst_get_next_entry (ab, srng))) { drop = false;@@ -3941,6 +3947,9 @@ int ath12k_dp_rx_process_wbm_err(struct ath12k_base *ab,ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (budget) { rx_desc =ath12k_hal_srng_dst_get_next_entry (ab, srng);if (!rx_desc)@@ -4122,6 +4131,9 @@ void ath12k_dp_rx_process_reo_status(struct ath12k_base *ab)ath12k_hal_srng_access_begin (ab, srng); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while ((hdr =ath12k_hal_srng_dst_get_next_entry (ab, srng))) { tag =le64_get_bits (hdr->tl,HAL_SRNG_TLV_HDR_TAG );drivers/net/wireless/ath/ath12k/dp_tx.c +0
-0
drivers/net/wireless/ath/ath12k/dp_tx.c void ath12k_dp_tx_completion_handler(struct ath12k_base *ab, int ring_id) · line 861
Quoted 9 lines
drivers/net/wireless/ath/ath12k/dp_tx.c +3
-0@@ -853,6 +853,9 @@ void ath12k_dp_tx_completion_handler(struct ath12k_base *ab, int ring_id)ath12k_hal_srng_access_begin (ab, status_ring); +/* Make sure descriptor is read after the head pointer. */ +dma_rmb (); +while (ATH12K_TX_COMPL_NEXT (tx_ring->tx_status_head) != tx_ring->tx_status_tail) { desc =ath12k_hal_srng_dst_get_next_entry (ab, status_ring);if (!desc)
PATCH 2/2 wifi: ath12k: use plain access for descriptor length
In reply to Johan HovoldThe read memory barrier added by commit 6b67d2cf14ea ("wifi: ath12k: fix ring-buffer corruption") is enough to guarantee ordering also for plain descriptor accesses if the length helper is ever inlined so drop the unnecessary READ_ONCE().
--- drivers/net/wireless/ath/ath12k/hal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/hal.c +1 -1
@@ -1962,7 +1962,7 @@ u32 ath12k_hal_ce_dst_status_get_length(struct hal_ce_srng_dst_status_desc *desc {u32 len; - len =le32_get_bits (READ_ONCE (desc->flags),HAL_CE_DST_STATUS_DESC_FLAGS_LEN ); + len =le32_get_bits (desc->flags,HAL_CE_DST_STATUS_DESC_FLAGS_LEN ); desc->flags &= ~cpu_to_le32 (HAL_CE_DST_STATUS_DESC_FLAGS_LEN );return len;
Signature · 1 line
2.49.0