From 920484918c272b0f9f39ae01cc956fa9d4fc9052 Mon Sep 17 00:00:00 2001 From: Hyounggyu Choi Date: Thu, 21 Nov 2024 18:07:40 +0100 Subject: [PATCH] runtime-rs: Add devno to VhostVsock A new attribute named `devno` is added to VhostVsock. It will be used to specify a device number for a CCW bus type. Signed-off-by: Hyounggyu Choi --- .../hypervisor/src/qemu/cmdline_generator.rs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs index f32b5dabc1..2be2291835 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs @@ -974,16 +974,23 @@ struct VhostVsock { guest_cid: u32, disable_modern: bool, iommu_platform: bool, + devno: Option, } impl VhostVsock { - fn new(vhostfd: tokio::fs::File, guest_cid: u32, bus_type: VirtioBusType) -> VhostVsock { + fn new( + vhostfd: tokio::fs::File, + guest_cid: u32, + bus_type: VirtioBusType, + devno: Option, + ) -> VhostVsock { VhostVsock { bus_type, vhostfd, guest_cid, disable_modern: false, iommu_platform: false, + devno, } } @@ -1009,6 +1016,9 @@ impl ToQemuParams for VhostVsock { if self.iommu_platform { params.push("iommu_platform=on".to_owned()); } + if let Some(devno) = &self.devno { + params.push(format!("devno={}", devno)); + } params.push(format!("vhostfd={}", self.vhostfd.as_raw_fd())); params.push(format!("guest-cid={}", self.guest_cid)); @@ -1859,13 +1869,28 @@ impl<'a> QemuCmdLine<'a> { pub fn add_vsock(&mut self, vhostfd: tokio::fs::File, guest_cid: u32) -> Result<()> { clear_cloexec(vhostfd.as_raw_fd()).context("clearing O_CLOEXEC failed on vsock fd")?; - let mut vhost_vsock_pci = VhostVsock::new(vhostfd, guest_cid, bus_type(self.config)); + let devno = match &mut self.ccw_subchannel { + Some(subchannel) => match subchannel.add_device("vsock-0") { + Ok(slot) => { + let addr = subchannel.address_format_ccw(slot); + Some(addr) + } + Err(err) => { + info!(sl!(), "failed to add device to subchannel {:?}", err); + None + } + }, + None => None, + }; + let mut vhost_vsock_pci = VhostVsock::new(vhostfd, guest_cid, bus_type(self.config), devno); if !self.config.disable_nesting_checks && should_disable_modern() { vhost_vsock_pci.set_disable_modern(true); } - if self.config.device_info.enable_iommu_platform { + if self.config.device_info.enable_iommu_platform + && bus_type(self.config) == VirtioBusType::Ccw + { vhost_vsock_pci.set_iommu_platform(true); }