From 4443df57bb3953b1ba3027c97fcdd4957fe0d01f Mon Sep 17 00:00:00 2001 From: German Maglione Date: Wed, 15 Nov 2023 11:28:51 +0100 Subject: [PATCH] vhost-user-backend: Add vhost-user bitmap trait bounds Any bitmap used in the vhost-user backend must implement the BitmapReplace trait, which provides the functionality to replace the internal bitmap in runtime. This internal bitmap is required because in the vm-memory crate the bitmap is expected to exist at the time of creating the memory regions, and in the case of vhost-user the bitmap is added at runtime, also it could be replaced at a later time. In addition, the vhost user protocol does not specify whether the previous bitmap is still active after replying to the VHOST_USER_SET_LOG_BASE message, so we must be sure that the in-flight requests are using the new bitmap after the message reply. Signed-off-by: German Maglione --- vhost-user-backend/src/handler.rs | 3 ++- vhost-user-backend/src/lib.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/vhost-user-backend/src/handler.rs b/vhost-user-backend/src/handler.rs index c63bc93..393156f 100644 --- a/vhost-user-backend/src/handler.rs +++ b/vhost-user-backend/src/handler.rs @@ -12,6 +12,7 @@ use std::os::unix::io::AsRawFd; use std::sync::Arc; use std::thread; +use crate::bitmap::BitmapReplace; #[cfg(feature = "postcopy")] use userfaultfd::{Uffd, UffdBuilder}; use vhost::vhost_user::message::{ @@ -230,7 +231,7 @@ where impl VhostUserBackendReqHandlerMut for VhostUserHandler where - T::Bitmap: NewBitmap + Clone, + T::Bitmap: BitmapReplace + NewBitmap + Clone, { fn set_owner(&mut self) -> VhostUserResult<()> { if self.owned { diff --git a/vhost-user-backend/src/lib.rs b/vhost-user-backend/src/lib.rs index e4f8a86..d6cfbf9 100644 --- a/vhost-user-backend/src/lib.rs +++ b/vhost-user-backend/src/lib.rs @@ -29,6 +29,7 @@ mod handler; pub use self::handler::VhostUserHandlerError; pub mod bitmap; +use crate::bitmap::BitmapReplace; mod vring; pub use self::vring::{ @@ -97,7 +98,7 @@ pub struct VhostUserDaemon { impl VhostUserDaemon where T: VhostUserBackend + Clone + 'static, - T::Bitmap: NewBitmap + Clone + Send + Sync, + T::Bitmap: BitmapReplace + NewBitmap + Clone + Send + Sync, T::Vring: Clone + Send + Sync, { /// Create the daemon instance, providing the backend implementation of `VhostUserBackend`.