wifi: ath11k: fix qmi memory allocation logic for CALDB region
Subsystems (2)
PATCH 1/1 wifi: ath11k: fix qmi memory allocation logic for CALDB region
Memory region assignment in ath11k_qmi_assign_target_mem_chunk() assumes that:
1. firmware will make a HOST_DDR_REGION_TYPE request, and
2. this request is processed before CALDB_MEM_REGION_TYPE
In this case CALDB_MEM_REGION_TYPE, can safely be assigned immediately after the host region.
However, if the HOST_DDR_REGION_TYPE request is not made, or the reserved-memory node is not present, then res.start and res.end are 0, and host_ddr_sz remains uninitialized. The physical address should fall back to ATH11K_QMI_CALDB_ADDRESS. That doesn't happen:
resource_size(&res) returns 1 for an empty resource, and thus the if clause never takes the fallback path. ab->qmi.target_mem[idx].paddr is assigned the uninitialized value of host_ddr_sz + 0 (res.start).
Use "if (res.end > res.start)" for the predicate, which correctly falls back to ATH11K_QMI_CALDB_ADDRESS.
--- drivers/net/wireless/ath/ath11k/qmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/qmi.c +2 -2
@@ -2054,7 +2054,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab)return ret; } -if (res.end - res.start +1 < ab->qmi.target_mem[i].size) { +if (resource_size (&res) < ab->qmi.target_mem[i].size) {ath11k_dbg (ab,ATH11K_DBG_QMI ,"fail to assign memory of sz\n" );return -EINVAL ;
@@ -2086,7 +2086,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) }if (ath11k_core_coldboot_cal_support (ab)) { -if (resource_size (&res)) { +if (res.end > res.start) { ab->qmi.target_mem[idx].paddr = res.start + host_ddr_sz; ab->qmi.target_mem[idx].iaddr =
Signature · 1 line
2.45.1
Quoted 9 lines · Alexandru Gagniuc
Memory region assignment in
ath11k_qmi_assign_target_mem_chunk()assumes that:
1. firmware will make aHOST_DDR_REGION_TYPErequest, and
2. this request is processed beforeCALDB_MEM_REGION_TYPEIn this case
CALDB_MEM_REGION_TYPE, can safely be assigned immediately after the host region.However, if the
HOST_DDR_REGION_TYPErequest is not made, or the
AFAICT, this is highly unlikely as HOST_DDR_REGION_TYPE will always be before CALDB_MEM_REGION_TYPE.
Quoted 33 lines
reserved-memory node is not present, then res.start and res.end are 0, and
host_ddr_szremains uninitialized. The physical address should fall back toATH11K_QMI_CALDB_ADDRESS. That doesn't happen:
resource_size(&res)returns 1 for an empty resource, and thus the if clause never takes the fallback path. ab->qmi.target_mem[idx].paddr is assigned the uninitialized value ofhost_ddr_sz+ 0 (res.start).Use "if (res.end > res.start)" for the predicate, which correctly falls back to
ATH11K_QMI_CALDB_ADDRESS.Fixes 900730dc4705 ("wifi: ath: Use of_reserved_mem_region_to_resource() for "memory-region"")Cc [email protected] # v6.18Signed-off-by Alexandru Gagniuc <[email protected]>--- drivers/net/wireless/ath/ath11k/qmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/ath/ath11k/qmi.c +1
-1@@ -2054,7 +2054,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab)return ret; } -if (res.end - res.start +1 < ab->qmi.target_mem[i].size) { +if (resource_size (&res) < ab->qmi.target_mem[i].size) {ath11k_dbg (ab,ATH11K_DBG_QMI ,"fail to assign memory of sz\n" );return -EINVAL ;
drivers/net/wireless/ath/ath11k/qmi.c static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) · line 2092
Quoted 8 lines
drivers/net/wireless/ath/ath11k/qmi.c +1
-1@@ -2086,7 +2086,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) }if (ath11k_core_coldboot_cal_support (ab)) { -if (resource_size (&res)) { +if (res.end > res.start) { ab->qmi.target_mem[idx].paddr = res.start + host_ddr_sz; ab->qmi.target_mem[idx].iaddr =
The rest looks good.
Quoted 57 lines · Vasanthakumar Thiagarajan
Quoted 9 lines · Alexandru Gagniuc
Memory region assignment in
ath11k_qmi_assign_target_mem_chunk()assumes that:
1. firmware will make aHOST_DDR_REGION_TYPErequest, and
2. this request is processed beforeCALDB_MEM_REGION_TYPEIn this case
CALDB_MEM_REGION_TYPE, can safely be assigned immediately after the host region.However, if the
HOST_DDR_REGION_TYPErequest is not made, or theAFAICT, this is highly unlikely as
HOST_DDR_REGION_TYPEwill always be beforeCALDB_MEM_REGION_TYPE. >Quoted 36 lines
reserved-memory node is not present, then res.start and res.end are 0, and
host_ddr_szremains uninitialized. The physical address should fall back toATH11K_QMI_CALDB_ADDRESS. That doesn't happen:
resource_size(&res)returns 1 for an empty resource, and thus the if clause never takes the fallback path. ab->qmi.target_mem[idx].paddr is assigned the uninitialized value ofhost_ddr_sz+ 0 (res.start).Use "if (res.end > res.start)" for the predicate, which correctly falls back to
ATH11K_QMI_CALDB_ADDRESS.Fixes 900730dc4705 ("wifi: ath: Use of_reserved_mem_region_to_resource() for "memory-region"")Cc [email protected] # v6.18Signed-off-by Alexandru Gagniuc <[email protected]>---
drivers/net/wireless/ath/ath11k/qmi.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/ath/ath11k/qmi.c +2
-2@@ -2054,7 +2054,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) return ret; } - if (res.end - res.start + 1 < ab->qmi.target_mem[i].size) { + if (resource_size(&res) < ab->qmi.target_mem[i].size) { ath11k_dbg(ab, ATH11K_DBG_QMI, "fail to assign memory of sz\n"); return -EINVAL;@@ -2086,7 +2086,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) } if (ath11k_core_coldboot_cal_support(ab)) { - if (resource_size(&res)) { + if (res.end > res.start) {Quoted 3 lines
ab->qmi.target_mem[idx].paddr = res.start +
host_ddr_sz; ab->qmi.target_mem[idx].iaddr =The rest looks good.
Quoted 2 lines
Reviewed-by Vasanthakumar Thiagarajan <[email protected]>
Well, since CALDB_MEM_REGION_TYPE will always come only after HOST_DDR_REGION_TYPE we'll not be running into this issue in real deployment with ath11k firmware binaries available in public.
Quoted 62 lines · Vasanthakumar Thiagarajan
Quoted 59 lines · Vasanthakumar Thiagarajan
Quoted 9 lines · Alexandru Gagniuc
Memory region assignment in
ath11k_qmi_assign_target_mem_chunk()assumes that:
1. firmware will make aHOST_DDR_REGION_TYPErequest, and
2. this request is processed beforeCALDB_MEM_REGION_TYPEIn this case
CALDB_MEM_REGION_TYPE, can safely be assigned immediately after the host region.However, if the
HOST_DDR_REGION_TYPErequest is not made, or theAFAICT, this is highly unlikely as
HOST_DDR_REGION_TYPEwill always be beforeCALDB_MEM_REGION_TYPE. >Quoted 38 lines
reserved-memory node is not present, then res.start and res.end are 0, and
host_ddr_szremains uninitialized. The physical address should fall back toATH11K_QMI_CALDB_ADDRESS. That doesn't happen:
resource_size(&res)returns 1 for an empty resource, and thus the if clause never takes the fallback path. ab->qmi.target_mem[idx].paddr is assigned the uninitialized value ofhost_ddr_sz+ 0 (res.start).Use "if (res.end > res.start)" for the predicate, which correctly falls back to
ATH11K_QMI_CALDB_ADDRESS.Fixes 900730dc4705 ("wifi: ath: Use of_reserved_mem_region_to_resource() for "memory-region"")Cc [email protected] # v6.18Signed-off-by Alexandru Gagniuc <[email protected]>---
drivers/net/wireless/ath/ath11k/qmi.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/ath/ath11k/qmi.c +2
-2@@ -2054,7 +2054,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) return ret; } - if (res.end - res.start + 1 < ab->qmi.target_mem[i].size) { + if (resource_size(&res) < ab->qmi.target_mem[i].size) { ath11k_dbg(ab, ATH11K_DBG_QMI, "fail to assign memory of sz\n"); return -EINVAL;@@ -2086,7 +2086,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) } if (ath11k_core_coldboot_cal_support(ab)) { - if (resource_size(&res)) { + if (res.end > res.start) {Quoted 3 lines
ab->qmi.target_mem[idx].paddr = res.start +
host_ddr_sz; ab->qmi.target_mem[idx].iaddr =The rest looks good.
Quoted 5 lines
Quoted 2 lines
Reviewed-by Vasanthakumar Thiagarajan <[email protected]>Well, since
CALDB_MEM_REGION_TYPEwill always come only afterHOST_DDR_REGION_TYPEwe'll not be running into this issue in real deployment with ath11k firmware binaries available in public.
Nevertheless, I agree this is a critical issue to be fixed. There is another patch[1] fixing the same issue a bit differently.
Vasanth
[1]: https://lore.kernel.org/linux-wireless/[email protected]/
Quoted 13 lines · Alexandru Gagniuc
Memory region assignment in
ath11k_qmi_assign_target_mem_chunk()assumes that:
1. firmware will make aHOST_DDR_REGION_TYPErequest, and
2. this request is processed beforeCALDB_MEM_REGION_TYPEIn this case
CALDB_MEM_REGION_TYPE, can safely be assigned immediately after the host region.However, if the
HOST_DDR_REGION_TYPErequest is not made, or the reserved-memory node is not present, then res.start and res.end are 0, andhost_ddr_szremains uninitialized. The physical address should fall back toATH11K_QMI_CALDB_ADDRESS. That doesn't happen:
Quoted 6 lines
resource_size(&res)returns 1 for an empty resource, and thus the if clause never takes the fallback path. ab->qmi.target_mem[idx].paddr is assigned the uninitialized value ofhost_ddr_sz+ 0 (res.start).Use "if (res.end > res.start)" for the predicate, which correctly falls back to
ATH11K_QMI_CALDB_ADDRESS.
In addition, does it make sense to do of_reserved_mem_region_to_resource() before the loop, which may give CALDB_MEM_REGION_TYPE a chance even HOST_DDR_REGION_TYPE request is not made?
Quoted 31 lines
Fixes 900730dc4705 ("wifi: ath: Use of_reserved_mem_region_to_resource() for "memory-region"")Cc [email protected] # v6.18Signed-off-by Alexandru Gagniuc <[email protected]>--- drivers/net/wireless/ath/ath11k/qmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/ath/ath11k/qmi.c +2
-2@@ -2054,7 +2054,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab)return ret; } -if (res.end - res.start +1 < ab->qmi.target_mem[i].size) { +if (resource_size (&res) < ab->qmi.target_mem[i].size) {ath11k_dbg (ab,ATH11K_DBG_QMI ,"fail to assign memory of sz\n" );return -EINVAL ;@@ -2086,7 +2086,7 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab) }if (ath11k_core_coldboot_cal_support (ab)) { -if (resource_size (&res)) { +if (res.end > res.start) { ab->qmi.target_mem[idx].paddr = res.start + host_ddr_sz; ab->qmi.target_mem[idx].iaddr =
Quoted 15 lines · CST Baochen Qiang
Quoted 14 lines · Alexandru Gagniuc
Memory region assignment in
ath11k_qmi_assign_target_mem_chunk()assumes that:
1. firmware will make aHOST_DDR_REGION_TYPErequest, and
2. this request is processed beforeCALDB_MEM_REGION_TYPEIn this case
CALDB_MEM_REGION_TYPE, can safely be assigned immediately after the host region.However, if the
HOST_DDR_REGION_TYPErequest is not made, or the reserved-memory node is not present, then res.start and res.end are 0, andhost_ddr_szremains uninitialized. The physical address should fall back toATH11K_QMI_CALDB_ADDRESS. That doesn't happen:
Quoted 6 lines
Quoted 6 lines
resource_size(&res)returns 1 for an empty resource, and thus the if clause never takes the fallback path. ab->qmi.target_mem[idx].paddr is assigned the uninitialized value ofhost_ddr_sz+ 0 (res.start).Use "if (res.end > res.start)" for the predicate, which correctly falls back to
ATH11K_QMI_CALDB_ADDRESS.
I am ready to submit the IPQ9574 support. This patch is a dependency. Should I include this change in the series that adds IPQ9574?
Quoted 3 lines
In addition, does it make sense to do
of_reserved_mem_region_to_resource()before the loop, which may giveCALDB_MEM_REGION_TYPEa chance evenHOST_DDR_REGION_TYPErequest is not made?
I'm sorry that I initially missed this question. I don't think we should move &res initialization outside the loop. We also need host_ddr_sz to be initialized by a HOST_DDR_REGION_TYPE (1) request. On IPQ9574, the firmware doesn't make that request, so host_ddr_sz remains uninitialized. Since &res and host_ddr_sz are used together, I think it's better to initialize them, together.
Without patch:
ath11k c000000.wifi: qmi firmware request memory request
ath11k c000000.wifi: qmi mem seg type 4 size 409600
ath11k c000000.wifi: qmi mem seg type 2 size 262144
ath11k c000000.wifi: qmi mem seg type 3 size 1048576
...
ath11k c000000.wifi: failed to assign qmi target memory: -5With patch:
ath11k c000000.wifi: qmi firmware request memory request
ath11k c000000.wifi: qmi mem seg type 4 size 409600
ath11k c000000.wifi: qmi mem seg type 2 size 262144
ath11k c000000.wifi: qmi mem seg type 3 size 1048576
ath11k c000000.wifi: qmi ignore invalid mem req type 3
ath11k c000000.wifi: qmi req mem_seg[0] 0x000000004ba00000 409600 4
ath11k c000000.wifi: qmi req mem_seg[1] 0x000000004b700000 262144 2Tested on : WLAN.HK.2.9.0.1-01890-QCAHKSWPL_SILICONZ-1
Alex
Quoted 20 lines · Alex G.
Quoted 19 lines · CST Baochen Qiang
Quoted 18 lines · Alexandru Gagniuc
Memory region assignment in
ath11k_qmi_assign_target_mem_chunk()assumes that:
1. firmware will make aHOST_DDR_REGION_TYPErequest, and
2. this request is processed beforeCALDB_MEM_REGION_TYPEIn this case
CALDB_MEM_REGION_TYPE, can safely be assigned immediately after the host region.However, if the
HOST_DDR_REGION_TYPErequest is not made, or the reserved-memory node is not present, then res.start and res.end are 0, andhost_ddr_szremains uninitialized. The physical address should fall back toATH11K_QMI_CALDB_ADDRESS. That doesn't happen:
resource_size(&res)returns 1 for an empty resource, and thus the if clause never takes the fallback path. ab->qmi.target_mem[idx].paddr is assigned the uninitialized value ofhost_ddr_sz+ 0 (res.start).
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Use "if (res.end > res.start)" for the predicate, which correctly falls back to
ATH11K_QMI_CALDB_ADDRESS.I am ready to submit the IPQ9574 support. This patch is a dependency. Should I include this change in the series that adds IPQ9574?
Better not, first reason is for track purpose. And the second, since the patch is fixing a broken commit, IMO being standalone makes it easy for stable team to do backport work.
Quoted 11 lines
Quoted 4 lines
In addition, does it make sense to do
of_reserved_mem_region_to_resource()before the loop, which may giveCALDB_MEM_REGION_TYPEa chance evenHOST_DDR_REGION_TYPErequest is not made?I'm sorry that I initially missed this question. I don't think we should move &res initialization outside the loop. We also need
host_ddr_szto be initialized by aHOST_DDR_REGION_TYPE(1) request. On IPQ9574, the firmware doesn't make that request, sohost_ddr_szremains uninitialized. Since &res andhost_ddr_szare used together, I think it's better to initialize them, together.
fine then
Quoted 31 lines
Without patch:
ath11k c000000.wifi: qmi firmware request memory request ath11k c000000.wifi: qmi mem seg type 4 size 409600 ath11k c000000.wifi: qmi mem seg type 2 size 262144 ath11k c000000.wifi: qmi mem seg type 3 size 1048576 ... ath11k c000000.wifi: failed to assign qmi target memory: -5With patch:
ath11k c000000.wifi: qmi firmware request memory request ath11k c000000.wifi: qmi mem seg type 4 size 409600 ath11k c000000.wifi: qmi mem seg type 2 size 262144 ath11k c000000.wifi: qmi mem seg type 3 size 1048576 ath11k c000000.wifi: qmi ignore invalid mem req type 3 ath11k c000000.wifi: qmi req mem_seg[0] 0x000000004ba00000 409600 4 ath11k c000000.wifi: qmi req mem_seg[1] 0x000000004b700000 262144 2Tested on : WLAN.HK.2.9.0.1-01890-QCAHKSWPL_SILICONZ-1
Alex