net: ipa: compute DMA pool size properly
PATCH 1/1 net: ipa: compute DMA pool size properly
In gsi_trans_pool_init_dma(), the total size of a pool of memory used for DMA transactions is calculated. However the calculation is done incorrectly.
For 4KB pages, this total size is currently always more than one page, and as a result, the calculation produces a positive (though incorrect) total size. The code still works in this case; we just end up with fewer DMA pool entries than we intended.
Bjorn Andersson tested booting a kernel with 16KB pages, and hit a null pointer derereference in sg_alloc_append_table_from_pages(), descending from gsi_trans_pool_init_dma(). The cause of this was that a 16KB total size was going to be allocated, and with 16KB pages the order of that allocation is 0. The total_size calculation yielded 0, which eventually led to the crash.
Correcting the total_size calculation fixes the problem.
--- drivers/net/ipa/gsi_trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ipa/gsi_trans.c +1 -1
@@ -156,7 +156,7 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,* gsi_trans_pool_exit_dma() can assume the total allocated * size is exactly (count * size). */ - total_size =get_order (total_size) <<PAGE_SHIFT ; + total_size =PAGE_SIZE <<get_order (total_size); virt =dma_alloc_coherent (dev, total_size, &addr,GFP_KERNEL );if (!virt)
Signature · 1 line
2.34.1
Quoted 31 lines · Alex Elder
In
gsi_trans_pool_init_dma(), the total size of a pool of memory used for DMA transactions is calculated. However the calculation is done incorrectly.For 4KB pages, this total size is currently always more than one page, and as a result, the calculation produces a positive (though incorrect) total size. The code still works in this case; we just end up with fewer DMA pool entries than we intended.
Bjorn Andersson tested booting a kernel with 16KB pages, and hit a null pointer derereference in
sg_alloc_append_table_from_pages(), descending fromgsi_trans_pool_init_dma(). The cause of this was that a 16KB total size was going to be allocated, and with 16KB pages the order of that allocation is 0. Thetotal_sizecalculation yielded 0, which eventually led to the crash.Correcting the
total_sizecalculation fixes the problem.Reported-by <[email protected]>Tested-by <[email protected]>Fixes 9dd441e4ed57 ("soc: qcom: ipa: GSI transactions")Signed-off-by Alex Elder <[email protected]>--- drivers/net/ipa/gsi_trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ipa/gsi_trans.c +0
-0
drivers/net/ipa/gsi_trans.c int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool, · line 162
Quoted 8 lines
drivers/net/ipa/gsi_trans.c +1
-1@@ -156,7 +156,7 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,* gsi_trans_pool_exit_dma() can assume the total allocated * size is exactly (count * size). */ - total_size =get_order (total_size) <<PAGE_SHIFT ; + total_size =PAGE_SIZE <<get_order (total_size); virt =dma_alloc_coherent (dev, total_size, &addr,GFP_KERNEL );if (!virt)
Thanks,
Quoted 16 lines · Alex Elder
In
gsi_trans_pool_init_dma(), the total size of a pool of memory used for DMA transactions is calculated. However the calculation is done incorrectly.For 4KB pages, this total size is currently always more than one page, and as a result, the calculation produces a positive (though incorrect) total size. The code still works in this case; we just end up with fewer DMA pool entries than we intended.
Bjorn Andersson tested booting a kernel with 16KB pages, and hit a null pointer derereference in
sg_alloc_append_table_from_pages(), descending fromgsi_trans_pool_init_dma(). The cause of this was that a 16KB total size was going to be allocated, and with 16KB pages the order of that allocation is 0. Thetotal_sizecalculation yielded 0, which eventually led to the crash.
Quoted 4 lines
Correcting the
total_sizecalculation fixes the problem.Reported-by <[email protected]>Tested-by <[email protected]>
It would be nice to add "Bjorn Andersson" to these two.
Regards,
Bjorn
Quoted 22 lines
Fixes 9dd441e4ed57 ("soc: qcom: ipa: GSI transactions")Signed-off-by Alex Elder <[email protected]>--- drivers/net/ipa/gsi_trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ipa/gsi_trans.c +1
-1@@ -156,7 +156,7 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,* gsi_trans_pool_exit_dma() can assume the total allocated * size is exactly (count * size). */ - total_size =get_order (total_size) <<PAGE_SHIFT ; + total_size =PAGE_SIZE <<get_order (total_size); virt =dma_alloc_coherent (dev, total_size, &addr,GFP_KERNEL );if (!virt)Signature · 1 line
2.34.1
Quoted 21 lines · Bjorn Andersson
Quoted 16 lines · Alex Elder
In
gsi_trans_pool_init_dma(), the total size of a pool of memory used for DMA transactions is calculated. However the calculation is done incorrectly.For 4KB pages, this total size is currently always more than one page, and as a result, the calculation produces a positive (though incorrect) total size. The code still works in this case; we just end up with fewer DMA pool entries than we intended.
Bjorn Andersson tested booting a kernel with 16KB pages, and hit a null pointer derereference in
sg_alloc_append_table_from_pages(), descending fromgsi_trans_pool_init_dma(). The cause of this was that a 16KB total size was going to be allocated, and with 16KB pages the order of that allocation is 0. Thetotal_sizecalculation yielded 0, which eventually led to the crash.
Quoted 7 lines
Quoted 4 lines
Correcting the
total_sizecalculation fixes the problem.Reported-by <[email protected]>Tested-by <[email protected]>It would be nice to add "Bjorn Andersson" to these two.
Oh yeah sorry about that. I’ll add it. -Alex
Quoted 25 lines
Regards,
BjornQuoted 22 lines
Fixes 9dd441e4ed57 ("soc: qcom: ipa: GSI transactions")Signed-off-by Alex Elder <[email protected]>---
drivers/net/ipa/gsi_trans.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ipa/gsi_trans.c +1
-1@@ -156,7 +156,7 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,* gsi_trans_pool_exit_dma() can assume the total allocated * size is exactly (count * size). */ - total_size =get_order (total_size) <<PAGE_SHIFT ; + total_size =PAGE_SIZE <<get_order (total_size); virt =dma_alloc_coherent (dev, total_size, &addr,GFP_KERNEL );if (!virt)Signature · 1 line
2.34.1