[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251020165120.GY316284@nvidia.com>
Date: Mon, 20 Oct 2025 13:51:20 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: Leon Romanovsky <leon@...nel.org>
Cc: Alex Williamson <alex.williamson@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Christian König <christian.koenig@....com>,
dri-devel@...ts.freedesktop.org, iommu@...ts.linux.dev,
Jens Axboe <axboe@...nel.dk>, Joerg Roedel <joro@...tes.org>,
kvm@...r.kernel.org, linaro-mm-sig@...ts.linaro.org,
linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-media@...r.kernel.org, linux-mm@...ck.org,
linux-pci@...r.kernel.org, Logan Gunthorpe <logang@...tatee.com>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Robin Murphy <robin.murphy@....com>,
Sumit Semwal <sumit.semwal@...aro.org>,
Vivek Kasireddy <vivek.kasireddy@...el.com>,
Will Deacon <will@...nel.org>
Subject: Re: [PATCH v5 9/9] vfio/pci: Add dma-buf export support for MMIO
regions
On Mon, Oct 20, 2025 at 07:44:57PM +0300, Leon Romanovsky wrote:
> On Mon, Oct 20, 2025 at 01:15:16PM -0300, Jason Gunthorpe wrote:
> > On Fri, Oct 17, 2025 at 07:13:58PM +0300, Leon Romanovsky wrote:
> > > > static int dma_ranges_to_p2p_phys(struct vfio_pci_dma_buf *priv,
> > > > struct vfio_device_feature_dma_buf *dma_buf,
> > > > struct vfio_region_dma_range *dma_ranges,
> > > > struct p2pdma_provider *provider)
> > > > {
> > > > struct pci_dev *pdev = priv->vdev->pdev;
> > > > phys_addr_t len = pci_resource_len(pdev, dma_buf->region_index);
> > > > phys_addr_t pci_start;
> > > > phys_addr_t pci_last;
> > > > u32 i;
> > > >
> > > > if (!len)
> > > > return -EINVAL;
> > > > pci_start = pci_resource_start(pdev, dma_buf->region_index);
> > > > pci_last = pci_start + len - 1;
> > > > for (i = 0; i < dma_buf->nr_ranges; i++) {
> > > > phys_addr_t last;
> > > >
> > > > if (!dma_ranges[i].length)
> > > > return -EINVAL;
> > > >
> > > > if (check_add_overflow(pci_start, dma_ranges[i].offset,
> > > > &priv->phys_vec[i].paddr) ||
> > > > check_add_overflow(priv->phys_vec[i].paddr,
> > > > dma_ranges[i].length - 1, &last))
> > > > return -EOVERFLOW;
> > > > if (last > pci_last)
> > > > return -EINVAL;
> > > >
> > > > priv->phys_vec[i].len = dma_ranges[i].length;
> > > > priv->size += priv->phys_vec[i].len;
> > > > }
> > > > priv->nr_ranges = dma_buf->nr_ranges;
> > > > priv->provider = provider;
> > > > return 0;
> > > > }
> > >
> > > I have these checks in validate_dmabuf_input().
> > > Do you think that I need to add extra checks?
> >
> > I think they work better in this function, so I'd move them here.
>
> The main idea for validate_dmabuf_input() is to perform as much as
> possible checks before allocating kernel memory.
Yeah, but it's fine, it can just be turned into a function to safely
compute the total size. It makes more sense to try to validate once we
have the kernel memory and got the physical range from the driver to
copy into the phys.
Jason
Powered by blists - more mailing lists