Skip to content

feat: Add Seqpacket support#5595

Open
aerosouund wants to merge 31 commits intofirecracker-microvm:mainfrom
aerosouund:vsock
Open

feat: Add Seqpacket support#5595
aerosouund wants to merge 31 commits intofirecracker-microvm:mainfrom
aerosouund:vsock

Conversation

@aerosouund
Copy link
Copy Markdown
Contributor

@aerosouund aerosouund commented Dec 20, 2025

Changes

There's currently no support for seqpacket based vsock connections in firecracker.
This PR adds it by creating an enum ConnBackend that implements VsockConnectionBackend and make its variants a unix stream or a seqpacket connection. The actual connection is handled by a module for seqpacket based connection that leverages libc calls.
It adds vsock_type as an api parameter to the vsock type.

Reason

Fixes: #4822

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

@aerosouund aerosouund force-pushed the vsock branch 22 times, most recently from 9cb7f64 to 4988a5e Compare December 26, 2025 18:31
@aerosouund aerosouund changed the title Vsock feat: Add Seqpacket support Dec 26, 2025
@aerosouund aerosouund marked this pull request as ready for review December 26, 2025 18:38
@JamesC1305 JamesC1305 self-assigned this Jan 8, 2026
- Make the multiplexer use a VsockConnection<ConnBackend> for its
conn_map values to forward calls to stream or seqpacket types.

- Make the host sock a boxed implementation of the Socket trait which
exposes the accept() method with different implementations for stream
and seqpacket connections.

- Globally replace the MuxerConnection type with a VsockConnection
generic over a ConnBackend.

- Make the init_pkt_hdr method add different type constants based on
the vsock type.

Signed-off-by: aerosouund <aerosound161@gmail.com>
Add a new field to the vsock api and modify functions that interact with
a VsockDeviceConfig or a VsockUnixBackend.

Signed-off-by: aerosouund <aerosound161@gmail.com>
add changelog entry for the modified field

Signed-off-by: aerosouund <aerosound161@gmail.com>
- incoming length is a trait with a default implementation to read the
  size of an incoming message from a connection fd
- read result stores the count of bytes read and whether or no another
  receive should be triggered
- change the VsockChannel trait to return a ReadResult instead of null

Signed-off-by: aerosouund <aerosound161@gmail.com>
- create a set_msg_eom function to set eom in the packet header

Signed-off-by: aerosouund <aerosound161@gmail.com>
- make it start another loop iteration if it received a result with
  should_retrigger

Signed-off-by: aerosouund <aerosound161@gmail.com>
- add connection_buffer and conn_buffer_wrote_bytes fields to the
  connection
- when there's a seqpacket connection with incoming data check the
  length of the incoming message
- if its small enough to fit in the packet buffer (1 memory page size)
  receive directly from the af_unix to the buffer
- if its bigger, receive into a buffer then copy whatever you can fit
  into the buffer and mark that we should retrigger
- if the buffer has data, don't read from the stream. iterate until you
  finish the buffer
- don't use intermediate rx buffering for stream connections

Signed-off-by: aerosouund <aerosound161@gmail.com>

connection fix

Signed-off-by: aerosouund <aerosound161@gmail.com>

squash

Signed-off-by: aerosouund <aerosound161@gmail.com>
- propagate conn_buffer_size to connections on creation to determine
  how big the rx intermediate buffer should be
- if the result coming from the connection has should_retrigger push to
  the rx queue to mark that there's still data to be read from the
buffer

Signed-off-by: aerosouund <aerosound161@gmail.com>
- the setting should be persisted across snapshot and restore so the new
  vsock buffers have the same size

Signed-off-by: aerosouund <aerosound161@gmail.com>
- if the incoming message is larger than the connection buffer
  we return VsockError::MessageTooLong

Signed-off-by: aerosouund <aerosound161@gmail.com>
- add safety comments, clippy lint supressing for too many args, remove
  unnecessary casts and indent functions properly

Signed-off-by: aerosouund <aerosound161@gmail.com>
- make the serialization of the conn_buffer_size skipped if its none

Signed-off-by: aerosouund <aerosound161@gmail.com>
- make the field documented in the api and the readme

Signed-off-by: aerosouund <aerosound161@gmail.com>
covering the following scenarios:

- receiving a message larger than one memory page
- receiving a message small enough to fit in one page
- receiving a message exactly one memory page (should cause a single
  receive with eom)
- receiving a message larger than the conn_buffer_size, should error

Signed-off-by: aerosouund <aerosound161@gmail.com>
- prevent the caller from passing too large buffers. 256 is also the
  limit set by the linux kernel

Signed-off-by: aerosouund <aerosound161@gmail.com>
- seqpacket sockets necessitate that you read the
  message in one go

Signed-off-by: aerosouund <aerosound161@gmail.com>
- fix serialization error to make the field default to none

Signed-off-by: aerosouund <aerosound161@gmail.com>
- seqpacket sockets necessitate a different flag set than
  whats currently in the seccomp rules. we need to add
  seqpacket with SOCK_CLOEXEC for testing to work

Signed-off-by: aerosouund <aerosound161@gmail.com>
- use ioctl FIONBIO to make connections non blocking instead
  of relying on SOCK_NONBLOCK
- fix UB where the addr variable was being dropped while a
  live pointer to it was being returned

Signed-off-by: aerosouund <aerosound161@gmail.com>
- the functional tests use an echo server which is just a socat command.
  socat doesn't support seqpacket.
- the program listens on a port and handles a connection in a separate
  thread

Signed-off-by: aerosouund <aerosound161@gmail.com>
- can be stream or seqpacket. to facilitate seqpacket testing

Signed-off-by: aerosouund <aerosound161@gmail.com>
- create a fixture to compile the vsock_seq_server program
- create start_seqpacket_echo_server to run the program in
  the vm
- create the check_guest_connections_seqpacket function to
  start a host side seqpacket server and connect to it from
  the guestn and check data hash
- create h2g, g2h and overflow functional tests

Signed-off-by: aerosouund <aerosound161@gmail.com>
- seqpacket was introduced in linux 5.14. any previous version would
  fail

Signed-off-by: aerosouund <aerosound161@gmail.com>
- the api will return an error without this field in the payload

Signed-off-by: aerosouund <aerosound161@gmail.com>
- the test_cycled_snapshot_restore test checks for its existence in the
  output

Signed-off-by: aerosouund <aerosound161@gmail.com>
- add missing safety blocks
- add missing lisence for the seqpacket c server
- collapse if statement in vsock.rs

Signed-off-by: aerosouund <aerosound161@gmail.com>
- fix test line spacing, import ordering, indentation, formatting
  function calls

Signed-off-by: aerosouund <aerosound161@gmail.com>
- add python docstrings and arrange imports

Signed-off-by: aerosouund <aerosound161@gmail.com>
@aerosouund
Copy link
Copy Markdown
Contributor Author

@JamesC1305 fixed the merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Awaiting author Indicates that an issue or pull request requires author action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add SEQPACKET socket type for vsock

2 participants