mirror-linux/kernel/dma
Petr Tesarik fd5b64c1cf swiotlb: reduce the number of areas to match actual memory pool size
[ Upstream commit 8ac0406335 ]

Although the desired size of the SWIOTLB memory pool is increased in
swiotlb_adjust_nareas() to match the number of areas, the actual allocation
may be smaller, which may require reducing the number of areas.

For example, Xen uses swiotlb_init_late(), which in turn uses the page
allocator. On x86, page size is 4 KiB and MAX_ORDER is 10 (1024 pages),
resulting in a maximum memory pool size of 4 MiB. This corresponds to 2048
slots of 2 KiB each. The minimum area size is 128 (IO_TLB_SEGSIZE),
allowing at most 2048 / 128 = 16 areas.

If num_possible_cpus() is greater than the maximum number of areas, areas
are smaller than IO_TLB_SEGSIZE and contiguous groups of free slots will
span multiple areas. When allocating and freeing slots, only one area will
be properly locked, causing race conditions on the unlocked slots and
ultimately data corruption, kernel hangs and crashes.

Fixes: 20347fca71 ("swiotlb: split up the global swiotlb lock")
Signed-off-by: Petr Tesarik <petr.tesarik.ext@huawei.com>
Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-07-23 13:49:20 +02:00
..
Kconfig
Makefile
coherent.c dma-mapping: Add dma_release_coherent_memory to DMA API 2022-06-24 09:30:54 -06:00
contiguous.c
debug.c dma-debug: improve search for partial syncs 2022-09-07 10:38:16 +02:00
debug.h
direct.c dma-mapping updates 2022-08-06 10:56:45 -07:00
direct.h dma-direct: support PCI P2PDMA pages in dma-direct map_sg 2022-07-26 07:27:47 -04:00
dummy.c
map_benchmark.c
mapping.c - Yu Zhao's Multi-Gen LRU patches are here. They've been under test in 2022-10-10 17:53:04 -07:00
ops_helpers.c
pool.c
remap.c
swiotlb.c swiotlb: reduce the number of areas to match actual memory pool size 2023-07-23 13:49:20 +02:00