Skip to content

Commit d509048

Browse files
Petr TesarikChristoph Hellwig
authored andcommitted
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 <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Fixes: 1aaa736 ("swiotlb: allocate a new memory pool when existing pools are full") Signed-off-by: Petr Tesarik <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 4f82870 commit d509048

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/dma/swiotlb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@ static struct io_tlb_pool *swiotlb_alloc_pool(struct device *dev,
678678
size_t pool_size;
679679
size_t tlb_size;
680680

681+
if (nslabs > SLABS_PER_PAGE << MAX_ORDER) {
682+
nslabs = SLABS_PER_PAGE << MAX_ORDER;
683+
nareas = limit_nareas(nareas, nslabs);
684+
}
685+
681686
pool_size = sizeof(*pool) + array_size(sizeof(*pool->areas), nareas);
682687
pool = kzalloc(pool_size, gfp);
683688
if (!pool)

0 commit comments

Comments
 (0)