Skip to content

Commit

Permalink
nvme-pci: don't use dma_alloc_noncontiguous with 0 merge boundary
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Christoph Hellwig authored and keithbusch committed Dec 4, 2024
1 parent 41d826c commit ad0cf42
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/nvme/host/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,7 @@ static int nvme_alloc_host_mem_multi(struct nvme_dev *dev, u64 preferred,

static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
{
unsigned long dma_merge_boundary = dma_get_merge_boundary(dev->dev);
u64 min_chunk = min_t(u64, preferred, PAGE_SIZE * MAX_ORDER_NR_PAGES);
u64 hmminds = max_t(u32, dev->ctrl.hmminds * 4096, PAGE_SIZE * 2);
u64 chunk_size;
Expand All @@ -2180,7 +2181,7 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
* If there is an IOMMU that can merge pages, try a virtually
* non-contiguous allocation for a single segment first.
*/
if (!(PAGE_SIZE & dma_get_merge_boundary(dev->dev))) {
if (dma_merge_boundary && (PAGE_SIZE & dma_merge_boundary) == 0) {
if (!nvme_alloc_host_mem_single(dev, preferred))
return 0;
}
Expand Down

0 comments on commit ad0cf42

Please sign in to comment.