From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.5 Received: by atuin.qyliss.net (Postfix, from userid 496) id 59C353623; Thu, 13 May 2021 00:50:58 +0000 (UTC) Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 932623591; Thu, 13 May 2021 00:50:23 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 3FA7E143AA; Wed, 12 May 2021 17:08:49 +0000 (UTC) Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by atuin.qyliss.net (Postfix) with ESMTPS id 239701435D for ; Wed, 12 May 2021 17:08:42 +0000 (UTC) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B364F1348 for ; Wed, 12 May 2021 13:08:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 12 May 2021 13:08:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=cFT8NI5gLwb9B uifu3DyYABzplB7ECmN+jSEiA8w6FI=; b=JhR/xfQ2tY3wH9eH2iaVSqdTcN+QU uhbLVW2gZX6YcMyOyjh0qFAyZTeupAnV2dAqOkkhe6bs92AOO4NNFg8RJ5yu3nbh umMn+jhM6Q2sMXG2DSyCdfdhWipLryyzngQNpqAHt+K5LuZdKXC3G2yZGek/tocT t0WjjKl3e4cvoIw0Nf9gmxCwTIGkVUZrGb10iMlpmsgXuo403oGqwC7Nd8Jp3XqA ro+N3r4vdRS0Fc+whsaOcH+dLlaP1ReRPKrYpRhuOqoGdYa97yS4QbVz7NfSIcGq PDfAzuIDG9tX3L+7AbiN2bovwRVDBNN5JN/3+NK5+z8ZtOQqvQ5neam7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=cFT8NI5gLwb9Buifu3DyYABzplB7ECmN+jSEiA8w6FI=; b=nZ9+YNux T3wRqEuW4iJe6L/wBVBqEj2UJ1mkmTnvcGPQ4q+mZWglWuy3FK32HHebMG1kCauD T4zZB79Exjrpn9aKj3dRAbNrdLPVJkWB+mdJe6ZwH6yYMBYLD4cxcniXQ1vt+W+g lYC53V1SQ2582ooRKx7tFO/09t0emy8pPkJvZG62CK/mnqzz71PZ7Q3ICld4AiTI zTIKQ7xtb3A8f/Hd2PuSJhc9M7y13DTEY9ZHHOGqSWc1ttYvYf6DPXRO+5R4YnbI 3xhC5e1dV9cFU7lhblOJ2TaoCAqddS8mGVk4HBloB57sgCwXhgzho9xgd/6i3bl5 om57izNeLDmC6w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdehvddguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpeetlhihshhsrgcutfhoshhsuceohhhisegrlhihshhsrgdr ihhsqeenucggtffrrghtthgvrhhnpeevueejtefgieeuhffgheejteetleehveduvedutd ffveelvedtteegkeejiefgteenucffohhmrghinhepnhgvthhmrghskhdrihhsnecukfhp peekgedrudekgedrvddviedrkedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepqhihlhhishhssegvvhgvrdhqhihlihhsshdrnhgvth X-ME-Proxy: Received: from eve.qyliss.net (p54b8e251.dip0.t-ipconnect.de [84.184.226.81]) by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 12 May 2021 13:08:37 -0400 (EDT) Received: by eve.qyliss.net (Postfix, from userid 1000) id 477F51143; Wed, 12 May 2021 17:08:36 +0000 (UTC) From: Alyssa Ross To: devel@spectrum-os.org Subject: [RFC PATCH 4/4] crosvm: use vhost-user-net instead of virtio-net Date: Wed, 12 May 2021 17:08:12 +0000 Message-Id: <20210512170812.192540-5-hi@alyssa.is> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210512170812.192540-1-hi@alyssa.is> References: <20210512170812.192540-1-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: FBSGPFYRMSDEONLTNFCMIYAMESLNOKOW X-Message-ID-Hash: FBSGPFYRMSDEONLTNFCMIYAMESLNOKOW X-MailFrom: qyliss@eve.qyliss.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.4 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This is a hack that just assumes vhost-user-net is desired if a MAC address is given, but not a host IP or netmask. No sandbox is created for this device. It'll do for a proof of concept. --- src/linux.rs | 32 ++++++++++++++++++++++++++++---- src/main.rs | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/linux.rs b/src/linux.rs index 31b9d325..3b040a87 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -507,6 +507,28 @@ fn create_balloon_device(cfg: &Config, socket: BalloonControlResponseSocket) -> }) } +fn create_vhost_user_net_device(mac_address: MacAddress) -> DeviceResult { + use virtio::vhost_user::cloud_hypervisor::net_util::MacAddr; + use virtio::vhost_user::{self, VhostUserConfig}; + + let xdg_runtime_dir = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR is not set"); + + let dev = vhost_user::Net::new( + MacAddr::from_bytes(&mac_address.octets()).unwrap(), + VhostUserConfig { + sock: &format!("{}/vhost-user0.sock", xdg_runtime_dir), + num_queues: 2, + queue_size: 256, + }, + ) + .expect("vhost_user::Net::new"); + + Ok(VirtioDeviceStub { + dev: Box::new(dev), + jail: None, + }) +} + fn create_tap_net_device(cfg: &Config, tap_fd: RawFd) -> DeviceResult { // Safe because we ensure that we get a unique handle to the fd. let tap = unsafe { @@ -872,10 +894,12 @@ fn create_virtio_devices( devs.push(create_tap_net_device(cfg, *tap_fd)?); } - if let (Some(host_ip), Some(netmask), Some(mac_address)) = - (cfg.host_ip, cfg.netmask, cfg.mac_address) - { - devs.push(create_net_device(cfg, host_ip, netmask, mac_address, mem)?); + if let Some(mac_address) = cfg.mac_address { + if let (Some(host_ip), Some(netmask)) = (cfg.host_ip, cfg.netmask) { + devs.push(create_net_device(cfg, host_ip, netmask, mac_address, mem)?); + } else { + devs.push(create_vhost_user_net_device(mac_address)?); + } } #[cfg_attr(not(feature = "gpu"), allow(unused_mut))] diff --git a/src/main.rs b/src/main.rs index a864833c..d19def4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -803,7 +803,7 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> { if cfg.executable_path.is_none() { return Err(argument::Error::ExpectedArgument("`KERNEL`".to_owned())); } - if cfg.host_ip.is_some() || cfg.netmask.is_some() || cfg.mac_address.is_some() { + if cfg.host_ip.is_some() || cfg.netmask.is_some() { if cfg.host_ip.is_none() { return Err(argument::Error::ExpectedArgument( "`host_ip` missing from network config".to_owned(), -- 2.31.0