From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id EC01D1FF16F for ; Tue, 2 Sep 2025 13:23:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DA1B810E6F; Tue, 2 Sep 2025 13:23:16 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Tue, 2 Sep 2025 13:22:01 +0200 Message-ID: <20250902112307.124706-6-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250902112307.124706-1-d.kral@proxmox.com> References: <20250902112307.124706-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1756812177073 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Subject: [pve-devel] [RFC qemu-server v2 4/4] machine: warn intel-iommu users about too large address width 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Similarily to the guest address width exceeding the vIOMMU address width, also warn users about the Intel vIOMMU address width being larger than the maximum allowed value, the maximum guest address width, as reported by the hardware. Signed-off-by: Daniel Kral --- I only added this as it was relatively cheap to implement now, but the user will be stopped by starting the VM anyway by issuing something like: kvm: -device vfio-pci,host=0000:00:02.0,id=hostpci0,bus=pci.0,addr=0x10: vfio 0000:00:02.0: Failed to set vIOMMU: aw-bits 48 > host aw-bits 39 src/PVE/QemuServer/Machine.pm | 16 ++++++++++++++++ src/test/run_config2command_tests.pl | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/PVE/QemuServer/Machine.pm b/src/PVE/QemuServer/Machine.pm index c083a27b..18b4a1b5 100644 --- a/src/PVE/QemuServer/Machine.pm +++ b/src/PVE/QemuServer/Machine.pm @@ -133,12 +133,28 @@ sub assert_valid_machine_property { } } +sub get_maximum_iommu_address_width { + my $max_iommu_aw_bits; + + if (-d "/sys/class/iommu/dmar0") { + my $cap = PVE::Tools::file_read_firstline("/sys/class/iommu/dmar0/intel-iommu/cap"); + # bits 21:16 contain the host's iommu maximum guest address width (MGAW) value + # hex(...) warns on 64-bit hex values, so use substr(...) to retrieve needed byte + $max_iommu_aw_bits = (hex("0x" . substr($cap, -6, 2)) & 0x3F) + 1; + } + + return $max_iommu_aw_bits; +} + sub check_valid_iommu_address_width { my ($machine_conf, $machine_version, $cpu_aw_bits) = @_; if ($machine_conf->{viommu} && $machine_conf->{viommu} eq 'intel') { my $iommu_aw_bits_default = min_version($machine_version, 9, 2) ? 48 : 39; my $iommu_aw_bits = $machine_conf->{'aw-bits'} // $iommu_aw_bits_default; + my $max_iommu_aw_bits = get_maximum_iommu_address_width(); + warn "Intel vIOMMU address width larger than maximum: $iommu_aw_bits > $max_iommu_aw_bits\n" + if $iommu_aw_bits && $max_iommu_aw_bits && $iommu_aw_bits > $max_iommu_aw_bits; warn "guest address width exceeds vIOMMU address width: $cpu_aw_bits > $iommu_aw_bits\n" if $cpu_aw_bits && $iommu_aw_bits && $cpu_aw_bits > $iommu_aw_bits; } diff --git a/src/test/run_config2command_tests.pl b/src/test/run_config2command_tests.pl index 0623b5c1..7594c52a 100755 --- a/src/test/run_config2command_tests.pl +++ b/src/test/run_config2command_tests.pl @@ -350,6 +350,14 @@ $qemu_server_config->mock( }, ); +my $qemu_server_machine; +$qemu_server_machine = Test::MockModule->new('PVE::QemuServer::Machine'); +$qemu_server_machine->mock( + get_maximum_iommu_address_width => sub { + return 48; + }, +); + my $qemu_server_memory; $qemu_server_memory = Test::MockModule->new('PVE::QemuServer::Memory'); $qemu_server_memory->mock( -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel