linux-stable/kernel/dma
Will Deacon 18c288992d 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:11:43 +02:00
..
Kconfig dma-direct: add a CONFIG_ARCH_HAS_DMA_ALLOC symbol 2023-10-22 16:38:54 +02:00
Makefile
coherent.c dma-mapping: clear dev->dma_mem to NULL after freeing it 2024-01-25 15:44:53 -08:00
contiguous.c Revert "dma-contiguous: check for memory region overlap" 2023-09-08 05:58:32 -03:00
debug.c dma-debug: Fix a typo in a debugging eye-catcher 2023-10-23 07:52:54 +02:00
debug.h
direct.c dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM 2023-11-06 08:38:16 +01:00
direct.h dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM 2023-11-06 08:38:16 +01:00
dummy.c
map_benchmark.c dma-mapping: benchmark: remove MODULE_LICENSE in non-modules 2023-04-13 13:13:51 -07:00
mapping.c dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM 2023-11-06 08:38:16 +01:00
ops_helpers.c
pool.c dma-pool: remove a __maybe_unused label in atomic_pool_expand 2023-08-31 14:12:37 +02:00
remap.c dma-remap: use kvmalloc_array/kvfree for larger dma memory remap 2023-06-07 15:06:28 +02:00
swiotlb.c swiotlb: Fix alignment checks when both allocation and DMA masks are present 2024-04-03 15:11:43 +02:00