Skip to content

Commit 80d7cc6

Browse files
authored
Merge pull request #1795 from cagatay-y/mrgbuf-test
Test MRG_RXBUF
2 parents 85b8266 + fae159a commit 80d7cc6

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ jobs:
249249
working-directory: .
250250
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package httpd --features ci,hermit/dhcpv4,hermit/virtio-net qemu ${{ matrix.flags }} --devices virtio-net-pci
251251
if: matrix.arch != 'riscv64'
252+
# FIXME: this is broken on QEMU 8.2.2
253+
# Enable this once CI reaches QEMU 8.2.3 or QEMU 9.0.0
254+
# - run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package httpd --features ci,hermit/dhcpv4,hermit/virtio-net qemu ${{ matrix.flags }} --devices virtio-net-pci
255+
# if: matrix.arch != 'riscv64'
256+
# env:
257+
# # The buffer is sized to be smaller than the packets received during DHCPv4 address acquisition and thus exercise the buffer merging code path.
258+
# HERMIT_MRG_RXBUF_SIZE: 200
252259
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package httpd --features ci,hermit/virtio-net qemu --sudo --devices virtio-net-pci --tap
253260
if: matrix.arch != 'riscv64'
254261
- run: cargo xtask ci rs --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} --package httpd --features ci,hermit/dhcpv4,hermit/virtio-net qemu ${{ matrix.flags }} --devices virtio-net-pci --no-default-virtio-features

src/drivers/net/virtio/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cfg_if::cfg_if! {
1313
use alloc::boxed::Box;
1414
use alloc::vec::Vec;
1515
use core::mem::{ManuallyDrop, MaybeUninit, transmute};
16+
use core::str::FromStr;
1617

1718
use smallvec::SmallVec;
1819
use smoltcp::phy::{Checksum, ChecksumCapabilities, DeviceCapabilities};
@@ -59,15 +60,24 @@ fn determine_mtu(dev_cfg: &NetDevCfg) -> u16 {
5960
}
6061
}
6162

62-
fn determine_buf_size(dev_cfg: &NetDevCfg) -> u32 {
63+
fn determine_rx_buf_size(dev_cfg: &NetDevCfg) -> u32 {
6364
// See Virtio specification v1.1 - 5.1.6.3.1 and 5.1.4.2
6465

6566
// Our desired minimum buffer size - we want it to be at least the MTU generally
6667
let mut min_buf_size = determine_mtu(dev_cfg).into();
6768

6869
// If VIRTIO_NET_F_MRG_RXBUF is negotiated, each buffer MUST be at least the size of the struct virtio_net_hdr.
6970
// We just use MTU in that case, but otherwise...
70-
if !dev_cfg.features.contains(virtio::net::F::MRG_RXBUF) {
71+
if dev_cfg.features.contains(virtio::net::F::MRG_RXBUF)
72+
&& let Some(my_mrg_rxbuf_size) = hermit_var!("HERMIT_MRG_RXBUF_SIZE")
73+
{
74+
let my_mrg_rxbuf_size = u32::from_str(&my_mrg_rxbuf_size).unwrap();
75+
assert!(
76+
my_mrg_rxbuf_size > 0,
77+
"VIRTIO does not allow buffer elements of size 0."
78+
);
79+
min_buf_size = my_mrg_rxbuf_size;
80+
} else {
7181
// If [...] are negotiated, the driver SHOULD populate the receive queue(s) with buffers of at least 65562 bytes.
7282
if dev_cfg.features.contains(virtio::net::F::GUEST_TSO4)
7383
|| dev_cfg.features.contains(virtio::net::F::GUEST_TSO6)
@@ -92,7 +102,7 @@ impl RxQueues {
92102
pub fn new(vqs: Vec<VirtQueue>, dev_cfg: &NetDevCfg) -> Self {
93103
Self {
94104
vqs,
95-
buf_size: determine_buf_size(dev_cfg),
105+
buf_size: determine_rx_buf_size(dev_cfg),
96106
}
97107
}
98108

@@ -167,7 +177,7 @@ impl TxQueues {
167177
pub fn new(vqs: Vec<VirtQueue>, dev_cfg: &NetDevCfg) -> Self {
168178
Self {
169179
vqs,
170-
buf_size: determine_buf_size(dev_cfg),
180+
buf_size: determine_mtu(dev_cfg).into(),
171181
}
172182
}
173183

0 commit comments

Comments
 (0)