Kernel KVM virtualization development
 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 5/5] vfio/pci: Refuse ioeventfds and dma-buf exports over excluded ranges
Date: Wed, 2 Dec 2026 16:19:11 -0700	[thread overview]
Message-ID: <20261202161911.1fc80ac4@shazbot.org> (raw)
In-Reply-To: <20261202093250.1683744-6-mhonap@nvidia.com>

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

> From: Manish Honap <mhonap@nvidia.com>
> 
> vfio_pci_bar_rw() keeps the excluded ranges of a BAR off the device, but
> two other paths can reach BAR MMIO without it.
> 
> An ioeventfd writes the BAR directly when it fires, through
> vfio_pci_core_iowriteN(). Refuse an ioeventfd whose range overlaps a
> write-excluded range. This replaces the open-coded MSI-X test: the MSI-X
> table is a write-excluded range, and the BAR length test already refuses
> the part of a table past the BAR.
> 
> A dma-buf export of a BAR range lets an importer map it for DMA, which
> reaches a range that the BAR keeps off mmap. Refuse an export whose
> ranges overlap an mmap-excluded range in validate_dmabuf_input(), so the
> dma-buf follows the same rule as mmap.

These are different things they fall into different categories.  An
ioeventfd is just a write triggered by an eventfd.  The WRITE exclusion
series is incomplete without it.  MSI-X shouldn't be left open coded
relative to ioeventfds.

dma-buf export is a memory access through DMA.  It's more related to
mmap.  It should be implemented along with VFIO_PCI_EXCLUDE_MMAP.
Thanks,

Alex

> 
> Suggested-by: Alex Williamson <alex@shazbot.org>
> Signed-off-by: Manish Honap <mhonap@nvidia.com>
> ---
>  drivers/vfio/pci/vfio_pci_core.c   |  4 ++--
>  drivers/vfio/pci/vfio_pci_dmabuf.c | 10 ++++++++--
>  drivers/vfio/pci/vfio_pci_priv.h   |  3 +++
>  drivers/vfio/pci/vfio_pci_rdwr.c   |  6 ++----
>  4 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 0b9da823456e..5d54d624982f 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -988,8 +988,8 @@ static int vfio_pci_for_each_slot_or_bus(struct pci_dev *pdev,
>  	return walk.ret;
>  }
>  
> -static bool vfio_pci_bar_range_excluded(struct vfio_pci_core_device *vdev,
> -					int bar, u64 start, u64 len, u32 flags)
> +bool vfio_pci_bar_range_excluded(struct vfio_pci_core_device *vdev, int bar,
> +				 u64 start, u64 len, u32 flags)
>  {
>  	struct range r = DEFINE_RANGE(start, start + len - 1);
>  	struct vfio_pci_excluded_range *x;
> diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
> index 7d1d34029b95..6f28cc285e78 100644
> --- a/drivers/vfio/pci/vfio_pci_dmabuf.c
> +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
> @@ -193,7 +193,8 @@ int vfio_pci_core_get_dmabuf_phys(struct vfio_pci_core_device *vdev,
>  }
>  EXPORT_SYMBOL_GPL(vfio_pci_core_get_dmabuf_phys);
>  
> -static int validate_dmabuf_input(struct vfio_device_feature_dma_buf *dma_buf,
> +static int validate_dmabuf_input(struct vfio_pci_core_device *vdev,
> +				 struct vfio_device_feature_dma_buf *dma_buf,
>  				 struct vfio_region_dma_range *dma_ranges,
>  				 size_t *lengthp)
>  {
> @@ -207,6 +208,11 @@ static int validate_dmabuf_input(struct vfio_device_feature_dma_buf *dma_buf,
>  		if (!len || !PAGE_ALIGNED(offset) || !PAGE_ALIGNED(len))
>  			return -EINVAL;
>  
> +		if (vfio_pci_bar_range_excluded(vdev, dma_buf->region_index,
> +						offset, len,
> +						VFIO_PCI_EXCLUDE_MMAP))
> +			return -EINVAL;
> +
>  		if (check_add_overflow(length, len, &length))
>  			return -EINVAL;
>  	}
> @@ -260,7 +266,7 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
>  	if (IS_ERR(dma_ranges))
>  		return PTR_ERR(dma_ranges);
>  
> -	ret = validate_dmabuf_input(&get_dma_buf, dma_ranges, &length);
> +	ret = validate_dmabuf_input(vdev, &get_dma_buf, dma_ranges, &length);
>  	if (ret)
>  		goto err_free_ranges;
>  
> diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h
> index 6def038cb213..a969ae3025c9 100644
> --- a/drivers/vfio/pci/vfio_pci_priv.h
> +++ b/drivers/vfio/pci/vfio_pci_priv.h
> @@ -55,6 +55,9 @@ struct vfio_pci_excluded_range {
>  	u32			flags;
>  };
>  
> +bool vfio_pci_bar_range_excluded(struct vfio_pci_core_device *vdev, int bar,
> +				 u64 start, u64 len, u32 flags);
> +
>  #ifdef CONFIG_VFIO_PCI_VGA
>  ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf,
>  			size_t count, loff_t *ppos, bool iswrite);
> diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
> index 04aed725325c..e620798f9007 100644
> --- a/drivers/vfio/pci/vfio_pci_rdwr.c
> +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
> @@ -475,10 +475,8 @@ int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset,
>  	if (pos + count > pci_resource_len(pdev, bar))
>  		return -EINVAL;
>  
> -	/* Disallow ioeventfds working around MSI-X table writes */
> -	if (bar == vdev->msix_bar &&
> -	    !(pos + count <= vdev->msix_offset ||
> -	      pos >= vdev->msix_offset + vdev->msix_size))
> +	if (vfio_pci_bar_range_excluded(vdev, bar, pos, count,
> +					VFIO_PCI_EXCLUDE_WRITE))
>  		return -EINVAL;
>  
>  	io = vfio_pci_core_get_iomap(vdev, bar);


      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
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 [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=20261202161911.1fc80ac4@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