Skip to content

[RFC] virtio-vsock: Introduce Reader/Writer support#392

Draft
luigix25 wants to merge 4 commits intorust-vmm:mainfrom
luigix25:fix_vsock
Draft

[RFC] virtio-vsock: Introduce Reader/Writer support#392
luigix25 wants to merge 4 commits intorust-vmm:mainfrom
luigix25:fix_vsock

Conversation

@luigix25
Copy link
Copy Markdown

@luigix25 luigix25 commented Mar 31, 2026

Summary of the PR

Linux can use more than 2 descriptor in a chain for a vsock packet and this crate does not handle it.
To fix it I'm using Reader/Writer helpers from the virtio-queue crate. This needs major (and breaking) changes.

I'm splitting the VsockPacket in Rx and Tx, because in the first one I need writers while in the second Readers.

I had to delete some tests because they no longer apply.

Fixes: #216

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

Replace the unified VsockPacket type with two separate types:
- VsockPacketTx, backed by a Reader for device-readable TX chains
- VsockPacketRx, backed by Writer for device-writable RX chains

This removes the VolatileSlice-based implementation, replacing
them with the higher-level Reader/Writer abstractions from virtio-queue.
Setters and getters are moved directly onto PacketHeader, and the unsafe
VsockPacket::new() constructor is removed.

vsock packets can be split across multiple descriptors, up until now
the code assumed that header + payload was in a single descriptor or the header
was on the first descriptor and the data on the second one.
This is not compliant to the standard, as multiple descriptors can be used.
This is actually the case for Linux with a payload bigger than 32k.
Reader and Writer abstraction handle this.

Some tests had to be dropped, because with the Reader/Writer is not
possible to get the addresses of the slices.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Take the DescriptorChain by value instead of by mutable reference.
This removes the need for Clone trait on the DescriptorChain's memory
handle, since Reader/Writer can be constructed directly from the owned
chain.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
@luigix25
Copy link
Copy Markdown
Author

TODO:

  • Fix fuzzing
  • Improve commit messages

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.

vsock: make the descriptor chain parsing more generic

1 participant