Skip to content

Commit ad0cf42

Browse files
Christoph Hellwigkeithbusch
Christoph Hellwig
authored andcommitted
nvme-pci: don't use dma_alloc_noncontiguous with 0 merge boundary
Only call into nvme_alloc_host_mem_single which uses dma_alloc_noncontiguous when there is non-null dma merge boundary. Without this we'll call into dma_alloc_noncontiguous for device using dma-direct, which can work fine as long as the preferred size is below the MAX_ORDER of the page allocator, but blows up with a warning if it is too large. Fixes: 63a5c7a ("nvme-pci: use dma_alloc_noncontigous if possible") Reported-by: Leon Romanovsky <[email protected]> Reported-by: Chaitanya Kumar Borah <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Tested-by: Chaitanya Kumar Borah <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 41d826c commit ad0cf42

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/nvme/host/pci.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,7 @@ static int nvme_alloc_host_mem_multi(struct nvme_dev *dev, u64 preferred,
21722172

21732173
static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
21742174
{
2175+
unsigned long dma_merge_boundary = dma_get_merge_boundary(dev->dev);
21752176
u64 min_chunk = min_t(u64, preferred, PAGE_SIZE * MAX_ORDER_NR_PAGES);
21762177
u64 hmminds = max_t(u32, dev->ctrl.hmminds * 4096, PAGE_SIZE * 2);
21772178
u64 chunk_size;
@@ -2180,7 +2181,7 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
21802181
* If there is an IOMMU that can merge pages, try a virtually
21812182
* non-contiguous allocation for a single segment first.
21822183
*/
2183-
if (!(PAGE_SIZE & dma_get_merge_boundary(dev->dev))) {
2184+
if (dma_merge_boundary && (PAGE_SIZE & dma_merge_boundary) == 0) {
21842185
if (!nvme_alloc_host_mem_single(dev, preferred))
21852186
return 0;
21862187
}

0 commit comments

Comments
 (0)