> -----Original Message-----
> From: Alex Williamson <[email protected]>
> Sent: Thursday, December 3, 2026 4:49 AM
> To: Manish Honap <[email protected]>
> Cc: [email protected]; Yishai Hadas <[email protected]>;
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; linaro-mm-
> [email protected]; [email protected]; [email protected]
> Subject: Re: [PATCH 1/5] vfio/pci: Move the excluded windows out of
> vfio_pci_core_do_io_rw()
> 
> External email: Use caution opening links or attachments
> 
> 
> On Wed, 2 Dec 2026 15:02:46 +0530
> <[email protected]> wrote:
> 
> > From: Manish Honap <[email protected]>
> >
> > vfio_pci_core_do_io_rw() fills reads with 0xff and drops writes in one
> > excluded window given by its caller. vfio_pci_bar_rw() sets it to the
> > MSI-X table or to the part of a ROM BAR past the ROM image.
> > vfio_pci_vga_rw() and nvgrace-gpu pass an empty window.
> >
> > The next patch for vfio-cxl series puts the MSI-X table on a per-BAR
> > list of excluded ranges, and a BAR can then have more than one such
> > range (CXL component register region range)
> 
> The "next patch" reference should be avoided in commit logs, series are an
> ephemeral thing that exist on the mailing list, and especially here, it's not 
> even
> referring to the next patch in this series.
> 

Okay, for v2, I will mention vfio-cxl and HDM decoder registers as the user.

> > Add a helper in vfio_pci_bar_rw() that sends the bytes before a range
> > to the device in a call of their own, so no device access runs into
> > the range, and fills or drops the bytes of the range. Use it for the
> > MSI-X table and for the ROM BAR past the ROM image. Remove the window
> > arguments from vfio_pci_core_do_io_rw() and its callers.
> >
> > No functional change.
> >
> > Signed-off-by: Manish Honap <[email protected]>
> > ---
> >  drivers/vfio/pci/nvgrace-gpu/main.c |   4 +-
> >  drivers/vfio/pci/vfio_pci_rdwr.c    | 115 ++++++++++++++++++----------
> >  include/linux/vfio_pci_core.h       |   3 +-
> >  3 files changed, 76 insertions(+), 46 deletions(-)
> >
> > diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c
> > b/drivers/vfio/pci/nvgrace-gpu/main.c
> > index 5ddec340b73b..432f6b9c2842 100644
> > --- a/drivers/vfio/pci/nvgrace-gpu/main.c
> > +++ b/drivers/vfio/pci/nvgrace-gpu/main.c
> > @@ -787,7 +787,7 @@ nvgrace_gpu_map_and_read(struct
> nvgrace_gpu_pci_core_device *nvdev,
> >               ret = vfio_pci_core_do_io_rw(&nvdev->core_device, false,
> >                                            nvdev->resmem.ioaddr,
> >                                            buf, offset, mem_count,
> > -                                          0, 0, false, 
> > VFIO_PCI_IO_WIDTH_8);
> > +                                          false,
> > + VFIO_PCI_IO_WIDTH_8);
> >       }
> >
> >       return ret;
> > @@ -925,7 +925,7 @@ nvgrace_gpu_map_and_write(struct
> nvgrace_gpu_pci_core_device *nvdev,
> >               ret = vfio_pci_core_do_io_rw(&nvdev->core_device, false,
> >                                            nvdev->resmem.ioaddr,
> >                                            (char __user *)buf, pos, 
> > mem_count,
> > -                                          0, 0, true, VFIO_PCI_IO_WIDTH_8);
> > +                                          true, VFIO_PCI_IO_WIDTH_8);
> >       }
> >
> >       return ret;
> > diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c
> > b/drivers/vfio/pci/vfio_pci_rdwr.c
> > index df8848087681..68008f28bcbe 100644
> > --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> > +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> > @@ -12,6 +12,7 @@
> >
> >  #include <linux/fs.h>
> >  #include <linux/pci.h>
> > +#include <linux/range.h>
> >  #include <linux/uaccess.h>
> >  #include <linux/io.h>
> >  #include <linux/vfio.h>
> > @@ -126,66 +127,41 @@ VFIO_IORDWR(16)
> >  VFIO_IORDWR(32)
> >  VFIO_IORDWR(64)
> >
> > -/*
> > - * Read or write from an __iomem region (MMIO or I/O port) with an
> > excluded
> > - * range which is inaccessible.  The excluded range drops writes and
> > fills
> > - * reads with -1.  This is intended for handling MSI-X vector tables
> > and
> > - * leftover space for ROM BARs.
> > - */
> > +/* Read or write from an __iomem region (MMIO or I/O port) */
> >  ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device *vdev, bool
> test_mem,
> >                              void __iomem *io, char __user *buf,
> > -                            loff_t off, size_t count, size_t x_start,
> > -                            size_t x_end, bool iswrite,
> > +                            loff_t off, size_t count, bool iswrite,
> >                              enum vfio_pci_io_width max_width)
> 
> I think there's a better shape to this series, and I think we should keep
> vfio_pci_core_do_io_rw() as the variant driver facing API.  I'd propose the
> following sequence replacing 1 and 3, interleave the virtio patch as 
> necessary:
> 
>  1. Simple conversion from x_start, x_end to a range.  Pass NULL for an
>     empty range rather than {0, 0}.
>  2. Split static __vfio_pci_do_io_rw() from vfio_pci_core_do_io_rw() as
>     the helper that reads contiguous chunks, called by the original
>     function that retains the range information.
>  3. Convert from a range to a list_head.  Callers allocate the list on
>     the stack and vfio_pci_core_do_io_rw() learns to iterate a list of
>     excluded ranges.
>  4. Introduce the per BAR excluded range list, populating MSI-X.  ROM
>     remains a stack allocated list based on pci_map_rom().  Common
>     vfio_pci_core_do_io_rw() call sites now use the list_head on the
>     BAR, while ROM, VGA, and variant driver decide whether to use a
>     list_head or NULL.  For example the nvgrace use case could pass the
>     list_head from the BAR index or NULL.
> 

Okay, I will restructure the patch sequence as per suggestion in v2.

Thanks,
Manish

> Thanks,
> Alex

Reply via email to