public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Evans <mattev@meta.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Alex Williamson <alex@shazbot.org>,
	Kevin Tian <kevin.tian@intel.com>, Jason Gunthorpe <jgg@ziepe.ca>,
	Ankit Agrawal <ankita@nvidia.com>,
	Alistair Popple <apopple@nvidia.com>, Kees Cook <kees@kernel.org>,
	Shameer Kolothum <skolothumtho@nvidia.com>,
	Yishai Hadas <yishaih@nvidia.com>,
	Alexey Kardashevskiy <aik@ozlabs.ru>,
	Eric Auger <eric.auger@redhat.com>, Peter Xu <peterx@redhat.com>,
	Vivek Kasireddy <vivek.kasireddy@intel.com>,
	Zhi Wang <zhiw@nvidia.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	virtualization@lists.linux.dev
Subject: Re: [PATCH v2 2/3] vfio/pci: Replace vfio_pci_core_setup_barmap() with checks for resource/map
Date: Wed, 29 Apr 2026 11:17:43 +0100	[thread overview]
Message-ID: <393f65a8-75c3-401c-b983-5814e1bfcba2@meta.com> (raw)
In-Reply-To: <20260426110517.GB440345@unreal>

Hi Leon,

On 26/04/2026 12:05, Leon Romanovsky wrote:
> > 
> On Thu, Apr 23, 2026 at 11:25:08AM -0700, Matt Evans wrote:
>> Since "vfio/pci: Set up barmap in vfio_pci_core_enable()", the
>> resource request and iomap for the BARs was performed early, and
>> vfio_pci_core_setup_barmap() now just checks those actions succeeded.
>>
>> There were two types of callers:
>>   - Those that need the iomap, because they'll access the BAR
>>   - Those that need the resource, because they'll map/export it
>>
>> This replaces vfio_pci_core_setup_barmap() with two helpers,
>> vfio_pci_core_check_barmap_valid() and vfio_pci_core_check_bar_rsrc(),
>> to make it clear which behaviour is required in each caller.
>>
>> Signed-off-by: Matt Evans <mattev@meta.com>
>> ---
>>   drivers/vfio/pci/nvgrace-gpu/main.c |  8 +++-----
>>   drivers/vfio/pci/vfio_pci_core.c    |  5 ++---
>>   drivers/vfio/pci/vfio_pci_rdwr.c    | 22 ++--------------------
>>   drivers/vfio/pci/virtio/legacy_io.c |  4 ++--
>>   include/linux/vfio_pci_core.h       | 23 ++++++++++++++++++++++-
>>   5 files changed, 31 insertions(+), 31 deletions(-)
> 
> <...>
> 
>> +/* Returns 0 if vdev->barmap[bar] can be accessed, otherwise errno */
>> +static inline int
>> +vfio_pci_core_check_barmap_valid(struct vfio_pci_core_device *vdev, int bar)
>> +{
>> +	if (bar < 0 || bar >= PCI_STD_NUM_BARS)
>> +		return -EINVAL;
>> +	if (vdev->barmap[bar] == 0)
> 
> I understand this line was copied from an earlier implementation, but
> barmap[bar] is a pointer, and it is set to NULL when it is released.
> 
>   if (!dev->barmap[bar])
>     return -ENOMEM;

Absolutely.  Fixed in upcoming v3, thank you,


Matt

> 
> Thanks
> 
>> +		return -ENOMEM;
>> +	return 0;
>> +}
>> +
>> +/* Returns 0 if BAR has a valid resource reserved for use, otherwise errno */
>> +static inline int vfio_pci_core_check_bar_rsrc(struct vfio_pci_core_device *vdev,
>> +					       int bar)
>> +{
>> +	if (bar < 0 || bar >= PCI_STD_NUM_BARS)
>> +		return -EINVAL;
>> +	if (!vdev->have_bar_resource[bar])
>> +		return -EBUSY;
>> +	return 0;
>> +}
>> +
>>   static inline bool is_aligned_for_order(struct vm_area_struct *vma,
>>   					unsigned long addr,
>>   					unsigned long pfn,
>> -- 
>> 2.47.3
>>


  reply	other threads:[~2026-04-29 10:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 18:25 [PATCH v2 0/3] vfio/pci: Request resources and map BARs at enable time Matt Evans
2026-04-23 18:25 ` [PATCH v2 1/3] vfio/pci: Set up bar resources and maps in vfio_pci_core_enable() Matt Evans
2026-04-23 21:30   ` Alex Williamson
2026-04-24 15:15     ` Matt Evans
2026-04-24 17:20       ` Alex Williamson
2026-04-29 10:15         ` Matt Evans
2026-04-23 18:25 ` [PATCH v2 2/3] vfio/pci: Replace vfio_pci_core_setup_barmap() with checks for resource/map Matt Evans
2026-04-23 21:30   ` Alex Williamson
2026-04-26 11:05   ` Leon Romanovsky
2026-04-29 10:17     ` Matt Evans [this message]
2026-04-23 18:25 ` [PATCH v2 3/3] vfio/pci: Check BAR resources before exporting a DMABUF Matt Evans
2026-04-26 11:16   ` Leon Romanovsky

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=393f65a8-75c3-401c-b983-5814e1bfcba2@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