linux-stable/kernel/dma
Will Deacon ef80ecc721 swiotlb: Fix alignment checks when both allocation and DMA masks are present
[ Upstream commit 51b30ecb73 ]

Nicolin reports that swiotlb buffer allocations fail for an NVME device
behind an IOMMU using 64KiB pages. This is because we end up with a
minimum allocation alignment of 64KiB (for the IOMMU to map the buffer
safely) but a minimum DMA alignment mask corresponding to a 4KiB NVME
page (i.e. preserving the 4KiB page offset from the original allocation).
If the original address is not 4KiB-aligned, the allocation will fail
because swiotlb_search_pool_area() erroneously compares these unmasked
bits with the 64KiB-aligned candidate allocation.

Tweak swiotlb_search_pool_area() so that the DMA alignment mask is
reduced based on the required alignment of the allocation.

Fixes: 82612d66d5 ("iommu: Allow the dma-iommu api to use bounce buffers")
Link: https://lore.kernel.org/r/cover.1707851466.git.nicolinc@nvidia.com
Reported-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Will Deacon <will@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-03 15:19:44 +02:00
..
Kconfig dma-mapping: remove CONFIG_DMA_REMAP 2022-03-03 14:00:57 +03:00
Makefile dma-mapping: remove CONFIG_DMA_REMAP 2022-03-03 14:00:57 +03:00
coherent.c dma-mapping: clear dev->dma_mem to NULL after freeing it 2024-01-25 15:27:28 -08:00
contiguous.c cma: factor out minimum alignment requirement 2022-03-22 15:57:05 -07:00
debug.c dma-debug: don't call __dma_entry_alloc_check_leak() under free_entries_lock 2023-10-06 14:56:50 +02:00
debug.h dma-debug: teach add_dma_entry() about DMA_ATTR_SKIP_CPU_SYNC 2021-10-18 12:46:45 +02:00
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 dma-mapping: return error code from dma_dummy_map_sg() 2021-08-09 17:13:06 +02:00
map_benchmark.c dma-mapping: benchmark: extract a common header file for map_benchmark definition 2022-03-10 07:41:14 +01:00
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 dma-mapping: handle vmalloc addresses in dma_common_{mmap,get_sgtable} 2021-07-16 11:30:26 +02:00
pool.c dma/pool: create dma atomic pool only if dma zone has managed pages 2022-01-15 16:30:29 +02:00
remap.c dma-remap: use kvmalloc_array/kvfree for larger dma memory remap 2023-08-23 17:52:21 +02:00
swiotlb.c swiotlb: Fix alignment checks when both allocation and DMA masks are present 2024-04-03 15:19:44 +02:00