virtio_net: enable checksum and GSO offloads#2968
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds virtio-net TX/RX offload support by advertising checksum/TSO features based on backend capabilities, translating virtio-net header offload fields into net_backend::TxMetadata, and setting VIRTIO_NET_HDR_F_DATA_VALID on RX when the backend reports validated checksums.
Changes:
- Advertise
VIRTIO_NET_F_CSUMandVIRTIO_NET_F_HOST_TSO4/6based onEndpoint::tx_offload_support(). - Parse virtio-net TX header + Ethernet prefix to set
TxMetadataoffload flags and header-length fields. - Set RX
data_validflag when backend checksum states are validated; add/extend unit and integration-style tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| vm/devices/virtio/virtio_net/src/lib.rs | Adds feature advertisement and TX offload parsing to populate TxMetadata for the backend. |
| vm/devices/virtio/virtio_net/src/buffers.rs | Sets RX virtio-net header DATA_VALID flag based on backend checksum validity. |
| vm/devices/virtio/virtio_net/src/tests.rs | Adds TX offload parsing tests, RX data_valid tests, and feature negotiation tests. |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Adds virtio-net TX/RX offload plumbing so the device can advertise and translate virtio-net checksum/GSO fields into backend TxMetadata/RX header flags, with accompanying tests.
Changes:
- Advertise virtio-net offload-related feature bits based on backend
TxOffloadSupport. - Parse virtio-net TX header fields (csum/GSO) and map them into
net_backend::TxMetadataoffload flags and header lengths. - Set
VIRTIO_NET_HDR_F_DATA_VALIDon RX when backend checksum state is reported as valid; add unit/integration tests for offload behaviors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| vm/devices/virtio/virtio_net/src/lib.rs | Offload feature advertisement + TX header peeking/parsing into TxMetadata. |
| vm/devices/virtio/virtio_net/src/buffers.rs | Map RX checksum validity into virtio-net header data_valid flag. |
| vm/devices/virtio/virtio_net/src/tests.rs | Add TX offload parsing tests, RX data_valid tests, and feature negotiation tests. |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Adds virtio-net TX/RX offload plumbing (checksum + TCP segmentation) and corresponding test coverage, integrating backend offload capabilities into virtio feature advertisement and per-packet metadata.
Changes:
- Advertise virtio-net checksum/TSO features based on
Endpoint::tx_offload_support()and propagate parsed offload metadata intoTxMetadata. - Parse virtio-net TX headers + Ethernet EtherType/VLAN prefix to derive
TxFlagsand header lengths for checksum/GSO offloads. - Set RX
VIRTIO_NET_HDR_F_DATA_VALIDbased on backend-reported checksum validity, with new unit/integration tests.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/virtio/virtio_net/src/lib.rs | Feature negotiation + TX header parsing to generate backend offload metadata. |
| vm/devices/virtio/virtio_net/src/buffers.rs | Map RX checksum validation state to virtio-net header data_valid flag. |
| vm/devices/virtio/virtio_net/src/tests.rs | Adds parsing/unit tests, RX data_valid tests, and feature negotiation tests. |
| vm/devices/virtio/virtio_net/Cargo.toml | Adds tracelimit dependency for rate-limited logging. |
| Cargo.lock | Records the new tracelimit dependency usage. |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Adds virtio-net TX/RX offload support (checksum + TSO/GSO) to improve networking performance while hardening malformed-guest handling.
Changes:
- Advertise virtio-net offload features based on backend
TxOffloadSupportand store negotiated features in the worker. - Parse virtio-net TX headers to populate
TxMetadataoffload flags/lengths; mark malformed TX packets as dropped (non-fatal) with ratelimited logging + new counter. - Set RX
VIRTIO_NET_HDR_F_DATA_VALIDbased on backend checksum validation state; add extensive unit + integration-style tests.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/virtio/virtio_net/src/lib.rs | Feature advertisement, negotiated-feature plumbing, TX packet hardening + offload parsing, tx_dropped counter |
| vm/devices/virtio/virtio_net/src/buffers.rs | Sets RX data_valid header flag based on checksum validity |
| vm/devices/virtio/virtio_net/src/tests.rs | Adds offload parsing tests, RX data_valid tests, and feature negotiation tests; extends harness utilities |
| vm/devices/virtio/virtio_net/Cargo.toml | Adds tracelimit dependency for ratelimited TX-drop logging |
| Cargo.lock | Locks tracelimit dependency |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Adds virtio-net TX/RX offload support by negotiating and translating virtio-net header offload fields into backend TxMetadata, and by reflecting backend RX checksum validity back to the guest via VIRTIO_NET_HDR_F_DATA_VALID.
Changes:
- Advertise checksum/TSO-related virtio-net features based on endpoint
TxOffloadSupport, and gate TX offload parsing on negotiated features. - Harden TX/RX queue handling by dropping malformed/duplicate guest submissions non-fatally with rate-limited logging and new drop counters.
- Extend unit and end-to-end tests to cover TX offload parsing, RX
data_valid, duplicate descriptor handling, and feature negotiation.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/virtio/virtio_net/src/lib.rs | Feature advertisement, negotiated-feature plumbing into workers, TX offload parsing, and non-fatal drop handling with counters/logging. |
| vm/devices/virtio/virtio_net/src/buffers.rs | Map backend RX checksum states to virtio-net header DATA_VALID; handle duplicate RX descriptor submissions without panicking. |
| vm/devices/virtio/virtio_net/src/tests.rs | Add comprehensive TX offload parsing tests, RX data_valid tests, duplicate TX descriptor test, and feature negotiation tests. |
| vm/devices/virtio/virtio_net/Cargo.toml | Add tracelimit dependency for rate-limited guest-triggerable warnings. |
| Cargo.lock | Record the new tracelimit dependency in the lockfile. |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
This PR adds virtio-net TX/RX offload support, translating virtio-net header offload fields into backend TxMetadata (checksum + TSO) and reporting RX checksum validation back to the guest via VIRTIO_NET_HDR_F_DATA_VALID.
Changes:
- Advertise virtio-net offload feature bits based on backend
TxOffloadSupport, and store negotiated features in each worker for per-packet gating. - Implement TX offload parsing (CSUM + TSO4/TSO6) with validation + non-fatal drop behavior and new dropped counters/logging.
- Set RX
data_validbased on backend checksum states; extend tests to cover offload parsing, end-to-end TX metadata, RXdata_valid, and feature negotiation.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/virtio/virtio_net/src/lib.rs | Advertises offload features, stores negotiated features in workers, parses TX offloads, and hardens TX/RX queueing with drop handling + counters. |
| vm/devices/virtio/virtio_net/src/buffers.rs | Makes RX buffer queueing detect duplicates and sets RX data_valid header flag based on checksum validity. |
| vm/devices/virtio/virtio_net/src/tests.rs | Adds unit + integration tests covering TX offload parsing, end-to-end TX metadata, RX data_valid, and feature advertisement. |
| vm/devices/virtio/virtio_net/Cargo.toml | Adds tracelimit dependency for rate-limited drop logging. |
| Cargo.lock | Records the new tracelimit dependency usage. |
You can also share your feedback on Copilot code review. Take the survey.
| if l3_len > 0 && l4_len > 0 { | ||
| flags.set_offload_tcp_segmentation(true); | ||
| flags.set_offload_tcp_checksum(true); | ||
| max_tcp_segment_size = header.gso_size; | ||
|
|
||
| flags.set_is_ipv4(is_ipv4_from_gso); | ||
| flags.set_is_ipv6(is_ipv6_from_gso); | ||
| if is_ipv4_from_gso { |
366d80b to
9571fde
Compare
There was a problem hiding this comment.
Pull request overview
Adds virtio-net TX/RX offload support by translating virtio-net header offload fields into backend TxMetadata flags and by propagating backend RX checksum validity to the guest via VIRTIO_NET_HDR_F_DATA_VALID. The PR also hardens queue handling against malformed/duplicate guest submissions and expands test coverage around offload parsing and feature negotiation.
Changes:
- Advertise virtio-net checksum/TSO features based on backend
TxOffloadSupport, and gate offload parsing on negotiated features. - Implement TX offload parsing (CSUM + TSO4/TSO6) and RX
DATA_VALIDsignaling; make malformed/duplicate packets non-fatal and counted as dropped. - Add unit + end-to-end tests for TX offloads, RX
data_valid, duplicate descriptor handling, and feature negotiation.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
vm/devices/virtio/virtio_net/src/lib.rs |
Advertises offload features, adds negotiated-feature gating, TX offload parsing, and drop-on-error hardening with new counters/logging. |
vm/devices/virtio/virtio_net/src/buffers.rs |
Handles duplicate RX descriptor submissions without panicking and sets DATA_VALID based on checksum validity. |
vm/devices/virtio/virtio_net/src/tests.rs |
Extends mock logging to capture TX metadata; adds extensive TX/RX offload and negotiation tests. |
vm/devices/virtio/virtio_net/Cargo.toml |
Adds tracelimit dependency for rate-limited drop logging. |
Cargo.lock |
Locks the added tracelimit dependency. |
You can also share your feedback on Copilot code review. Take the survey.
Add TX and RX offload support to the virtio-net device.
TX path:
RX path:
Hardening:
tx_droppedcounter — the worker continues processing.try_queue_tx_packet(returnsResult) andqueue_tx_packet(handles cleanup structurally: truncate segments, complete descriptor, increment counter).Tests: