From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C76B76AF95 for ; Thu, 17 Mar 2022 13:54:23 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B769D4355 for ; Thu, 17 Mar 2022 13:53:53 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 277BD434B for ; Thu, 17 Mar 2022 13:53:53 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id F1FDD46EC8 for ; Thu, 17 Mar 2022 13:53:52 +0100 (CET) From: Markus Frank To: pve-devel@lists.proxmox.com Date: Thu, 17 Mar 2022 13:52:51 +0100 Message-Id: <20220317125251.1293163-1-m.frank@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.001 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemuserver.pm] Subject: [pve-devel] [PATCH qemu-server v2] fix #3784: Parameter for guest vIOMMU X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 12:54:23 -0000 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 --- 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