Skip to content

virtio_net/consomme: add USO support #3114

Open
damanm24 wants to merge 15 commits intomicrosoft:mainfrom
damanm24:udp-gso
Open

virtio_net/consomme: add USO support #3114
damanm24 wants to merge 15 commits intomicrosoft:mainfrom
damanm24:udp-gso

Conversation

@damanm24
Copy link
Copy Markdown
Contributor

Implements VIRTIO_NET_F_HOST_USO support, allowing the guest to send large UDP super-packets that the host splits into individual datagrams using host OS provided APIs

Background:

USO (UDP Segmentation Offload) is the UDP analogue of TSO. Instead of the guest sending many individual datagrams, it sends one large buffer with a gso_size hint in the virtio header. The host then splits it at the transport layer, producing independent UDP datagrams.

Changes:

net_backend: Adds TxOffloadSupport::uso, TxFlags::offload_udp_segmentation, and TxMetadata::max_udp_segment_size to carry USO metadata through the TX pipeline.

virtio_net: Advertises HOST_USO to the guest. Handles VirtioNetHeaderGsoProtocol::UDP_L4 in parse_tx_offloads, extracting gso_size and setting the new offload flags. IPv4 USO packets also set offload_ip_header_checksum for the same reason as TSO. The IP header length validation in consomme is extended to skip total_len checks for USO super-packets, mirroring the existing TSO handling.

consomme UDP send path: Adds gso: Option to ChecksumState. Each UdpConnection tracks the currently configured GSO segment size and calls platform::set_udp_gso_size only when it changes, avoiding redundant syscalls. The subsequent send is a plain send_to on Linux and Windows since the socket is pre-configured.

Platform implementations:

  • Linux: setsockopt(IPPROTO_UDP, UDP_SEGMENT, size) — persists for the socket's lifetime; kernel handles segmentation transparently on each send_to.
  • Windows: setsockopt(IPPROTO_UDP, UDP_SEND_MSG_SIZE, size) — same persistent model.
  • macOS: No equivalent socket option; uses the private sendmsg_x() API to batch all segments in a single syscall with one msghdr_x entry per segment (user-space segmentation).

Running the following benchmark:

  import socket, time

  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  sock.setsockopt(socket.IPPROTO_UDP, 103, 1472)  # UDP_SEGMENT

  data = b'x' * 65000
  host = '<host_ip>'
  count = 0
  start = time.time()

  while time.time() - start < 10:
      sock.sendto(data, (host, 5201))
      count += 1

  elapsed = time.time() - start
  gbps = (count * 65000 * 8) / elapsed / 1e9
  print(f"{count} sends in {elapsed:.1f}s = {gbps:.2f} Gbps")

Yielded the following results:
35930 sends in 10.0s = 1.87 Gbps (from main branch)
107842 datagrams sent in 10.0s = 5.61Gbps (with these changes)

@damanm24 damanm24 requested a review from a team as a code owner March 24, 2026 05:05
Copilot AI review requested due to automatic review settings March 24, 2026 05:05
@github-actions
Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

@github-actions github-actions bot added the unsafe Related to unsafe code label Mar 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds end-to-end UDP Segmentation Offload (USO) support to the virtio-net TX path by carrying USO metadata through net_backend, advertising/negotiating VIRTIO_NET_F_HOST_USO (bank 1) in virtio_net, and configuring the consomme UDP send path to use OS-supported UDP GSO mechanisms.

Changes:

  • Extend net_backend TX offload capabilities/metadata to represent USO (new support bit, TX flag, and per-packet segment size).
  • Update virtio_net to advertise HOST_USO in bank 1 and parse VirtioNetHeaderGsoProtocol::UDP_L4 into the new TX metadata; add/extend tests for USO and feature negotiation.
  • Update consomme UDP TX path to apply UDP GSO/segmentation using platform-specific helpers (Linux/macOS/Windows).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
vm/devices/virtio/virtio_net/src/tests.rs Adds USO-focused TX offload parsing tests and extends feature negotiation tests to validate HOST_USO in bank 1.
vm/devices/virtio/virtio_net/src/lib.rs Advertises bank-1 HOST_USO and parses UDP_L4 GSO into backend TX metadata/flags.
vm/devices/net/net_consomme/src/lib.rs Plumbs backend USO metadata into consomme::ChecksumState as gso.
vm/devices/net/net_consomme/consomme/src/windows.rs Implements Windows UDP GSO socket option configuration and a platform send_to wrapper.
vm/devices/net/net_consomme/consomme/src/unix.rs Implements Linux UDP_SEGMENT socket configuration and macOS sendmsg_x()-based batching send path.
vm/devices/net/net_consomme/consomme/src/udp.rs Tracks per-connection GSO size and applies platform UDP GSO configuration before sending.
vm/devices/net/net_consomme/consomme/src/lib.rs Extends send-path validation to tolerate IP length fields being inconsistent for TSO/USO super-packets.
vm/devices/net/net_backend/src/null.rs Marks the null endpoint as supporting USO.
vm/devices/net/net_backend/src/lib.rs Adds TxOffloadSupport::uso, TxFlags::offload_udp_segmentation, and TxMetadata::max_udp_segment_size.
vm/devices/net/gdma/src/bnic.rs Initializes the new TxMetadata::max_udp_segment_size field for GDMA TX metadata.

Daman Mulye and others added 3 commits March 24, 2026 21:14
Copilot AI review requested due to automatic review settings March 25, 2026 04:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

tcp: true,
udp: true,
tso: true,
uso: false,
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

There’s trailing whitespace after uso: false, here. Please run formatting (or remove the extra space) to keep diffs clean and avoid lint/format noise.

Suggested change
uso: false,
uso: false,

Copilot uses AI. Check for mistakes.
Daman Mulye added 2 commits March 25, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants