Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: sudo apt-get install -y --no-install-recommends build-essential patchelf pkg-config net-tools

- name: Install libkrunfw
run: curl -L -o /tmp/libkrunfw-4.9.0-x86_64.tgz https://github.com/containers/libkrunfw/releases/download/v4.9.0/libkrunfw-4.9.0-x86_64.tgz && mkdir tmp && tar xf /tmp/libkrunfw-4.9.0-x86_64.tgz -C tmp && sudo mv tmp/lib64/* /lib/x86_64-linux-gnu
run: curl -L -o /tmp/libkrunfw-5.0.0-x86_64.tgz https://github.com/containers/libkrunfw/releases/download/v5.0.0/libkrunfw-5.0.0-x86_64.tgz && mkdir tmp && tar xf /tmp/libkrunfw-5.0.0-x86_64.tgz -C tmp && sudo mv tmp/lib64/* /lib/x86_64-linux-gnu

- name: Integration tests
run: RUST_LOG=trace KRUN_ENOMEM_WORKAROUND=1 KRUN_NO_UNSHARE=1 make test
43 changes: 30 additions & 13 deletions src/devices/src/virtio/vsock/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ impl Vsock {
host_port_map: Option<HashMap<u16, u16>>,
queues: Vec<VirtQueue>,
unix_ipc_port_map: Option<HashMap<u32, (PathBuf, bool)>>,
enable_tsi: bool,
enable_tsi_unix: bool,
) -> super::Result<Vsock> {
let mut queue_events = Vec::new();
for _ in 0..queues.len() {
Expand All @@ -64,7 +66,13 @@ impl Vsock {

Ok(Vsock {
cid,
muxer: VsockMuxer::new(cid, host_port_map, unix_ipc_port_map),
muxer: VsockMuxer::new(
cid,
host_port_map,
unix_ipc_port_map,
enable_tsi,
enable_tsi_unix,
),
queue_rx,
queue_tx,
queues,
Expand All @@ -82,12 +90,21 @@ impl Vsock {
cid: u64,
host_port_map: Option<HashMap<u16, u16>>,
unix_ipc_port_map: Option<HashMap<u32, (PathBuf, bool)>>,
enable_tsi: bool,
enable_tsi_unix: bool,
) -> super::Result<Vsock> {
let queues: Vec<VirtQueue> = defs::QUEUE_SIZES
.iter()
.map(|&max_size| VirtQueue::new(max_size))
.collect();
Self::with_queues(cid, host_port_map, queues, unix_ipc_port_map)
Self::with_queues(
cid,
host_port_map,
queues,
unix_ipc_port_map,
enable_tsi,
enable_tsi_unix,
)
}

pub fn id(&self) -> &str {
Expand All @@ -102,7 +119,7 @@ impl Vsock {
/// have pending. Return `true` if descriptors have been added to the used ring, and `false`
/// otherwise.
pub fn process_stream_rx(&mut self) -> bool {
debug!("vsock: process_stream_rx()");
debug!("process_stream_rx()");
let mem = match self.device_state {
DeviceState::Activated(ref mem, _) => mem,
// This should never happen, it's been already validated in the event handler.
Expand All @@ -111,10 +128,10 @@ impl Vsock {

let mut have_used = false;

debug!("vsock: process_rx before while");
debug!("process_rx before while");
let mut queue_rx = self.queue_rx.lock().unwrap();
while let Some(head) = queue_rx.pop(mem) {
debug!("vsock: process_rx inside while");
debug!("process_rx inside while");
let used_len = match VsockPacket::from_rx_virtq_head(&head) {
Ok(mut pkt) => {
if self.muxer.recv_pkt(&mut pkt).is_ok() {
Expand All @@ -127,12 +144,12 @@ impl Vsock {
}
}
Err(e) => {
warn!("vsock: RX queue error: {e:?}");
warn!("RX queue error: {e:?}");
0
}
};

debug!("vsock: process_rx: something to queue");
debug!("process_rx: something to queue");
have_used = true;
if let Err(e) = queue_rx.add_used(mem, head.index, used_len) {
error!("failed to add used elements to the queue: {e:?}");
Expand All @@ -145,7 +162,7 @@ impl Vsock {
/// Walk the driver-provided TX queue buffers, package them up as vsock packets, and process
/// them. Return `true` if descriptors have been added to the used ring, and `false` otherwise.
pub fn process_stream_tx(&mut self) -> bool {
debug!("vsock::process_stream_tx()");
debug!("process_stream_tx()");
let mem = match self.device_state {
DeviceState::Activated(ref mem, _) => mem,
// This should never happen, it's been already validated in the event handler.
Expand All @@ -159,7 +176,7 @@ impl Vsock {
let pkt = match VsockPacket::from_tx_virtq_head(&head) {
Ok(pkt) => pkt,
Err(e) => {
error!("vsock: error reading TX packet: {e:?}");
error!("error reading TX packet: {e:?}");
have_used = true;
if let Err(e) = queue_tx.add_used(mem, head.index, 0) {
error!("failed to add used elements to the queue: {e:?}");
Expand All @@ -169,13 +186,13 @@ impl Vsock {
};

if pkt.type_() == uapi::VSOCK_TYPE_DGRAM {
debug!("vsock::process_stream_tx() is DGRAM");
debug!("process_stream_tx() is DGRAM");
if self.muxer.send_dgram_pkt(&pkt).is_err() {
queue_tx.undo_pop();
break;
}
} else {
debug!("vsock::process_stream_tx() is STREAM");
debug!("process_stream_tx() is STREAM");
if self.muxer.send_stream_pkt(&pkt).is_err() {
queue_tx.undo_pop();
break;
Expand Down Expand Up @@ -235,7 +252,7 @@ impl VirtioDevice for Vsock {
byte_order::write_le_u32(data, ((self.cid() >> 32) & 0xffff_ffff) as u32)
}
_ => warn!(
"vsock: virtio-vsock received invalid read request of {} bytes at offset {}",
"virtio-vsock received invalid read request of {} bytes at offset {}",
data.len(),
offset
),
Expand All @@ -244,7 +261,7 @@ impl VirtioDevice for Vsock {

fn write_config(&mut self, offset: u64, data: &[u8]) {
warn!(
"vsock: guest driver attempted to write device config (offset={:x}, len={:x})",
"guest driver attempted to write device config (offset={:x}, len={:x})",
offset,
data.len()
);
Expand Down
16 changes: 8 additions & 8 deletions src/devices/src/virtio/vsock/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use crate::virtio::VirtioDevice;

impl Vsock {
pub(crate) fn handle_rxq_event(&mut self, event: &EpollEvent) -> bool {
debug!("vsock: RX queue event");
debug!("RX queue event");

let event_set = event.event_set();
if event_set != EventSet::IN {
warn!("vsock: rxq unexpected event {event_set:?}");
warn!("rxq unexpected event {event_set:?}");
return false;
}

Expand All @@ -33,11 +33,11 @@ impl Vsock {
}

pub(crate) fn handle_txq_event(&mut self, event: &EpollEvent) -> bool {
debug!("vsock: TX queue event");
debug!("TX queue event");

let event_set = event.event_set();
if event_set != EventSet::IN {
warn!("vsock: txq unexpected event {event_set:?}");
warn!("txq unexpected event {event_set:?}");
return false;
}

Expand All @@ -57,11 +57,11 @@ impl Vsock {
}

fn handle_evq_event(&mut self, event: &EpollEvent) -> bool {
debug!("vsock: event queue event");
debug!("event queue event");

let event_set = event.event_set();
if event_set != EventSet::IN {
warn!("vsock: evq unexpected event {event_set:?}");
warn!("evq unexpected event {event_set:?}");
return false;
}

Expand All @@ -72,7 +72,7 @@ impl Vsock {
}

fn handle_activate_event(&self, event_manager: &mut EventManager) {
debug!("vsock: activate event");
debug!("activate event");
if let Err(e) = self.activate_evt.read() {
error!("Failed to consume vsock activate event: {e:?}");
}
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Subscriber for Vsock {
self.device_state.signal_used_queue();
}
} else {
warn!("Vsock: The device is not yet activated. Spurious event received: {source:?}");
warn!("The device is not yet activated. Spurious event received: {source:?}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/devices/src/virtio/vsock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ mod muxer_thread;
mod packet;
mod proxy;
mod reaper;
mod tcp;
#[cfg(target_os = "macos")]
mod timesync;
mod udp;
mod tsi_dgram;
mod tsi_stream;
mod unix;

pub use self::defs::uapi::VIRTIO_ID_VSOCK as TYPE_VSOCK;
Expand Down
Loading
Loading