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 <pmores@redhat.com>
This commit is contained in:
Pavel Mores 2024-04-24 17:05:04 +02:00
parent 0859f47a17
commit d1e6f9cc4e

View File

@ -1191,7 +1191,7 @@ pub struct QemuCmdLine<'a> {
impl<'a> QemuCmdLine<'a> {
pub fn new(id: &str, config: &'a HypervisorConfig) -> Result<QemuCmdLine<'a>> {
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,