Skip to content
Merged
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: 2 additions & 0 deletions lib/propolis/src/hw/virtio/vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::vmm::MemCtx;
use crate::vsock::packet::VsockPacket;
use crate::vsock::packet::VsockPacketError;
use crate::vsock::packet::VsockPacketHeader;
use crate::vsock::probes;
use crate::vsock::proxy::VsockPortMapping;
use crate::vsock::GuestCid;
use crate::vsock::VsockBackend;
Expand Down Expand Up @@ -84,6 +85,7 @@ impl RxPermit<'_> {
});
}

probes::vsock_pkt_rx!(|| header);
queue.push_used(&mut chain, &mem);
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/propolis/src/vsock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ pub enum VsockError {
pub trait VsockBackend: Send + Sync + 'static {
fn queue_notify(&self, queue_id: u16) -> Result<(), VsockError>;
}

#[usdt::provider(provider = "propolis")]
mod probes {
use crate::vsock::packet::VsockPacketHeader;

/// Host->Guest
fn vsock_pkt_rx(hdr: &VsockPacketHeader) {}
/// Guest->Host
fn vsock_pkt_tx(hdr: &VsockPacketHeader) {}
}
29 changes: 26 additions & 3 deletions lib/propolis/src/vsock/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use serde::{Serialize, Serializer};
use strum::FromRepr;
use zerocopy::byteorder::little_endian::{U16, U32, U64};
use zerocopy::{FromBytes, Immutable, IntoBytes};
Expand All @@ -11,15 +12,15 @@ use crate::vsock::{GuestCid, VSOCK_HOST_CID};

bitflags! {
/// Shutdown flags for VIRTIO_VSOCK_OP_SHUTDOWN
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
#[repr(transparent)]
pub struct VsockPacketFlags: u32 {
const VIRTIO_VSOCK_SHUTDOWN_F_RECEIVE = 1 << 0;
const VIRTIO_VSOCK_SHUTDOWN_F_SEND = 1 << 1;
}
}

#[derive(Debug, Clone, Copy, FromRepr, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, FromRepr, PartialEq, Eq, Serialize)]
#[repr(u16)]
pub enum VsockSocketType {
Stream = 1,
Expand Down Expand Up @@ -52,7 +53,7 @@ pub enum VsockPacketError {
InvalidDstCid { dst_cid: u64 },
}

#[derive(Clone, Copy, Debug, FromRepr, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, FromRepr, Eq, PartialEq, Serialize)]
#[repr(u16)]
pub enum VsockPacketOp {
Request = 1,
Expand Down Expand Up @@ -90,6 +91,28 @@ pub struct VsockPacketHeader {
fwd_cnt: U32,
}

// NB: This implementation is here to support dtrace usdt probes.
impl Serialize for VsockPacketHeader {
fn serialize<S: Serializer>(
&self,
serializer: S,
) -> Result<S::Ok, S::Error> {
use serde::ser::SerializeStruct;
let mut s = serializer.serialize_struct("VsockPacketHeader", 10)?;
s.serialize_field("src_cid", &self.src_cid.get())?;
s.serialize_field("dst_cid", &self.dst_cid.get())?;
s.serialize_field("src_port", &self.src_port.get())?;
s.serialize_field("dst_port", &self.dst_port.get())?;
s.serialize_field("len", &self.len.get())?;
s.serialize_field("socket_type", &self.socket_type())?;
s.serialize_field("op", &self.op())?;
s.serialize_field("flags", &self.flags())?;
s.serialize_field("buf_alloc", &self.buf_alloc.get())?;
s.serialize_field("fwd_cnt", &self.fwd_cnt.get())?;
s.end()
}
}

impl VsockPacketHeader {
pub fn src_cid(&self) -> u64 {
self.src_cid.get()
Expand Down
2 changes: 2 additions & 0 deletions lib/propolis/src/vsock/poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::hw::virtio::vsock::VSOCK_TX_QUEUE;
use crate::vsock::packet::VsockPacket;
use crate::vsock::packet::VsockPacketFlags;
use crate::vsock::packet::VsockSocketType;
use crate::vsock::probes;
use crate::vsock::proxy::ConnKey;
use crate::vsock::proxy::VsockPortMapping;
use crate::vsock::proxy::VsockProxyConn;
Expand Down Expand Up @@ -302,6 +303,7 @@ impl VsockPoller {
}
};

probes::vsock_pkt_tx!(|| &packet.header);
// If the packet is not destined for the host drop it.
if packet.header.dst_cid() != VSOCK_HOST_CID {
warn!(
Expand Down
Loading