From 0859f47a17ee4a4c7d080ba93cb6a2d36b72b5d7 Mon Sep 17 00:00:00 2001 From: Pavel Mores Date: Fri, 19 Apr 2024 15:38:57 +0200 Subject: [PATCH] runtime-rs: add representation of '-device intel-iommu' to qemu-rs Following the golang shim example, the values are hardcoded. Signed-off-by: Pavel Mores --- .../hypervisor/src/qemu/cmdline_generator.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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 7068e6598..2244e2c9f 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs @@ -1118,6 +1118,36 @@ impl ToQemuParams for Rtc { } } +#[derive(Debug)] +struct DeviceIntelIommu { + intremap: bool, + device_iotlb: bool, + caching_mode: bool, +} + +impl DeviceIntelIommu { + fn new() -> DeviceIntelIommu { + DeviceIntelIommu { + intremap: true, + device_iotlb: true, + caching_mode: true, + } + } +} + +#[async_trait] +impl ToQemuParams for DeviceIntelIommu { + async fn qemu_params(&self) -> Result> { + let mut params = Vec::new(); + params.push("intel-iommu".to_owned()); + let to_onoff = |b| if b { "on" } else { "off" }; + params.push(format!("intremap={}", to_onoff(self.intremap))); + params.push(format!("device-iotlb={}", to_onoff(self.device_iotlb))); + params.push(format!("caching-mode={}", to_onoff(self.caching_mode))); + Ok(vec!["-device".to_owned(), params.join(",")]) + } +} + fn is_running_in_vm() -> Result { let res = read_to_string("/proc/cpuinfo")? .lines()