Linux CXL
 help / color / mirror / Atom feed
From: Alex Williamson <alex@shazbot.org>
To: <mhonap@nvidia.com>
Cc: <jgg@ziepe.ca>, <yishaih@nvidia.com>, <sumit.semwal@linaro.org>,
	<kvm@vger.kernel.org>, <virtualization@lists.linux.dev>,
	<linux-media@vger.kernel.org>, <dri-devel@lists.freedesktop.org>,
	<linaro-mm-sig@lists.linaro.org>, <linux-cxl@vger.kernel.org>,
	alex@shazbot.org
Subject: Re: [PATCH 1/5] vfio/pci: Move the excluded windows out of vfio_pci_core_do_io_rw()
Date: Wed, 2 Dec 2026 16:19:29 -0700	[thread overview]
Message-ID: <20261202161929.77d44151@shazbot.org> (raw)
In-Reply-To: <20261202093250.1683744-2-mhonap@nvidia.com>

On Wed, 2 Dec 2026 15:02:46 +0530
<mhonap@nvidia.com> wrote:

> From: Manish Honap <mhonap@nvidia.com>
> 
> 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.

> 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 <mhonap@nvidia.com>
> ---
>  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.

Thanks,
Alex

  parent reply	other threads:[~2026-12-02 23:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:32 [PATCH 0/5] vfio/pci: Per-BAR excluded ranges mhonap
2026-12-02  9:32 ` [PATCH 1/5] vfio/pci: Move the excluded windows out of vfio_pci_core_do_io_rw() mhonap
2026-12-02  9:44   ` sashiko-bot
2026-12-02 23:19   ` Alex Williamson [this message]
2026-12-02  9:32 ` [PATCH 2/5] vfio/virtio: Release vfio-pci-core state when legacy I/O setup fails mhonap
2026-12-02 23:19   ` Alex Williamson
2026-12-02  9:32 ` [PATCH 3/5] vfio/pci: Add per-BAR excluded ranges and put the MSI-X table on them mhonap
2026-12-02  9:32 ` [PATCH 4/5] vfio/pci: Advertise the mmap areas around excluded ranges mhonap
2026-12-02 23:19   ` Alex Williamson
2026-12-02  9:32 ` [PATCH 5/5] vfio/pci: Refuse ioeventfds and dma-buf exports over " mhonap
2026-12-02  9:42   ` sashiko-bot
2026-12-02 23:19   ` Alex Williamson

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=20261202161929.77d44151@shazbot.org \
    --to=alex@shazbot.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jgg@ziepe.ca \
    --cc=kvm@vger.kernel.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mhonap@nvidia.com \
    --cc=sumit.semwal@linaro.org \
    --cc=virtualization@lists.linux.dev \
    --cc=yishaih@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