From: Matt Evans <mattev@meta.com>
To: "Tian, Kevin" <kevin.tian@intel.com>, Alex Williamson <alex@shazbot.org>
Cc: Ankit Agrawal <ankita@nvidia.com>, Jason Gunthorpe <jgg@ziepe.ca>,
Yishai Hadas <yishaih@nvidia.com>,
Shameer Kolothum <skolothumtho@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
"Kasireddy, Vivek" <vivek.kasireddy@intel.com>,
Kees Cook <kees@kernel.org>, Zhi Wang <zhiw@nvidia.com>,
Peter Xu <peterx@redhat.com>,
Alexey Kardashevskiy <aik@ozlabs.ru>,
Eric Auger <eric.auger@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"virtualization@lists.linux.dev" <virtualization@lists.linux.dev>
Subject: Re: [PATCH 1/2] vfio/pci: Set up VFIO barmap before creating a DMABUF
Date: Tue, 21 Apr 2026 18:46:38 +0100 [thread overview]
Message-ID: <e44ba83a-bbfb-4c80-aaee-ab16026c666b@meta.com> (raw)
In-Reply-To: <3fd01aa0-955d-44e3-aa4a-1918f9c42bb0@meta.com>
Hi,
On 17/04/2026 20:11, Matt Evans wrote:
> Hi Kevin, Alex,
>
> On 17/04/2026 06:16, Tian, Kevin wrote:
>>
>>> From: Alex Williamson <alex@shazbot.org>
>>> Sent: Friday, April 17, 2026 6:44 AM
>>>
>>> On Wed, 15 Apr 2026 11:14:22 -0700
>>> Matt Evans <mattev@meta.com> wrote:
>>>
>>>> A DMABUF exports access to BAR resources which need to be requested
>>>> before the DMABUF is handed out. Usually the resources are requested
>>>> when setting up the barmap when the VFIO device fd is mmap()ed, but
>>>> there's no guarantee that's done before a DMABUF is created.
>>>>
>>>> Set up the barmap (and so request resources) in the DMABUF-creation
>>>> path.
>>>>
>>>> Fixes: 5d74781ebc86c ("vfio/pci: Add dma-buf export support for MMIO
>>> regions")
>>>> Signed-off-by: Matt Evans <mattev@meta.com>
>>>> ---
>>>> drivers/vfio/pci/vfio_pci_dmabuf.c | 9 +++++++++
>>>> 1 file changed, 9 insertions(+)
>>>>
>>>> diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c
>>> b/drivers/vfio/pci/vfio_pci_dmabuf.c
>>>> index 4ccaf3531e02..fefe7cf4256b 100644
>>>> --- a/drivers/vfio/pci/vfio_pci_dmabuf.c
>>>> +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
>>>> @@ -272,6 +272,15 @@ int vfio_pci_core_feature_dma_buf(struct
>>> vfio_pci_core_device *vdev, u32 flags,
>>>> goto err_free_priv;
>>>> }
>>>>
>>>> + /*
>>>> + * See comment in vfio_pci_core_mmap(); ensure PCI regions
>>>> + * were requested before returning DMABUFs that reference
>>>> + * them. Barmap setup does this:
>>>> + */
>>>> + ret = vfio_pci_core_setup_barmap(vdev, get_dma_buf.region_index);
>>>> + if (ret)
>>>> + goto err_free_phys;
>>>> +
>>>> priv->vdev = vdev;
>>>> priv->nr_ranges = get_dma_buf.nr_ranges;
>>>> priv->size = length;
>>>
>>> Wouldn't this get a lot easier if we just setup all the barmaps in
>>> vfio_pci_core_enable(), conditional on pci_resource_len() just like we
>>> use to filter in REGION_INFO?
>>>
>>> I don't recall if there's some reason we've avoid this so far, maybe
>>> others can shout it out if they do.
>>
>> I don't remember too. probably just because it's not a wide requirement
>> then was made in this on-demand approach...
>>
>>>
>>> We already tear them all down in vfio_pci_core_disable(). It would be
>>> a small patch to add that, which we would mark as Fixes:, then a small
>>> follow-up on top of that that removes any then redundant or unnecessary
>>> callers (all of them). Thoughts? Thanks,
>>>
>>
>> Agree. then the next patch fixing the racing conditions is also not
>> required.
>
> Oh, if we can do it earlier it's all much cleaner, agreed. I'd naively
> thought there was a reason it was done lazily. One benefit is truly
> huge TB-scale BARs don't get ioremap()ed until actually used by
> userspace. I can't think of a good usage example that relies on open
> performance.
>
> If you say fine, then great: Ignore these, and I'll post a new pair of
> patches doing that (...with a cover letter this time).
New series posted:
https://lore.kernel.org/kvm/20260421174143.3883579-1-mattev@meta.com/
(Titles/semantics very different, so didn't send as a v2 of this.)
Matt
prev parent reply other threads:[~2026-04-21 17:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 18:14 [PATCH 1/2] vfio/pci: Set up VFIO barmap before creating a DMABUF Matt Evans
2026-04-15 18:14 ` [PATCH 2/2] vfio/pci: Serialise vfio_pci_core_setup_barmap() Matt Evans
2026-04-16 22:44 ` [PATCH 1/2] vfio/pci: Set up VFIO barmap before creating a DMABUF Alex Williamson
2026-04-17 5:16 ` Tian, Kevin
2026-04-17 19:11 ` Matt Evans
2026-04-21 17:46 ` Matt Evans [this message]
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=e44ba83a-bbfb-4c80-aaee-ab16026c666b@meta.com \
--to=mattev@meta.com \
--cc=aik@ozlabs.ru \
--cc=alex@shazbot.org \
--cc=ankita@nvidia.com \
--cc=apopple@nvidia.com \
--cc=eric.auger@redhat.com \
--cc=jgg@ziepe.ca \
--cc=kees@kernel.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=skolothumtho@nvidia.com \
--cc=virtualization@lists.linux.dev \
--cc=vivek.kasireddy@intel.com \
--cc=yishaih@nvidia.com \
--cc=zhiw@nvidia.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