]> git.ipfire.org Git - thirdparty/qemu.git/commit
amd_iommu: Support 64-bit address for IOTLB lookup
authorSairaj Kodilkar <sarunkod@amd.com>
Mon, 3 Nov 2025 20:32:09 +0000 (20:32 +0000)
committerMichael S. Tsirkin <mst@redhat.com>
Sun, 9 Nov 2025 08:25:43 +0000 (03:25 -0500)
commit637dc49a3ae6b72cdb6415dcdcdb22ff770f2c8d
treea7a6d33481c9ad77950fed8b949951249dd82350
parent27d6a0ec0beec45c35a70cd5f12c4530725dda2a
amd_iommu: Support 64-bit address for IOTLB lookup

The physical AMD IOMMU supports up to 64 bits of IOVA. When a device tries
to read or write from a given DMA address, the IOMMU translates the address
using the I/O page tables assigned to that device. Since the emulated IOMMU
uses per-device page tables, an ideal cache tag would need to be 68 bits
(64-bit address - 12-bit page alignment + 16-bit device ID).

The current software IOTLB implementation uses a GLib hash table with a
64-bit key to hash both the IOVA and device ID, which limits the IOVA to 60
bits. This causes a failure while setting up the device when a guest is
booted with "iommu.forcedac=1", which forces the use of DMA addresses at the
top of the 64-bit address space.

To address this issue, construct the 64-bit hash key using the upper 52 bits
of IOVA (GFN) and lower 12 bits of the device ID to avoid truncation as much
as possible (reducing hash collisions).

Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU")
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20251103203209.645434-4-alejandro.j.jimenez@oracle.com>
hw/i386/amd_iommu.c
hw/i386/amd_iommu.h