diff options
author | Chuanxiao Dong <chuanxiao.dong@intel.com> | 2020-03-21 08:17:35 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-03-25 01:33:57 +0000 |
commit | 02f58e6d74bc1926424de43e9caec707f17c1b80 (patch) | |
tree | db1d075307584ed435e38d997191b293fc4b3d60 | |
parent | 928a8395e04425b72c4af272ffae7b97f252238a (diff) | |
download | crosvm-02f58e6d74bc1926424de43e9caec707f17c1b80.tar crosvm-02f58e6d74bc1926424de43e9caec707f17c1b80.tar.gz crosvm-02f58e6d74bc1926424de43e9caec707f17c1b80.tar.bz2 crosvm-02f58e6d74bc1926424de43e9caec707f17c1b80.tar.lz crosvm-02f58e6d74bc1926424de43e9caec707f17c1b80.tar.xz crosvm-02f58e6d74bc1926424de43e9caec707f17c1b80.tar.zst crosvm-02f58e6d74bc1926424de43e9caec707f17c1b80.zip |
vhost-net: add control socket basic support
Add a pair of control socket for vhost net. This pair can be used for the vhost-net device model to control and communicate with its activate thread. BUG=None TEST=cargo test -p devices Change-Id: I8bacdb9132787dc499ef00eea1df26ff3b35028d Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2046450 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
-rw-r--r-- | devices/src/virtio/vhost/control_socket.rs | 36 | ||||
-rw-r--r-- | devices/src/virtio/vhost/mod.rs | 2 | ||||
-rw-r--r-- | devices/src/virtio/vhost/net.rs | 15 |
3 files changed, 53 insertions, 0 deletions
diff --git a/devices/src/virtio/vhost/control_socket.rs b/devices/src/virtio/vhost/control_socket.rs new file mode 100644 index 0000000..a1ccfaf --- /dev/null +++ b/devices/src/virtio/vhost/control_socket.rs @@ -0,0 +1,36 @@ +// Copyright 2020 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +use msg_socket::{MsgOnSocket, MsgSocket}; +use sys_util::Error as SysError; + +#[derive(MsgOnSocket, Debug)] +pub enum VhostDevRequest { + /// Mask or unmask all the MSI entries for a Virtio Vhost device. + MsixChanged, + /// Mask or unmask a MSI entry for a Virtio Vhost device. + MsixEntryChanged(usize), +} + +#[derive(MsgOnSocket, Debug)] +pub enum VhostDevResponse { + Ok, + Err(SysError), +} + +pub type VhostDevRequestSocket = MsgSocket<VhostDevRequest, VhostDevResponse>; +pub type VhostDevResponseSocket = MsgSocket<VhostDevResponse, VhostDevRequest>; + +/// Create control socket pair. This pair is used to communicate with the +/// virtio device process. +/// Mainly between the virtio and activate thread. +pub fn create_control_sockets() -> ( + Option<VhostDevRequestSocket>, + Option<VhostDevResponseSocket>, +) { + match msg_socket::pair::<VhostDevRequest, VhostDevResponse>() { + Ok((request, response)) => (Some(request), Some(response)), + _ => (None, None), + } +} diff --git a/devices/src/virtio/vhost/mod.rs b/devices/src/virtio/vhost/mod.rs index 66c62d0..86ed81e 100644 --- a/devices/src/virtio/vhost/mod.rs +++ b/devices/src/virtio/vhost/mod.rs @@ -12,10 +12,12 @@ use remain::sorted; use sys_util::Error as SysError; use vhost::Error as VhostError; +mod control_socket; mod net; mod vsock; mod worker; +pub use self::control_socket::*; pub use self::net::Net; pub use self::vsock::Vsock; diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs index ff72970..21f1587 100644 --- a/devices/src/virtio/vhost/net.rs +++ b/devices/src/virtio/vhost/net.rs @@ -14,6 +14,7 @@ use sys_util::{error, warn, EventFd, GuestMemory}; use vhost::NetT as VhostNetT; use virtio_sys::virtio_net; +use super::control_socket::*; use super::worker::Worker; use super::{Error, Result}; use crate::virtio::{Interrupt, Queue, VirtioDevice, TYPE_NET}; @@ -31,6 +32,8 @@ pub struct Net<T: TapT, U: VhostNetT<T>> { vhost_interrupt: Option<Vec<EventFd>>, avail_features: u64, acked_features: u64, + request_socket: Option<VhostDevRequestSocket>, + response_socket: Option<VhostDevResponseSocket>, } impl<T, U> Net<T, U> @@ -85,6 +88,8 @@ where vhost_interrupt.push(EventFd::new().map_err(Error::VhostIrqCreate)?); } + let (request_socket, response_socket) = create_control_sockets(); + Ok(Net { workers_kill_evt: Some(kill_evt.try_clone().map_err(Error::CloneKillEventFd)?), kill_evt, @@ -94,6 +99,8 @@ where vhost_interrupt: Some(vhost_interrupt), avail_features, acked_features: 0u64, + request_socket, + response_socket, }) } } @@ -143,6 +150,14 @@ where } keep_fds.push(self.kill_evt.as_raw_fd()); + if let Some(request_socket) = &self.request_socket { + keep_fds.push(request_socket.as_raw_fd()); + } + + if let Some(response_socket) = &self.response_socket { + keep_fds.push(response_socket.as_raw_fd()); + } + keep_fds } |