Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions lib/propolis/src/hw/virtio/viona.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::io::{self, Error, ErrorKind};
use std::num::NonZeroU16;
use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::{Arc, Condvar, Mutex, Weak};
use std::sync::atomic::{Ordering, AtomicBool};
Copy link
Member

Choose a reason for hiding this comment

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

clippy is kind of obnoxiously mad about alphabetization here :|


use crate::common::{RWOp, ReadOp};
use crate::hw::pci;
Expand Down Expand Up @@ -308,6 +309,7 @@ pub struct PciVirtioViona {
mac_addr: [u8; ETHERADDRL],
mtu: Option<u16>,
hdl: VionaHdl,
mq_active: AtomicBool,
Copy link
Member

Choose a reason for hiding this comment

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

would like a comment on this explaining what it means and why it's tracked here?

Copy link
Member

Choose a reason for hiding this comment

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

i found the description of the suspected issue in #1048 and #1052 quite useful and felt like something like that (though not necessarily from the angle of "it was broken") would be nice to capture closer to the code.

inner: Mutex<Inner>,
}

Expand Down Expand Up @@ -396,6 +398,7 @@ impl PciVirtioViona {
dev_features,
mac_addr: [0; ETHERADDRL],
mtu: info.mtu,
mq_active: AtomicBool::new(false),
hdl,
inner: Mutex::new(Inner::new(nqueues)),
};
Expand Down Expand Up @@ -735,13 +738,21 @@ impl VirtioDevice for PciVirtioViona {

fn set_features(&self, feat: u64) -> Result<(), ()> {
self.hdl.set_features(feat).map_err(|_| ())?;
if (feat & VIRTIO_NET_F_MQ) != 0 {
self.hdl.set_pairs(PROPOLIS_MAX_MQ_PAIRS).map_err(|_| ())?;
probes::virtio_viona_mq_set_use_pairs!(|| (
MqSetPairsCause::MqEnabled as u8,
PROPOLIS_MAX_MQ_PAIRS
));
self.set_use_pairs(PROPOLIS_MAX_MQ_PAIRS)?;
let want_mq = feat & VIRTIO_NET_F_MQ != 0;

if want_mq {
// This might be the first we're hearing from the guest about
// wanting multi-queue. If it is, we'll have a bit of work to do.
let mq_active = self.mq_active.swap(true, Ordering::Relaxed);

if !mq_active {
self.hdl.set_pairs(PROPOLIS_MAX_MQ_PAIRS).map_err(|_| ())?;
probes::virtio_viona_mq_set_use_pairs!(|| (
MqSetPairsCause::MqEnabled as u8,
PROPOLIS_MAX_MQ_PAIRS
));
self.set_use_pairs(PROPOLIS_MAX_MQ_PAIRS)?;
}
}
Ok(())
}
Expand Down Expand Up @@ -838,6 +849,7 @@ impl Lifecycle for PciVirtioViona {
));
self.set_use_pairs(1).expect("can set viona back to one queue pair");
self.hdl.set_pairs(1).expect("can set viona back to one queue pair");
self.mq_active.store(false, Ordering::Relaxed);
self.virtio_state.queues.reset_peak();
}
fn start(&self) -> anyhow::Result<()> {
Expand Down
Loading