Repository navigation
Conversation
A guest can write more than 32 bits to an eventfd before a device needs the underlying Linux descriptor. eventfd2 takes an unsigned int, so passing the accumulated counter as its initial value lost the high bits. Seed the low bits at creation, write any remaining amount while the descriptor is still private, and clear the guest counter only after the transfer succeeds.
tamird
force-pushed
the
review/eventfd-preserve-host-counter
branch
from
October 28, 2026 21:55
57e4b37 to
d94cb4a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A guest can write more than 32 bits to an eventfd before a device asks
for the underlying Linux file descriptor. The Gasket and VFIO interrupt
paths do this when registering an eventfd with the host. If a guest
creates an eventfd with 1 and writes 2^32, eventfd2's 32-bit initial
argument leaves the host descriptor with 1 instead of 4,294,967,297.
Create the descriptor with the low 32 bits, then write the rest before
handing it to the device. If the write or notifier registration fails,
close the private descriptor and keep the guest's counter. Counters
that already fit in the eventfd2 argument need no additional syscall.
The regression reads the actual descriptor in ordinary and semaphore
modes at UINT32_MAX, 2^32+1 and UINT64_MAX−1. To check a large
semaphore without draining it, read once, fill its predicted remaining
capacity, then check that writing one more returns EAGAIN.