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 <[email protected]>
> ---
> 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;
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
>