From 83a79373341d11400709e1830610b4d3fa46232a Mon Sep 17 00:00:00 2001 From: Anmin Liu Date: Sat, 30 Mar 2024 02:09:50 +0000 Subject: [PATCH] Make vsock device optional --- Makefile | 10 ++++++++ .../comps/virtio/src/device/socket/manager.rs | 25 +------------------ 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 4e049cea8..09d0b757f 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,16 @@ ifeq ($(ENABLE_KVM), 1) CARGO_OSDK_ARGS += --qemu-args="--enable-kvm" endif +ifeq ($(VSOCK),1) +ifeq ($(QEMU_MACHINE), microvm) +CARGO_OSDK_ARGS += --qumu.args="-device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3" +else ifeq ($(EMULATE_IOMMU), 1) +CARGO_OSDK_ARGS += --qemu.args="-device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3,disable-legacy=on,disable-modern=off,iommu_platform=on,ats=on" +else +CARGO_OSDK_ARGS += --qemu.args="-device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3,disable-legacy=on,disable-modern=off" +endif +endif + # Pass make variables to all subdirectory makes export diff --git a/kernel/comps/virtio/src/device/socket/manager.rs b/kernel/comps/virtio/src/device/socket/manager.rs index 30d6ee0ab..a4a58bf23 100644 --- a/kernel/comps/virtio/src/device/socket/manager.rs +++ b/kernel/comps/virtio/src/device/socket/manager.rs @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MPL-2.0 + use alloc::{boxed::Box, sync::Arc, vec, vec::Vec}; use core::{cmp::min, hint::spin_loop}; @@ -14,30 +15,6 @@ use crate::device::socket::error::SocketError; const PER_CONNECTION_BUFFER_CAPACITY: usize = 1024; -/// TODO: A higher level interface for VirtIO socket (vsock) devices. -/// -/// This keeps track of multiple vsock connections. -/// -/// # Example -/// -/// ``` -/// -/// let mut socket = VsockConnectionManager::new(SocketDevice); -/// -/// // Start a thread to call `socket.poll()` and handle events. -/// -/// let remote_address = VsockAddr { cid: 2, port: 4321 }; -/// let local_port = 1234; -/// socket.connect(remote_address, local_port)?; -/// -/// // Wait until `socket.poll()` returns an event indicating that the socket is connected. -/// -/// socket.send(remote_address, local_port, "Hello world".as_bytes())?; -/// -/// socket.shutdown(remote_address, local_port)?; -/// # Ok(()) -/// # } -/// `` pub struct VsockConnectionManager { driver: Arc>, connections: Vec,