From: Petr Tesarik Date: Wed, 25 Oct 2023 08:44:25 +0000 (+0200) Subject: swiotlb: do not try to allocate a TLB bigger than MAX_ORDER pages X-Git-Tag: v6.6.7~1660^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d5090484b021794271280ab64d20253883b7f6fd;p=platform%2Fkernel%2Flinux-starfive.git swiotlb: do not try to allocate a TLB bigger than MAX_ORDER pages When allocating a new pool at runtime, reduce the number of slabs so that the allocation order is at most MAX_ORDER. This avoids a kernel warning in __alloc_pages(). The warning is relatively benign, because the pool size is subsequently reduced when allocation fails, but it is silly to start with a request that is known to fail, especially since this is the default behavior if the kernel is built with CONFIG_SWIOTLB_DYNAMIC=y and booted without any swiotlb= parameter. Reported-by: Ben Greear Closes: https://lore.kernel.org/netdev/4f173dd2-324a-0240-ff8d-abf5c191be18@candelatech.com/ Fixes: 1aaa736815eb ("swiotlb: allocate a new memory pool when existing pools are full") Signed-off-by: Petr Tesarik Signed-off-by: Christoph Hellwig --- diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 0163767..dff067b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -678,6 +678,11 @@ static struct io_tlb_pool *swiotlb_alloc_pool(struct device *dev, size_t pool_size; size_t tlb_size; + if (nslabs > SLABS_PER_PAGE << MAX_ORDER) { + nslabs = SLABS_PER_PAGE << MAX_ORDER; + nareas = limit_nareas(nareas, nslabs); + } + pool_size = sizeof(*pool) + array_size(sizeof(*pool->areas), nareas); pool = kzalloc(pool_size, gfp); if (!pool)