All of lore.kernel.org
 help / color / mirror / Atom feed
From: <mhonap@nvidia.com>
To: <jgg@ziepe.ca>, <yishaih@nvidia.com>, <sumit.semwal@linaro.org>
Cc: <kvm@vger.kernel.org>, <virtualization@lists.linux.dev>,
	<linux-media@vger.kernel.org>, <dri-devel@lists.freedesktop.org>,
	<linaro-mm-sig@lists.linaro.org>, <mhonap@nvidia.com>,
	<linux-cxl@vger.kernel.org>
Subject: [PATCH 0/5] vfio/pci: Per-BAR excluded ranges
Date: Wed, 2 Dec 2026 15:02:45 +0530	[thread overview]
Message-ID: <20261202093250.1683744-1-mhonap@nvidia.com> (raw)

From: Manish Honap <mhonap@nvidia.com>

vfio-pci keeps the user away from one range of a BAR, the MSI-X table:
reads through the device file return 0xff and writes are dropped. The
vfio-cxl series needs the same for the HDM decoder registers of a CXL
device, and Piotr's xe RFC [3] needs it for ranges of an xe BAR. Alex
pointed both at one generic interface [4]. This series adds it, with
the MSI-X table as its in-tree user.

Patch 1 moves the MSI-X and ROM windows out of the exported
vfio_pci_core_do_io_rw() into vfio_pci_bar_rw(). The VGA and
nvgrace-gpu callers lose two arguments. No functional change.

Patch 2 fixes an error path in virtio-vfio that skips
vfio_pci_core_release_dev(). Patch 3 allocates in
vfio_pci_core_init_dev() and would leak there.

Patch 3 adds a list of excluded ranges for each standard BAR, sorted by
start. Each range has flags for mmap, read and write. The lists are
built in .init and freed in .release, so readers take no lock. The
MSI-X table is the first range, excluded from read and write. If its
BIR or offset is outside a standard BAR, nothing is added and one
warning is printed.

Patch 4 refuses an mmap that overlaps a range excluded from mmap, and
reports the other areas of the BAR with a sparse mmap capability. The
MSI-X table is not excluded from mmap, so the MSI-X BAR stays mappable
as it has been since commit a32295c612c5 ("vfio-pci: Allow mapping MSIX
BAR").

Patch 5 refuses an ioeventfd over a range excluded from write, and a
dma-buf export over a range excluded from mmap. The generic test
replaces the open-coded MSI-X ioeventfd test.

After this series no in-tree range is excluded from mmap, so patch 4
and the dma-buf check in patch 5 have no in-tree trigger yet. The
vfio-cxl v7 series adds the first such range, the HDM decoder
registers, and exports vfio_pci_core_add_excluded_range() with it.
Piotr's xe ranges are the second. If you prefer, patch 4 can move into
the vfio-cxl series, in front of its first user.

Changes from vfio-cxl v6 08 to 10/31 [1]:
- Patches 1 and 2 are new.
- Patch 3 (v6 08): lists built in vfio_pci_core_init_dev() and freed in
  vfio_pci_core_release_dev() (Alex, 08/31 [2]). Entries use struct
  range. The ROM BAR keeps its range past the ROM image outside the
  list. The MSI-X table is added by its own helper.
- Patch 4 (v6 09): count the sparse areas, allocate and fill them once
  (Alex, 09/31 [6]). VFIO_REGION_INFO_CAP_MSIX_MAPPABLE is not reported
  when a range excluded from mmap covers the MSI-X table pages (Sashiko
  on Piotr's RFC 2/4 [5]).
- Patch 5 (v6 10): the dma-buf check is in validate_dmabuf_input()
  (Alex, 10/31 [7]). The open-coded MSI-X ioeventfd test is removed.
- The export of vfio_pci_core_add_excluded_range() moves to the
  vfio-cxl series, with its first caller.

Testing:
 - Series applies cleanly to v7.4-rc4 (b6a9fa34ce41)
 - Tested with a passthrough guest on VR-NVL72 system with running
   CUDA/UVM workloads in guest.
 - No vfio selftests, kmemleak or sparse were run.

[1] https://lore.kernel.org/all/20261016161839.2765592-1-mhonap@nvidia.com/
[2] https://lore.kernel.org/all/20261106085939.764b6dde@shazbot.org/
[3] https://lore.kernel.org/all/20261105153738.1938345-1-piotr.piorkowski@intel.com/
[4] https://lore.kernel.org/all/20261105085032.679881ff@shazbot.org/
[5] https://lore.kernel.org/all/sashiko-outbox-199483@kernel.org/
[6] https://lore.kernel.org/all/20261106133920.144f0665@shazbot.org/
[7] https://lore.kernel.org/all/20261106135245.2870aebb@shazbot.org/

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

Manish Honap (5):
  vfio/pci: Move the excluded windows out of vfio_pci_core_do_io_rw()
  vfio/virtio: Release vfio-pci-core state when legacy I/O setup fails
  vfio/pci: Add per-BAR excluded ranges and put the MSI-X table on them
  vfio/pci: Advertise the mmap areas around excluded ranges
  vfio/pci: Refuse ioeventfds and dma-buf exports over excluded ranges

 drivers/vfio/pci/nvgrace-gpu/main.c |   4 +-
 drivers/vfio/pci/vfio_pci_core.c    | 178 +++++++++++++++++++++++++++-
 drivers/vfio/pci/vfio_pci_dmabuf.c  |  10 +-
 drivers/vfio/pci/vfio_pci_priv.h    |  14 +++
 drivers/vfio/pci/vfio_pci_rdwr.c    | 152 ++++++++++++++++--------
 drivers/vfio/pci/virtio/main.c      |   5 +-
 include/linux/vfio_pci_core.h       |   5 +-
 7 files changed, 312 insertions(+), 56 deletions(-)

-- 
2.53.0


             reply	other threads:[~2026-12-02  9:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:32 mhonap [this message]
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  9:32 ` [PATCH 2/5] vfio/virtio: Release vfio-pci-core state when legacy I/O setup fails mhonap
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  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  9:47 ` [PATCH 0/5] vfio/pci: Per-BAR " sashiko-bot

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=20261202093250.1683744-1-mhonap@nvidia.com \
    --to=mhonap@nvidia.com \
    --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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.