public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC qemu-server v2 4/4] machine: warn intel-iommu users about too large address width
Date: Tue,  2 Sep 2025 13:22:01 +0200	[thread overview]
Message-ID: <20250902112307.124706-6-d.kral@proxmox.com> (raw)
In-Reply-To: <20250902112307.124706-1-d.kral@proxmox.com>

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 <d.kral@proxmox.com>
---
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


  parent reply	other threads:[~2025-09-02 11:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 11:21 [pve-devel] [PATCH common/qemu-server v2 0/5] fix issues with viommu+vfio passthrough in #6608, #6378 Daniel Kral
2025-09-02 11:21 ` [pve-devel] [PATCH common v2 1/1] procfs: cpuinfo: expose x86_phys_bits and x86_virt_bits values Daniel Kral
2025-09-05  9:10   ` Fiona Ebner
2025-09-05 11:47     ` Daniel Kral
2025-09-02 11:21 ` [pve-devel] [PATCH qemu-server v2 1/4] fix #6608: expose viommu driver aw-bits option Daniel Kral
2025-09-05 10:07   ` Fiona Ebner
2025-09-05 11:45     ` Daniel Kral
2025-09-05 12:00       ` Fiona Ebner
2025-09-05 14:18   ` Daniel Kral
2025-09-02 11:21 ` [pve-devel] [PATCH qemu-server v2 2/4] cpu config: factor out gathering common cpu properties Daniel Kral
2025-09-05 10:32   ` Fiona Ebner
2025-09-02 11:22 ` [pve-devel] [RFC qemu-server v2 3/4] fix #6378 (continued): warn intel-iommu users about iommu and host aw bits mismatch Daniel Kral
2025-09-02 11:26   ` Daniel Kral
2025-09-05 10:50   ` Fiona Ebner
2025-09-05 11:38     ` Daniel Kral
2025-09-05 12:52       ` Fiona Ebner
2025-09-02 11:22 ` Daniel Kral [this message]
2025-09-05 10:55   ` [pve-devel] [RFC qemu-server v2 4/4] machine: warn intel-iommu users about too large address width Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250902112307.124706-6-d.kral@proxmox.com \
    --to=d.kral@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal