From d1e6f9cc4ea23c1ab7769e8ccbc8be930a39c3cd Mon Sep 17 00:00:00 2001 From: Pavel Mores Date: Wed, 24 Apr 2024 17:05:04 +0200 Subject: [PATCH] runtime-rs: add IOMMU to qemu VM if configured The adding itself is done by a new function add_iommu() that conforms with the add_*() convention. Note though that this function is called internally, by the QemuCmdLine constructor, simply because there's nothing to trigger its invocation from QemuInner (unlike the other add_*() functions so far). Signed-off-by: Pavel Mores --- .../hypervisor/src/qemu/cmdline_generator.rs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 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 2244e2c9f2..5cca822644 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs @@ -1191,7 +1191,7 @@ pub struct QemuCmdLine<'a> { impl<'a> QemuCmdLine<'a> { pub fn new(id: &str, config: &'a HypervisorConfig) -> Result> { - Ok(QemuCmdLine { + let mut qemu_cmd_line = QemuCmdLine { id: id.to_string(), config, kernel: Kernel::new(config)?, @@ -1202,7 +1202,13 @@ impl<'a> QemuCmdLine<'a> { rtc: Rtc::new(), knobs: Knobs::new(config), devices: Vec::new(), - }) + }; + + if config.device_info.enable_iommu { + qemu_cmd_line.add_iommu(); + } + + Ok(qemu_cmd_line) } fn bus_type(&self) -> VirtioBusType { @@ -1213,6 +1219,17 @@ impl<'a> QemuCmdLine<'a> { } } + fn add_iommu(&mut self) { + let dev_iommu = DeviceIntelIommu::new(); + self.devices.push(Box::new(dev_iommu)); + + self.kernel + .params + .append(&mut KernelParams::from_string("intel_iommu=on iommu=pt")); + + self.machine.set_kernel_irqchip("split"); + } + pub fn add_virtiofs_share( &mut self, virtiofsd_socket_path: &str,