Thanks to visit codestin.com
Credit goes to github.com

Skip to content

virtio-devices: Fix some spec compliance issues - #8066

Merged
rbradford merged 7 commits into
cloud-hypervisor:mainfrom
rbradford:202604/virtio-fixes
Apr 20, 2026
Merged

rbradford merged 7 commits into
cloud-hypervisor:mainfrom
rbradford:202604/virtio-fixes

Conversation

@rbradford

@rbradford rbradford commented Apr 20, 2026

Copy link
Copy Markdown
Member

Fix some basic spec compliance issues. :

  • Tolerating multiple writable descriptors (some devices already did this)
  • Ensuring the correct number of bytes reported via add_used()
  • Supporting descriptors larger than our version of the struct.

I used Claude to compare the virtio spec with our implementation. There was a lot of issues; these are fixes for all those related to reporting wrong bytes written with .add_used() and incorrect descriptor chain expectations (multiple writable, too strict.)

  • virtio-devices: net: Report correct used length on TX and ctrl
  • virtio-devices: mem: Relax descriptor size check
  • virtio-devices: pmem: Relax descriptor size check
  • virtio-devices: pmem: Always write status response on error
  • virtio-devices: rng: Fill the entire descriptor chain
  • vhost_user_block: Correctly report number of used bytes
  • virtio-devices: block: Correctly report number of bytes written

@rbradford
rbradford force-pushed the 202604/virtio-fixes branch from 3daf90f to 8ed3adb Compare April 20, 2026 11:17

@phip1611 phip1611 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally LGTM! Did you use an LLM to find all the spec inconsistencies?

Comment thread virtio-devices/src/pmem.rs
Comment thread virtio-devices/src/rng.rs
@rbradford
rbradford force-pushed the 202604/virtio-fixes branch from 8ed3adb to e94aea6 Compare April 20, 2026 12:07
@rbradford
rbradford marked this pull request as ready for review April 20, 2026 12:07
@rbradford
rbradford requested a review from a team as a code owner April 20, 2026 12:07
@rbradford

Copy link
Copy Markdown
Member Author

generally LGTM! Did you use an LLM to find all the spec inconsistencies?

Yes, I updated the PR description.

The virtio spec says the used-ring length is bytes the device wrote to
device writable descriptors. The net TX descriptors are device readable
only (the device wrote nothing back) so the length needs to be 0. On the
ctrl queue the number of bytes reported was wrongly the size of the
status descriptor not the number of bytes written (the descriptor is
permitted to be larger).

Signed-off-by: Rob Bradford <[email protected]>
The virtio spec allows the use of larger descriptors (for future
expansion). Relax the bounds check to only reject descriptors that are
too small.

Signed-off-by: Rob Bradford <[email protected]>
The virtio spec allows the use of larger descriptors (for future
expansion). Relax the bounds check to only reject descriptors that are
too small.

Signed-off-by: Rob Bradford <[email protected]>
The virtio spec requires that a status response is always written on
error. This was missing from the path where we had a valid request but
not for one we support.

Signed-off-by: Rob Bradford <[email protected]>
The virtio spec allows a chain of writable descriptors however the rng
device was assuming just a single writable descriptor. Instead fill in
all writable descriptors. There is no status byte (unlike e.g. block)
and instead 0 bytes used is used to indicate error.

Signed-off-by: Rob Bradford <[email protected]>
The number of bytes written into descriptors should be reported for
`add_used()`. Here it is either just the status byte or also the size of
serial ID for the block device.

Signed-off-by: Rob Bradford <[email protected]>
The driver needs to be notified with the number of bytes written by the
device. Ensure that the correct number of bytes is reported.

Signed-off-by: Rob Bradford <[email protected]>
@rbradford
rbradford force-pushed the 202604/virtio-fixes branch from e94aea6 to 88ff419 Compare April 20, 2026 13:34
@rbradford

Copy link
Copy Markdown
Member Author

@phip1611 PTAL!

@rbradford
rbradford added this pull request to the merge queue Apr 20, 2026
Merged via the queue into cloud-hypervisor:main with commit 9a14fdb Apr 20, 2026
38 checks passed
@rbradford rbradford moved this to ✅ Done in Cloud Hypervisor Roadmap Apr 25, 2026
@rbradford
rbradford deleted the 202604/virtio-fixes branch June 12, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants