summaryrefslogtreecommitdiff
path: root/kernel/dma
diff options
context:
space:
mode:
authorZhangPeng <zhangpeng362@huawei.com>2024-01-09 05:45:47 +0300
committerChristoph Hellwig <hch@lst.de>2024-01-09 18:58:36 +0300
commit3dc2f209208dddc73ffd1d817081711343de3242 (patch)
treebdee8b0c9e9a663690290fd2a6bcbaa228898633 /kernel/dma
parentb07bc2347672cc8c7293c64499f1488278c5ca3d (diff)
downloadlinux-3dc2f209208dddc73ffd1d817081711343de3242.tar.xz
swiotlb: check alloc_size before the allocation of a new memory pool
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> Reviewed-by: Petr Tesarik <petr.tesarik1@huawei-partners.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'kernel/dma')
-rw-r--r--kernel/dma/swiotlb.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index e20b856255ef..96f832d828fd 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -1136,6 +1136,9 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr,
int cpu, i;
int index;
+ if (alloc_size > IO_TLB_SEGSIZE * IO_TLB_SIZE)
+ return -1;
+
cpu = raw_smp_processor_id();
for (i = 0; i < default_nareas; ++i) {
index = swiotlb_search_area(dev, cpu, i, orig_addr, alloc_size,