From d723090d2511914fb870031b6f1ad7be3d7a1b9e Mon Sep 17 00:00:00 2001 From: Hanna Czenczek Date: Wed, 12 Nov 2025 12:59:10 +0100 Subject: [PATCH 1/3] vhost: Fix unused_assignments warning This test changes flags and bits to make the object invalid, and checks that `is_valid()` catches it. It always reverts that change after every test. As a result, there is an assignment at the end to make the object valid again, with no check remaining afterwards. For me, the compiler complains about that, so add a final assertion to make it happy. Signed-off-by: Hanna Czenczek --- vhost/src/vhost_user/message.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vhost/src/vhost_user/message.rs b/vhost/src/vhost_user/message.rs index 88dbcaf0..d6dc2942 100644 --- a/vhost/src/vhost_user/message.rs +++ b/vhost/src/vhost_user/message.rs @@ -1478,6 +1478,8 @@ mod tests { msg.flags |= 0x80000000; assert!(!msg.is_valid()); msg.flags &= !0x80000000; + + assert!(msg.is_valid()); } #[test] From 88d31a3c1d44ffa50ea7555032ea3b6cc8ed7a4b Mon Sep 17 00:00:00 2001 From: Hanna Czenczek Date: Fri, 15 Aug 2025 15:35:27 +0200 Subject: [PATCH 2/3] vhost_kern: Explicitly require physical GuestMemory vhost_kern requires physical `GuestMemory` (uses `.get_host_address()`), so we have to restrict its `GuestAddressSpace` requirement to physical memory only. In this patch, that is not actually a restriction, but with vm-memory 0.18, there is going to be a difference between physical and potentially non-physical memory (`GuestMemoryBackend` vs. `GuestMemory`). Signed-off-by: Hanna Czenczek --- vhost/src/vhost_kern/mod.rs | 10 ++++++++-- vhost/src/vhost_kern/net.rs | 5 +++-- vhost/src/vhost_kern/vdpa.rs | 6 ++++-- vhost/src/vhost_kern/vsock.rs | 5 +++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/vhost/src/vhost_kern/mod.rs b/vhost/src/vhost_kern/mod.rs index a1f404f6..a33c71e3 100644 --- a/vhost/src/vhost_kern/mod.rs +++ b/vhost/src/vhost_kern/mod.rs @@ -36,6 +36,12 @@ pub mod vdpa; #[cfg(feature = "vhost-vsock")] pub mod vsock; +/// Helper trait to signify `GuestAddressSpace`s that are physical, which is required for +/// vhost_kern. +pub trait PhysicalGuestAddressSpace: GuestAddressSpace {} + +impl PhysicalGuestAddressSpace for AS where AS::M: GuestMemory {} + #[inline] fn ioctl_result(rc: i32, res: T) -> Result { if rc < 0 { @@ -57,7 +63,7 @@ fn io_result(rc: isize, res: T) -> Result { /// Represent an in-kernel vhost device backend. pub trait VhostKernBackend: AsRawFd { /// Associated type to access guest memory. - type AS: GuestAddressSpace; + type AS: PhysicalGuestAddressSpace; /// Get the object to access the guest's memory. fn mem(&self) -> &Self::AS; @@ -439,7 +445,7 @@ impl VhostIotlbMsgParser for vhost_msg_v2 { impl VringConfigData { /// Convert the config (guest address space) into vhost_vring_addr /// (host address space). - pub fn to_vhost_vring_addr( + pub fn to_vhost_vring_addr( &self, queue_index: usize, mem: &AS, diff --git a/vhost/src/vhost_kern/net.rs b/vhost/src/vhost_kern/net.rs index 89f390ca..58d70d99 100644 --- a/vhost/src/vhost_kern/net.rs +++ b/vhost/src/vhost_kern/net.rs @@ -7,11 +7,12 @@ use std::fs::{File, OpenOptions}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::{AsRawFd, RawFd}; -use vm_memory::GuestAddressSpace; use vmm_sys_util::ioctl::ioctl_with_ref; use super::vhost_binding::*; -use super::{ioctl_result, Error, Result, VhostKernBackend}; +use super::{ + ioctl_result, Error, PhysicalGuestAddressSpace as GuestAddressSpace, Result, VhostKernBackend, +}; use crate::net::*; diff --git a/vhost/src/vhost_kern/vdpa.rs b/vhost/src/vhost_kern/vdpa.rs index 3e4f1dff..92ad2cdd 100644 --- a/vhost/src/vhost_kern/vdpa.rs +++ b/vhost/src/vhost_kern/vdpa.rs @@ -9,13 +9,15 @@ use std::os::raw::{c_uchar, c_uint}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::{AsRawFd, RawFd}; -use vm_memory::GuestAddressSpace; use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::fam::*; use vmm_sys_util::ioctl::{ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref}; use super::vhost_binding::*; -use super::{ioctl_result, Error, Result, VhostKernBackend, VhostKernFeatures}; +use super::{ + ioctl_result, Error, PhysicalGuestAddressSpace as GuestAddressSpace, Result, VhostKernBackend, + VhostKernFeatures, +}; use crate::vdpa::*; use crate::{VhostAccess, VhostIotlbBackend, VhostIotlbMsg, VhostIotlbType, VringConfigData}; diff --git a/vhost/src/vhost_kern/vsock.rs b/vhost/src/vhost_kern/vsock.rs index f3474919..76a718aa 100644 --- a/vhost/src/vhost_kern/vsock.rs +++ b/vhost/src/vhost_kern/vsock.rs @@ -11,11 +11,12 @@ use std::fs::{File, OpenOptions}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::{AsRawFd, RawFd}; -use vm_memory::GuestAddressSpace; use vmm_sys_util::ioctl::ioctl_with_ref; use super::vhost_binding::{VHOST_VSOCK_SET_GUEST_CID, VHOST_VSOCK_SET_RUNNING}; -use super::{ioctl_result, Error, Result, VhostKernBackend}; +use super::{ + ioctl_result, Error, PhysicalGuestAddressSpace as GuestAddressSpace, Result, VhostKernBackend, +}; use crate::vsock::VhostVsock; const VHOST_PATH: &str = "/dev/vhost-vsock"; From bf6da463b862027b3a4372c3b68f90f9770f3db6 Mon Sep 17 00:00:00 2001 From: Hanna Czenczek Date: Mon, 14 Jul 2025 14:42:40 +0200 Subject: [PATCH 3/3] [DRAFT] Update to IOMMU-supporting dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update our vm-memory and vm-virtio dependencies to a version with IOMMU (i.e. non-physical `GuestMemory` and `IommuMemory`) support. In some places, that means we need to import `GuestMemoryBackend` now to retain access to that trait’s methods. (`GuestMemoryBackend` is what used to be `GuestMemory`.) For vhost_kern, it means we need to have `PhysicalGuestAddressSpace` require `GuestMemoryBackend` instead of `GuestMemory` because, as explained in HEAD^, it strictly requires physical memory, and that is what `GuestMemoryBackend` is. (Marked as a draft until all of the updated dependencies have had proper releases and this commit just bumps their version number instead of pointing to non-released commits.) Signed-off-by: Hanna Czenczek --- Cargo.toml | 6 +++++- vhost-user-backend/CHANGELOG.md | 2 ++ vhost-user-backend/src/handler.rs | 4 +++- vhost-user-backend/tests/vhost-user-server.rs | 3 ++- vhost/CHANGELOG.md | 2 ++ vhost/src/vhost_kern/mod.rs | 6 +++--- vhost/src/vhost_kern/net.rs | 2 +- vhost/src/vhost_kern/vdpa.rs | 2 +- vhost/src/vhost_kern/vsock.rs | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4dd58935..140f241d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,9 @@ members = [ [workspace.dependencies] virtio-bindings = "0.2.6" virtio-queue = "0.17.0" -vm-memory = "=0.17.1" +vm-memory = "0.18.0" vmm-sys-util = "0.15.0" + +[patch.crates-io] +virtio-bindings = { git = "https://github.com/rust-vmm/vm-virtio.git" } +virtio-queue = { git = "https://github.com/rust-vmm/vm-virtio.git" } diff --git a/vhost-user-backend/CHANGELOG.md b/vhost-user-backend/CHANGELOG.md index 6b1293c9..b51d704a 100644 --- a/vhost-user-backend/CHANGELOG.md +++ b/vhost-user-backend/CHANGELOG.md @@ -6,6 +6,8 @@ - [[#339]](https://github.com/rust-vmm/vhost/pull/339) Add support for `GET_SHMEM_CONFIG` message ### Changed +- [[#348]](https://github.com/rust-vmm/vhost/pull/348) Updated vm-memory to 0.18.0 + ### Deprecated ### Fixed diff --git a/vhost-user-backend/src/handler.rs b/vhost-user-backend/src/handler.rs index e81d1f9d..0a7969b8 100644 --- a/vhost-user-backend/src/handler.rs +++ b/vhost-user-backend/src/handler.rs @@ -30,7 +30,9 @@ use vhost::vhost_user::{ use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX; use virtio_queue::{Error as VirtQueError, QueueT}; use vm_memory::mmap::NewBitmap; -use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryMmap, GuestRegionMmap}; +use vm_memory::{ + GuestAddress, GuestAddressSpace, GuestMemoryBackend, GuestMemoryMmap, GuestRegionMmap, +}; use vmm_sys_util::epoll::EventSet; use super::backend::VhostUserBackend; diff --git a/vhost-user-backend/tests/vhost-user-server.rs b/vhost-user-backend/tests/vhost-user-server.rs index 3c8205a5..dccab35a 100644 --- a/vhost-user-backend/tests/vhost-user-server.rs +++ b/vhost-user-backend/tests/vhost-user-server.rs @@ -15,7 +15,8 @@ use vhost::vhost_user::{Backend, Frontend, Listener, VhostUserFrontend}; use vhost::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData}; use vhost_user_backend::{VhostUserBackendMut, VhostUserDaemon, VringRwLock}; use vm_memory::{ - FileOffset, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, GuestMemoryMmap, + FileOffset, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryBackend, + GuestMemoryMmap, }; use vmm_sys_util::epoll::EventSet; use vmm_sys_util::event::{ diff --git a/vhost/CHANGELOG.md b/vhost/CHANGELOG.md index 018ac45d..8b1fb317 100644 --- a/vhost/CHANGELOG.md +++ b/vhost/CHANGELOG.md @@ -7,6 +7,8 @@ - [[#339]](https://github.com/rust-vmm/vhost/pull/339) Add support for `GET_SHMEM_CONFIG` message ### Changed +- [[#348]](https://github.com/rust-vmm/vhost/pull/348) Updated vm-memory to 0.18.0 + ### Deprecated ### Fixed - [[#338]](https://github.com/rust-vmm/vhost/pull/338) vhost: fix double-locking in Backend to Frontend request handlers diff --git a/vhost/src/vhost_kern/mod.rs b/vhost/src/vhost_kern/mod.rs index a33c71e3..834fed4a 100644 --- a/vhost/src/vhost_kern/mod.rs +++ b/vhost/src/vhost_kern/mod.rs @@ -16,7 +16,7 @@ use std::os::unix::io::{AsRawFd, RawFd}; use libc::{c_void, ssize_t, write}; -use vm_memory::{Address, GuestAddress, GuestAddressSpace, GuestMemory, GuestUsize}; +use vm_memory::{Address, GuestAddress, GuestAddressSpace, GuestMemoryBackend, GuestUsize}; use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::ioctl::{ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref}; @@ -38,9 +38,9 @@ pub mod vsock; /// Helper trait to signify `GuestAddressSpace`s that are physical, which is required for /// vhost_kern. -pub trait PhysicalGuestAddressSpace: GuestAddressSpace {} +pub trait PhysicalGuestAddressSpace: GuestAddressSpace {} -impl PhysicalGuestAddressSpace for AS where AS::M: GuestMemory {} +impl PhysicalGuestAddressSpace for AS where AS::M: GuestMemoryBackend {} #[inline] fn ioctl_result(rc: i32, res: T) -> Result { diff --git a/vhost/src/vhost_kern/net.rs b/vhost/src/vhost_kern/net.rs index 58d70d99..e6f3d1e6 100644 --- a/vhost/src/vhost_kern/net.rs +++ b/vhost/src/vhost_kern/net.rs @@ -68,7 +68,7 @@ impl AsRawFd for Net { #[cfg(test)] mod tests { - use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap}; + use vm_memory::{GuestAddress, GuestMemoryBackend, GuestMemoryMmap}; use vmm_sys_util::eventfd::EventFd; use super::*; diff --git a/vhost/src/vhost_kern/vdpa.rs b/vhost/src/vhost_kern/vdpa.rs index 92ad2cdd..1e735a2d 100644 --- a/vhost/src/vhost_kern/vdpa.rs +++ b/vhost/src/vhost_kern/vdpa.rs @@ -349,7 +349,7 @@ mod tests { const VHOST_VDPA_PATH: &str = "/dev/vhost-vdpa-0"; use std::alloc::{alloc, dealloc, Layout}; - use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap}; + use vm_memory::{GuestAddress, GuestMemoryBackend, GuestMemoryMmap}; use vmm_sys_util::eventfd::EventFd; use super::*; diff --git a/vhost/src/vhost_kern/vsock.rs b/vhost/src/vhost_kern/vsock.rs index 76a718aa..dc4bea42 100644 --- a/vhost/src/vhost_kern/vsock.rs +++ b/vhost/src/vhost_kern/vsock.rs @@ -84,7 +84,7 @@ impl AsRawFd for Vsock { #[cfg(test)] mod tests { - use vm_memory::{GuestAddress, GuestMemory, GuestMemoryMmap}; + use vm_memory::{GuestAddress, GuestMemoryBackend, GuestMemoryMmap}; use vmm_sys_util::eventfd::EventFd; use super::*;