linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wifi: ath12k: check M3 buffer size as well whey trying to reuse it
@ 2024-04-25  2:17 Baochen Qiang
  2024-04-25 17:05 ` Jeff Johnson
  2024-04-30 13:34 ` Kalle Valo
  0 siblings, 2 replies; 3+ messages in thread
From: Baochen Qiang @ 2024-04-25  2:17 UTC (permalink / raw)
  To: ath12k; +Cc: linux-wireless, quic_bqiang

Currently in recovery/resume cases, we do not free M3 buffer but
instead will reuse it. This is done by checking m3_mem->vaddr: if it
is not NULL we believe M3 buffer is ready and go ahead to reuse it.

Note that m3_mem->size is not checked. This is safe for now because
currently M3 reuse logic only gets executed in recovery/resume cases
and the size keeps unchanged in either of them.

However ideally the size should be checked as well, to make the code
safer. So add the check there. Now if that check fails, free old M3
buffer and reallocate a new one.

Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.30

Fixes: 303c017821d8 ("wifi: ath12k: fix kernel crash during resume")
Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
---
 drivers/net/wireless/ath/ath12k/qmi.c | 36 ++++++++++++++++-----------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c
index ebb20fc8e3ba..5484112859a6 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.c
+++ b/drivers/net/wireless/ath/ath12k/qmi.c
@@ -2717,6 +2717,19 @@ static int ath12k_qmi_load_bdf_qmi(struct ath12k_base *ab,
 	return ret;
 }
 
+static void ath12k_qmi_m3_free(struct ath12k_base *ab)
+{
+	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
+
+	if (!m3_mem->vaddr)
+		return;
+
+	dma_free_coherent(ab->dev, m3_mem->size,
+			  m3_mem->vaddr, m3_mem->paddr);
+	m3_mem->vaddr = NULL;
+	m3_mem->size = 0;
+}
+
 static int ath12k_qmi_m3_load(struct ath12k_base *ab)
 {
 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
@@ -2747,8 +2760,14 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
 		m3_len = fw->size;
 	}
 
-	if (m3_mem->vaddr)
-		goto skip_m3_alloc;
+	/* In recovery/resume cases, M3 buffer is not freed, try to reuse that */
+	if (m3_mem->vaddr) {
+		if (m3_mem->size >= m3_len)
+			goto skip_m3_alloc;
+
+		/* Old buffer is too small, free and reallocate */
+		ath12k_qmi_m3_free(ab);
+	}
 
 	m3_mem->vaddr = dma_alloc_coherent(ab->dev,
 					   m3_len, &m3_mem->paddr,
@@ -2772,19 +2791,6 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
 	return ret;
 }
 
-static void ath12k_qmi_m3_free(struct ath12k_base *ab)
-{
-	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
-
-	if (!m3_mem->vaddr)
-		return;
-
-	dma_free_coherent(ab->dev, m3_mem->size,
-			  m3_mem->vaddr, m3_mem->paddr);
-	m3_mem->vaddr = NULL;
-	m3_mem->size = 0;
-}
-
 static int ath12k_qmi_wlanfw_m3_info_send(struct ath12k_base *ab)
 {
 	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;

base-commit: 326f8f68f28b0b831233acfabffb486a5b0f4717
-- 
2.25.1


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

* Re: [PATCH] wifi: ath12k: check M3 buffer size as well whey trying to reuse it
  2024-04-25  2:17 [PATCH] wifi: ath12k: check M3 buffer size as well whey trying to reuse it Baochen Qiang
@ 2024-04-25 17:05 ` Jeff Johnson
  2024-04-30 13:34 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Johnson @ 2024-04-25 17:05 UTC (permalink / raw)
  To: Baochen Qiang, ath12k; +Cc: linux-wireless

On 4/24/2024 7:17 PM, Baochen Qiang wrote:
> Currently in recovery/resume cases, we do not free M3 buffer but
> instead will reuse it. This is done by checking m3_mem->vaddr: if it
> is not NULL we believe M3 buffer is ready and go ahead to reuse it.
> 
> Note that m3_mem->size is not checked. This is safe for now because
> currently M3 reuse logic only gets executed in recovery/resume cases
> and the size keeps unchanged in either of them.
> 
> However ideally the size should be checked as well, to make the code
> safer. So add the check there. Now if that check fails, free old M3
> buffer and reallocate a new one.
> 
> Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.30
> 
> Fixes: 303c017821d8 ("wifi: ath12k: fix kernel crash during resume")
> Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>


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

* Re: [PATCH] wifi: ath12k: check M3 buffer size as well whey trying to reuse it
  2024-04-25  2:17 [PATCH] wifi: ath12k: check M3 buffer size as well whey trying to reuse it Baochen Qiang
  2024-04-25 17:05 ` Jeff Johnson
@ 2024-04-30 13:34 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2024-04-30 13:34 UTC (permalink / raw)
  To: Baochen Qiang; +Cc: ath12k, linux-wireless, quic_bqiang

Baochen Qiang <quic_bqiang@quicinc.com> wrote:

> Currently in recovery/resume cases, we do not free M3 buffer but
> instead will reuse it. This is done by checking m3_mem->vaddr: if it
> is not NULL we believe M3 buffer is ready and go ahead to reuse it.
> 
> Note that m3_mem->size is not checked. This is safe for now because
> currently M3 reuse logic only gets executed in recovery/resume cases
> and the size keeps unchanged in either of them.
> 
> However ideally the size should be checked as well, to make the code
> safer. So add the check there. Now if that check fails, free old M3
> buffer and reallocate a new one.
> 
> Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.30
> 
> Fixes: 303c017821d8 ("wifi: ath12k: fix kernel crash during resume")
> Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
> Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

Patch applied to ath-next branch of ath.git, thanks.

05090ae82f44 wifi: ath12k: check M3 buffer size as well whey trying to reuse it

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20240425021740.29221-1-quic_bqiang@quicinc.com/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


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

end of thread, other threads:[~2024-04-30 13:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25  2:17 [PATCH] wifi: ath12k: check M3 buffer size as well whey trying to reuse it Baochen Qiang
2024-04-25 17:05 ` Jeff Johnson
2024-04-30 13:34 ` Kalle Valo

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).