From e7d46d6980ed1312e16243ff2ec4bb018f9aec5f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 8 Mar 2021 12:00:31 +0100 Subject: vhost_user: Add support for GET_MAX_MEM_SLOTS Add the support for GET_MAX_MEM_SLOTS command. This requests the vhost-user backend to provide the maximum amount of memory slots that can be supported. It is only available if the protocol feature VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS has been negotiated. Signed-off-by: Sebastien Boeuf --- src/vhost_user/slave_req_handler.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/vhost_user/slave_req_handler.rs') diff --git a/src/vhost_user/slave_req_handler.rs b/src/vhost_user/slave_req_handler.rs index 3b44e4c..870d324 100644 --- a/src/vhost_user/slave_req_handler.rs +++ b/src/vhost_user/slave_req_handler.rs @@ -62,6 +62,7 @@ pub trait VhostUserSlaveReqHandler { fn get_config(&self, offset: u32, size: u32, flags: VhostUserConfigFlags) -> Result>; fn set_config(&self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>; fn set_slave_req_fd(&self, _vu_req: SlaveFsCacheReq) {} + fn get_max_mem_slots(&self) -> Result; } /// Services provided to the master by the slave without interior mutability. @@ -102,6 +103,7 @@ pub trait VhostUserSlaveReqHandlerMut { ) -> Result>; fn set_config(&mut self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>; fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {} + fn get_max_mem_slots(&mut self) -> Result; } impl VhostUserSlaveReqHandler for Mutex { @@ -190,6 +192,10 @@ impl VhostUserSlaveReqHandler for Mutex { fn set_slave_req_fd(&self, vu_req: SlaveFsCacheReq) { self.lock().unwrap().set_slave_req_fd(vu_req) } + + fn get_max_mem_slots(&self) -> Result { + self.lock().unwrap().get_max_mem_slots() + } } /// Server to handle service requests from masters from the master communication channel. @@ -417,6 +423,18 @@ impl SlaveReqHandler { self.check_request_size(&hdr, size, hdr.get_size() as usize)?; self.set_slave_req_fd(&hdr, rfds)?; } + MasterReq::GET_MAX_MEM_SLOTS => { + if self.acked_protocol_features + & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits() + == 0 + { + return Err(Error::InvalidOperation); + } + self.check_request_size(&hdr, size, 0)?; + let num = self.backend.get_max_mem_slots()?; + let msg = VhostUserU64::new(num); + self.send_reply_message(&hdr, &msg)?; + } _ => { return Err(Error::InvalidMessage); } -- cgit v1.2.3 From 7e3ab1af4e1c2157e206798683b64eb384c3693a Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 4 Mar 2021 17:43:35 +0100 Subject: vhost_user: Add support for ADD_MEM_REG Adding support for a new message ADD_MEM_REG. This command request a new region to be added and mapped by the vhost-user backend. It is designed for supporting memory hotplug, avoiding the limitation from SET_MEM_TABLE (supports only 8 regions). It is only available if the protocol feature VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS has been negotiated. Signed-off-by: Sebastien Boeuf --- src/vhost_user/slave_req_handler.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/vhost_user/slave_req_handler.rs') diff --git a/src/vhost_user/slave_req_handler.rs b/src/vhost_user/slave_req_handler.rs index 870d324..3d8d6d5 100644 --- a/src/vhost_user/slave_req_handler.rs +++ b/src/vhost_user/slave_req_handler.rs @@ -63,6 +63,7 @@ pub trait VhostUserSlaveReqHandler { fn set_config(&self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>; fn set_slave_req_fd(&self, _vu_req: SlaveFsCacheReq) {} fn get_max_mem_slots(&self) -> Result; + fn add_mem_region(&self, region: &VhostUserSingleMemoryRegion, fd: RawFd) -> Result<()>; } /// Services provided to the master by the slave without interior mutability. @@ -104,6 +105,7 @@ pub trait VhostUserSlaveReqHandlerMut { fn set_config(&mut self, offset: u32, buf: &[u8], flags: VhostUserConfigFlags) -> Result<()>; fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {} fn get_max_mem_slots(&mut self) -> Result; + fn add_mem_region(&mut self, region: &VhostUserSingleMemoryRegion, fd: RawFd) -> Result<()>; } impl VhostUserSlaveReqHandler for Mutex { @@ -196,6 +198,10 @@ impl VhostUserSlaveReqHandler for Mutex { fn get_max_mem_slots(&self) -> Result { self.lock().unwrap().get_max_mem_slots() } + + fn add_mem_region(&self, region: &VhostUserSingleMemoryRegion, fd: RawFd) -> Result<()> { + self.lock().unwrap().add_mem_region(region, fd) + } } /// Server to handle service requests from masters from the master communication channel. @@ -435,6 +441,27 @@ impl SlaveReqHandler { let msg = VhostUserU64::new(num); self.send_reply_message(&hdr, &msg)?; } + MasterReq::ADD_MEM_REG => { + if self.acked_protocol_features + & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits() + == 0 + { + return Err(Error::InvalidOperation); + } + let fd = if let Some(fds) = &rfds { + if fds.len() != 1 { + return Err(Error::InvalidParam); + } + fds[0] + } else { + return Err(Error::InvalidParam); + }; + + let msg = + self.extract_request_body::(&hdr, size, &buf)?; + let res = self.backend.add_mem_region(&msg, fd); + self.send_ack_message(&hdr, res)?; + } _ => { return Err(Error::InvalidMessage); } @@ -655,6 +682,7 @@ impl SlaveReqHandler { MasterReq::SET_LOG_FD => Ok(rfds), MasterReq::SET_SLAVE_REQ_FD => Ok(rfds), MasterReq::SET_INFLIGHT_FD => Ok(rfds), + MasterReq::ADD_MEM_REG => Ok(rfds), _ => { if rfds.is_some() { Endpoint::::close_rfds(rfds); -- cgit v1.2.3 From ee3e8722706c984b3dfe12d3a130e92101b78e8f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 5 Mar 2021 10:34:14 +0100 Subject: vhost_user: Add support for REM_MEM_REG Adding support for a new message REM_MEM_REG. This command request an existing memory region to be removed and unmapped from the vhost-user backend. It is designed for supporting memory hot-unplug, rather than using SET_MEM_TABLE, which is less efficient as it would remap all remaining regions. It is only available if the protocol feature VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS has been negotiated. Signed-off-by: Sebastien Boeuf --- src/vhost_user/slave_req_handler.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/vhost_user/slave_req_handler.rs') diff --git a/src/vhost_user/slave_req_handler.rs b/src/vhost_user/slave_req_handler.rs index 3d8d6d5..18459a2 100644 --- a/src/vhost_user/slave_req_handler.rs +++ b/src/vhost_user/slave_req_handler.rs @@ -64,6 +64,7 @@ pub trait VhostUserSlaveReqHandler { fn set_slave_req_fd(&self, _vu_req: SlaveFsCacheReq) {} fn get_max_mem_slots(&self) -> Result; fn add_mem_region(&self, region: &VhostUserSingleMemoryRegion, fd: RawFd) -> Result<()>; + fn remove_mem_region(&self, region: &VhostUserSingleMemoryRegion) -> Result<()>; } /// Services provided to the master by the slave without interior mutability. @@ -106,6 +107,7 @@ pub trait VhostUserSlaveReqHandlerMut { fn set_slave_req_fd(&mut self, _vu_req: SlaveFsCacheReq) {} fn get_max_mem_slots(&mut self) -> Result; fn add_mem_region(&mut self, region: &VhostUserSingleMemoryRegion, fd: RawFd) -> Result<()>; + fn remove_mem_region(&mut self, region: &VhostUserSingleMemoryRegion) -> Result<()>; } impl VhostUserSlaveReqHandler for Mutex { @@ -202,6 +204,10 @@ impl VhostUserSlaveReqHandler for Mutex { fn add_mem_region(&self, region: &VhostUserSingleMemoryRegion, fd: RawFd) -> Result<()> { self.lock().unwrap().add_mem_region(region, fd) } + + fn remove_mem_region(&self, region: &VhostUserSingleMemoryRegion) -> Result<()> { + self.lock().unwrap().remove_mem_region(region) + } } /// Server to handle service requests from masters from the master communication channel. @@ -462,6 +468,19 @@ impl SlaveReqHandler { let res = self.backend.add_mem_region(&msg, fd); self.send_ack_message(&hdr, res)?; } + MasterReq::REM_MEM_REG => { + if self.acked_protocol_features + & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits() + == 0 + { + return Err(Error::InvalidOperation); + } + + let msg = + self.extract_request_body::(&hdr, size, &buf)?; + let res = self.backend.remove_mem_region(&msg); + self.send_ack_message(&hdr, res)?; + } _ => { return Err(Error::InvalidMessage); } -- cgit v1.2.3