Skip to content

virtio-vsock: Introduce Reader/Writer support - #392

Open
luigix25 wants to merge 7 commits into
rust-vmm:mainfrom
luigix25:fix_vsock
Open

virtio-vsock: Introduce Reader/Writer support#392
luigix25 wants to merge 7 commits into
rust-vmm:mainfrom
luigix25:fix_vsock

Conversation

@luigix25

@luigix25 luigix25 commented Mar 31, 2026

Copy link
Copy Markdown

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.

Since this PR involves major changes in the virtio-vsock crate I'd like some general feedback about the new architecture.

Fuzzing has not been modified yet, this is why CI it's failing. It requires massive changes and I'd like to get some feedback around the architecture first.

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.

@luigix25

luigix25 commented Mar 31, 2026

Copy link
Copy Markdown
Author

TODO:

  • Fix fuzzing
  • Improve commit messages

@luigix25
luigix25 force-pushed the fix_vsock branch 2 times, most recently from 8c08933 to 36d34b8 Compare April 20, 2026 13:49
@luigix25
luigix25 marked this pull request as ready for review April 29, 2026 15:59
@luigix25
luigix25 force-pushed the fix_vsock branch 2 times, most recently from 247b503 to 15d7372 Compare May 20, 2026 10:23
@luigix25

luigix25 commented May 20, 2026

Copy link
Copy Markdown
Author
  • Restored old VsockPacket struct and marked it as deprecated.
  • Moved shared definitions between VsockPacket and VsockPacketRx/Tx to a common file
  • Fixed various clippy and cargo fmt problems.

TODO:

  • Add fuzzing for new VsockPacketRx/Tx

@luigix25

Copy link
Copy Markdown
Author

mmh not sure why fuzzing is failing. It's untouched.

@stefano-garzarella

Copy link
Copy Markdown
Member

mmh not sure why fuzzing is failing. It's untouched.

Is seemed more infra issue, restarting helped.

@epilys epilys 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.

LGTM in general, will need to take another deep look once I have more time

Comment thread virtio-vsock/src/lib.rs Outdated
Comment thread virtio-vsock/src/packet_rw.rs Outdated
Comment thread virtio-vsock/src/packet_rw.rs Outdated
Comment thread virtio-vsock/src/packet_rw.rs Outdated
Comment thread virtio-vsock/src/packet_rw.rs Outdated
Comment thread virtio-vsock/src/packet_rw.rs
@luigix25

Copy link
Copy Markdown
Author

[@epilys]

  • Squashed commit
  • Fixed links and improved doc
  • dropped defs module. Moved everything to lib.rs

luigix25 added 5 commits July 14, 2026 14:45
Add getter/setter methods directly on PacketHeader. This is preliminary
work for new APIs that will be introduced in a following commit.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Move PacketHeader, Error, Result, and PKT_HEADER_SIZE from the packet
module into lib.rs so they can be shared across the crate without
circular dependencies.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Add VsockPacketTx and VsockPacketRx in the new packet_rw module. These
use virtio_queue's Reader/Writer abstractions instead of raw VolatileSlice,
providing a cleaner and safer API for vsock packet handling.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Mark VsockPacket as deprecated in favor of the new VsockPacketTx/VsockPacketRx
API introduced earlier.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
@epilys

epilys commented Jul 14, 2026

Copy link
Copy Markdown
Member

I think it looks good, is there anything left todo?

@luigix25

Copy link
Copy Markdown
Author

I think it looks good, is there anything left todo?

Hi Manos! The only thing missing is fuzzing using the new APIs. I am also rebasing the corresponding vhost-device PR.

Apart from fuzzing I think it's ready

@luigix25 luigix25 changed the title [RFC] virtio-vsock: Introduce Reader/Writer support virtio-vsock: Introduce Reader/Writer support Jul 14, 2026
The corpus-generation tests in vsock.rs defined a set of header-field
constants (SRC_CID, DST_CID, ports, etc.) locally in their test module.
The upcoming vsock_rw fuzzer needs the same constants.  Extract them
into a new fuzz/common/src/vsock_common.rs test_utils sub-module so
both can share them without duplication.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
@luigix25

Copy link
Copy Markdown
Author

Added fuzzing

  • For disclosure: i used claude to generate it, I reviewed and I think looks ok, but I'm not a fuzzing expert. If you think it's useless, i can drop it.

Add a vsock_rw fuzz target that exercises the VsockPacketTx and
VsockPacketRx APIs introduced in packet_rw.  The fuzzer deserializes a
bincode-encoded VsockRwInput that controls both the virtqueue descriptor
layout and the sequence of typed API calls (header getters/setters, data
reads/writes) to replay against the constructed packet.  This gives the
fuzzer structured control over descriptor contents and call sequences,
making it easier to reach interesting code paths than byte-level fuzzing.

Corpus-generation tests are included to seed the fuzzer with known-good
TX and RX descriptor chains.

Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
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

3 participants