Skip to content

feat(vfio-user): implement VFIO_USER_DEVICE_GET_REGION_IO_FDS - #521

Merged
Lencerf merged 2 commits into
google:mainfrom
Lencerf:feat/vfio-user-ioeventfd
Oct 7, 2026
Merged

Lencerf merged 2 commits into
google:mainfrom
Lencerf:feat/vfio-user-ioeventfd

Conversation

@Lencerf

@Lencerf Lencerf commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

KvmIoeventFdRegistry has to remember every registration in a per-VM
HashMap keyed by the raw fd, because deregister() only receives the
notifier while KVM_IOEVENTFD needs {addr, len, datamatch, flags} to
deassign an entry. That map also breaks for any caller registering one
notifier at several addresses, e.g. a vfio-user device that shares one
eventfd between sub-regions: the second registration overwrites the
bookkeeping of the first, and deregistering then leaves a live KVM
ioeventfd behind.

Hand the registration parameters back to deregister() instead, so the
registry needs no state and makes no assumptions about how callers use
their fds. To let a callback reconstruct them,
MemRegionCallback::unmapped() now receives the address the region is
unmapped from, symmetric with mapped(); both call sites already have it.

Assisted-by: Antigravity:Claude-Opus-5
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
Ask the server which sub-regions of a BAR it wants to watch with a file
descriptor, and register them as ioeventfds, so that a doorbell write no
longer travels through a VM exit and a REGION_WRITE round trip.

Device gains get_region_notifiers(), defaulting to none: kernel VFIO has
no equivalent, VFIO_DEVICE_IOEVENTFD goes the other way round and hands
an eventfd to the kernel so that it writes a fixed value to the device.
VfioPciDev::new() now takes an optional notifier registry, shared by the
BAR callbacks, which register the notifiers once the guest programs a
BAR address, mirroring what virtio-pci does for its queue notifiers.

Only VFIO_USER_IO_FD_TYPE_IOEVENTFD is honored. An ioregionfd needs a
KVM feature that is not upstream, and a shadow ioeventfd additionally
needs KVM to store the written value in a shared buffer, which upstream
cannot do either; libvfio-user documents clients as free to ignore it.
Sub-regions with KVM_IOEVENTFD_FLAG_PIO are dropped as well, since
NotifierRegistry cannot express port IO, as are sub-regions reaching
past the region, which the protocol makes the client's job to check.

Note the sub-region layout follows libvfio-user, which sends 48-byte
entries carrying the shadow fields whatever the type. The protocol
documentation describes 40-byte entries, predating shadow ioeventfds,
and computes the entry stride from an argsz that includes the message
header, which no implementation does.

Assisted-by: Antigravity:Claude-Opus-5
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@coveralls

coveralls commented Oct 7, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 37578781737

Coverage increased (+0.6%) to 39.652%

Details

  • Coverage increased (+0.6%) from the base build.
  • Patch coverage: 43 uncovered changes across 6 files (162 of 205 lines covered, 79.02%).
  • 3 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
alioth/src/vm/vm.rs 18 0 0.0%
alioth/src/hv/kvm/vm/vm.rs 9 0 0.0%
alioth/src/vfio/user/conn.rs 57 51 89.47%
alioth/src/vfio/pci.rs 68 63 92.65%
alioth/src/vfio/device.rs 3 0 0.0%
alioth/src/vfio/user/device.rs 36 34 94.44%
Total (8 files) 205 162 79.02%

Coverage Regressions

3 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
alioth/src/virtio/dev/vsock/uds_vsock.rs 2 81.51%
alioth/src/vm/vm.rs 1 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 15681
Covered Lines: 6042
Line Coverage: 38.53%
Relevant Branches: 1670
Covered Branches: 838
Branch Coverage: 50.18%
Branches in Coverage %: Yes
Coverage Strength: 912.71 hits per line

💛 - Coveralls

@Lencerf
Lencerf enabled auto-merge October 7, 2026 05:57
@Lencerf
Lencerf added this pull request to the merge queue Oct 7, 2026
Merged via the queue into google:main with commit b3d3176 Oct 7, 2026
20 checks passed
@Lencerf
Lencerf deleted the feat/vfio-user-ioeventfd branch October 7, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants