public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] swiotlb: check alloc_size before the allocation of a new memory pool
@ 2024-01-08 14:00 Peng Zhang
  2024-01-08 15:46 ` Petr Tesarik
  2024-01-08 17:06 ` Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: Peng Zhang @ 2024-01-08 14:00 UTC (permalink / raw)
  To: hch, m.szyprowski, robin.murphy, petr.tesarik1, iommu,
	linux-kernel
  Cc: wangkefeng.wang, sunnanyong, zhangpeng362

From: ZhangPeng <zhangpeng362@huawei.com>

The allocation request for swiotlb contiguous memory greater than
128*2KB cannot be fulfilled because it exceeds the maximum contiguous
memory limit. If the swiotlb memory we allocate is larger than 128*2KB,
swiotlb_find_slots() will still schedule the allocation of a new memory
pool, which will increase memory overhead.

Fix it by adding a check with alloc_size no more than 128*2KB before
scheduling the allocation of a new memory pool in swiotlb_find_slots().

Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
 kernel/dma/swiotlb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 33d942615be5..cc92cff02c60 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -1126,6 +1126,9 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
 	u64 phys_limit;
 	int index;
 
+	if (alloc_size > IO_TLB_SEGSIZE * IO_TLB_SIZE)
+		return -1;
+
 	rcu_read_lock();
 	list_for_each_entry_rcu(pool, &mem->pools, node) {
 		index = swiotlb_pool_find_slots(dev, pool, orig_addr,
-- 
2.25.1


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

end of thread, other threads:[~2024-01-09  2:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-08 14:00 [PATCH] swiotlb: check alloc_size before the allocation of a new memory pool Peng Zhang
2024-01-08 15:46 ` Petr Tesarik
2024-01-09  2:34   ` zhangpeng (AS)
2024-01-08 17:06 ` Christoph Hellwig
2024-01-09  2:34   ` zhangpeng (AS)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox