From: Damien Le Moal <dlemoal@kernel.org>
To: "Ionut Nechita (Wind River)" <ionut.nechita@windriver.com>,
m.szyprowski@samsung.com, kbusch@kernel.org, axboe@kernel.dk,
hch@lst.de, sagi@grimberg.me
Cc: robin.murphy@arm.com, martin.petersen@oracle.com,
damien.lemoal@opensource.wdc.com, john.g.garry@oracle.com,
ahuang12@lenovo.com, iommu@lists.linux.dev,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, ionut_n2001@yahoo.com,
sunlightlinux@gmail.com
Subject: Re: [PATCH v1 2/2] nvme-pci: handle dma_opt_mapping_size() returning 0
Date: Tue, 17 Mar 2026 06:21:14 +0900 [thread overview]
Message-ID: <bf63044a-5c5d-496c-be6d-43f310068bbe@kernel.org> (raw)
In-Reply-To: <20260316203956.64515-3-ionut.nechita@windriver.com>
On 3/17/26 05:39, Ionut Nechita (Wind River) wrote:
> From: Ionut Nechita <ionut.nechita@windriver.com>
>
> After the previous commit, dma_opt_mapping_size() returns 0 when no DMA
> backend provides an optimal mapping size hint (e.g. IOMMU in passthrough
> mode with no ops->opt_mapping_size callback).
>
> The NVMe PCI driver used min_t(u32, NVME_MAX_BYTES >> SECTOR_SHIFT,
> dma_opt_mapping_size() >> 9) to cap max_hw_sectors. With a 0 return
> value this would set max_hw_sectors to 0, which is invalid.
>
> Guard the min_t so that max_hw_sectors is only capped when
> dma_opt_mapping_size() provides a real hint. When it returns 0, fall
> back to the existing NVME_MAX_BYTES >> SECTOR_SHIFT default.
>
> Fixes: 3710e2b056cb ("nvme-pci: clamp max_hw_sectors based on DMA optimized limitation")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ionut Nechita <ionut.nechita@windriver.com>
> ---
> drivers/nvme/host/pci.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index b78ba239c8ea8..dc148fb6eff28 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -3640,6 +3640,7 @@ static struct nvme_dev *nvme_pci_alloc_dev(struct pci_dev *pdev,
> {
> unsigned long quirks = id->driver_data;
> int node = dev_to_node(&pdev->dev);
> + size_t dma_opt;
> struct nvme_dev *dev;
> struct quirk_entry *qentry;
> int ret = -ENOMEM;
> @@ -3691,12 +3692,16 @@ static struct nvme_dev *nvme_pci_alloc_dev(struct pci_dev *pdev,
> dma_set_max_seg_size(&pdev->dev, 0xffffffff);
>
> /*
> - * Limit the max command size to prevent iod->sg allocations going
> - * over a single page.
> + * Limit the max command size to prevent iod->sg allocations
> + * going over a single page. Only apply the DMA optimal mapping
> + * size limit when the DMA layer actually provides one (non-zero
> + * return from dma_opt_mapping_size()).
> */
> - dev->ctrl.max_hw_sectors = min_t(u32,
> - NVME_MAX_BYTES >> SECTOR_SHIFT,
> - dma_opt_mapping_size(&pdev->dev) >> 9);
Why not simply change this to min_not_zero() ? That would do the same. Are you
maybe getting a warning without the u32 cast ?
> + dev->ctrl.max_hw_sectors = NVME_MAX_BYTES >> SECTOR_SHIFT;
> + dma_opt = dma_opt_mapping_size(&pdev->dev);
> + if (dma_opt)
> + dev->ctrl.max_hw_sectors =
> + min_t(u32, dev->ctrl.max_hw_sectors, dma_opt >> 9);
> dev->ctrl.max_segments = NVME_MAX_SEGS;
> dev->ctrl.max_integrity_segments = 1;
> return dev;
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-03-16 21:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 20:39 [PATCH v1 0/2] dma: fix dma_opt_mapping_size() returning bogus value when no backend hint exists Ionut Nechita (Wind River)
2026-03-16 20:39 ` [PATCH v1 1/2] dma: return 0 from dma_opt_mapping_size() when no real " Ionut Nechita (Wind River)
2026-03-17 9:43 ` Robin Murphy
2026-03-17 14:19 ` Christoph Hellwig
2026-03-16 20:39 ` [PATCH v1 2/2] nvme-pci: handle dma_opt_mapping_size() returning 0 Ionut Nechita (Wind River)
2026-03-16 21:21 ` Damien Le Moal [this message]
2026-03-17 8:55 ` John Garry
2026-03-17 14:14 ` Christoph Hellwig
2026-03-17 9:11 ` [PATCH v1 0/2] dma: fix dma_opt_mapping_size() returning bogus value when no backend hint exists John Garry
2026-03-17 9:18 ` Damien Le Moal
2026-03-17 14:36 ` Christoph Hellwig
2026-03-17 15:18 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bf63044a-5c5d-496c-be6d-43f310068bbe@kernel.org \
--to=dlemoal@kernel.org \
--cc=ahuang12@lenovo.com \
--cc=axboe@kernel.dk \
--cc=damien.lemoal@opensource.wdc.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=ionut.nechita@windriver.com \
--cc=ionut_n2001@yahoo.com \
--cc=john.g.garry@oracle.com \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=m.szyprowski@samsung.com \
--cc=martin.petersen@oracle.com \
--cc=robin.murphy@arm.com \
--cc=sagi@grimberg.me \
--cc=stable@vger.kernel.org \
--cc=sunlightlinux@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox