[pve-devel] [PATCH qemu-server v2] fix #3784: Parameter for guest vIOMMU
Markus Frank
m.frank at proxmox.com
Thu Mar 17 13:52:51 CET 2022
added a Parameter for vIOMMU so nobody has to use a github-script
or change the kvm command on every vm boot.
The args parameter doesn't work because the -device parameter(kvm)
with intel-iommu has to be placed before the other arguments.
vIOMMU enables the option to pass through pci devices to guest-vms
in guest-vms for nested Virtualisation.
Signed-off-by: Markus Frank <m.frank at proxmox.com>
---
v2:
* moved viommu-parameter inside of machine_fmt and added it the new
parameter machine_properties
new Config -> machine_properties: viommu=1,etc
* check if kvm and q35 are set
PVE/QemuServer.pm | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6a9f6b3..5878dfc 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -134,6 +134,15 @@ sub nodename {
return $nodename_cache;
}
+my $machine_fmt = {
+ viommu => {
+ type => 'boolean',
+ description => "enable guest vIOMMU (needs kvm to be enabled and q35 to be set as machine)",
+ default => 0,
+ optional => 1,
+ },
+};
+
my $watchdog_fmt = {
model => {
default_key => 1,
@@ -647,6 +656,12 @@ EODESCR
." remove disk operations.",
default => 0,
},
+ machine_properties => {
+ optional => 1,
+ type => 'string',
+ format => $machine_fmt,
+ description => "Sets machine parameters for viommu for Example",
+ },
bios => {
optional => 1,
type => 'string',
@@ -3433,6 +3448,10 @@ sub config_to_command {
my $winversion = windows_version($ostype);
my $kvm = $conf->{kvm};
my $nodename = nodename();
+ my $machine_properties_str = $conf->{machine_properties} // '';
+
+ my $machine_properties = parse_property_string($machine_fmt, $machine_properties_str);
+
my $arch = get_vm_arch($conf);
my $kvm_binary = get_command_for_arch($arch);
@@ -3487,6 +3506,14 @@ sub config_to_command {
my $use_old_bios_files = undef;
($use_old_bios_files, $machine_type) = qemu_use_old_bios_files($machine_type);
+ if ($machine_properties->{viommu} && (!$kvm || !$q35)) {
+ die "to use vIOMMU please enable kvm and set the machine type to q35";
+ }
+
+ if ($machine_properties->{viommu}) {
+ push @$devices, '-device', 'intel-iommu,intremap=on,caching-mode=on';
+ }
+
push @$cmd, $kvm_binary;
push @$cmd, '-id', $vmid;
@@ -4027,6 +4054,10 @@ sub config_to_command {
}
push @$machineFlags, "type=${machine_type_min}";
+ if ($machine_properties->{viommu}) {
+ push @$machineFlags, 'kernel-irqchip=split';
+ }
+
push @$cmd, @$devices;
push @$cmd, '-rtc', join(',', @$rtcFlags) if scalar(@$rtcFlags);
push @$cmd, '-machine', join(',', @$machineFlags) if scalar(@$machineFlags);
--
2.30.2
More information about the pve-devel
mailing list