Skip to contentSkip to conversation

platform-bus: Align MMIO regions to host page size

PATCH In review Cédric Le Goater 2 participants 4 messages Jun 30 – Jul 1

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform-bus: Align MMIO regions to host page size

On aarch64 hosts with 64K pages, the platform bus MMIO allocator can place device regions (such as the 1KB "tpm-ppi" region) at offsets that are not aligned to the host page size. This causes unnecessary and noisy VFIO IOMMU warnings when starting VMs configured with passed-through PCI devices:

vfio_listener_valid_section received unaligned region tpm-ppi

    iova=0xc005000 offset_within_region=0x0
    qemu_real_host_page_size=0x10000

Fix this by ensuring the alignment used by the platform bus allocator is at least qemu_real_host_page_size().

---
 hw/core/platform-bus.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/core/platform-bus.c +7 -0
index a2217a2deec7ab0f49b211c6658db02d13c319df..a17a38c1ba5491e2001fec5a29c188de67e93d11 100644
@@ -140,6 +140,13 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
         return;
     }
 
+    /*
+     * Ensure alignment is at least the host page size so that IOMMU
+     * mappings (e.g. VFIO) work on hosts with large pages such as
+     * aarch64 with 64K pages.
+     */
+    alignment = MAX(alignment, qemu_real_host_page_size());
+
     /*
      * Look for empty space in the MMIO space that is naturally aligned with
      * the target device's memory region
Signature · 1 line
2.54.0
#1 lore raw
Quoted 10 lines · Cédric Le Goater

On aarch64 hosts with 64K pages, the platform bus MMIO allocator can place device regions (such as the 1KB "tpm-ppi" region) at offsets that are not aligned to the host page size. This causes unnecessary and noisy VFIO IOMMU warnings when starting VMs configured with passed-through PCI devices:

vfio_listener_valid_section received unaligned region tpm-ppi

    iova=0xc005000 offset_within_region=0x0
    qemu_real_host_page_size=0x10000

Why does vfio care about the tpm-ppi region? I thought vfio was only for passthrough devices, not for normal ones.

Quoted 13 lines

Fix this by ensuring the alignment used by the platform bus allocator is at least qemu_real_host_page_size().

---
 hw/core/platform-bus.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/core/platform-bus.c +0 -0
index a2217a2deec7ab0f49b211c6658db02d13c319df..a17a38c1ba5491e2001fec5a29c188de67e93d11 100644

hw/core/platform-bus.c static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev, · line 148

Quoted 9 lines
hw/core/platform-bus.c +6 -0
@@ -140,6 +140,13 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
         return;
     }
 
+    /*
+     * Ensure alignment is at least the host page size so that IOMMU
+     * mappings (e.g. VFIO) work on hosts with large pages such as
+     * aarch64 with 64K pages.
+     */
+    alignment = MAX(alignment, qemu_real_host_page_size());

Do we need to tie this to machine versions? Otherwise I think the memory layout can change underfoot which would break a guest migrated from an old QEMU to new.

-- PMM

#2 lore raw
Quoted 8 lines · Peter Maydell
Quoted 7 lines · Cédric Le Goater

On aarch64 hosts with 64K pages, the platform bus MMIO allocator can place device regions (such as the 1KB "tpm-ppi" region) at offsets that are not aligned to the host page size. This causes unnecessary and noisy VFIO IOMMU warnings when starting VMs configured with passed-through PCI devices:

Quoted 6 lines
Quoted 3 lines
   vfio_listener_valid_section received unaligned region tpm-ppi
     iova=0xc005000 offset_within_region=0x0
     qemu_real_host_page_size=0x10000

Why does vfio care about the tpm-ppi region? I thought vfio was only for passthrough devices, not for normal ones.

It's caught by the VFIO listener which doesn't filer per device, it covers the entire address space.

This is a benign address mis-alignment warning of the tpm-ppi memory region and VFIO simply skips the region.

Quoted 17 lines
Quoted 17 lines

Fix this by ensuring the alignment used by the platform bus allocator is at least qemu_real_host_page_size().

---
  hw/core/platform-bus.c | 7 +++++++
  1 file changed, 7 insertions(+)
hw/core/platform-bus.c +0 -0
index a2217a2deec7ab0f49b211c6658db02d13c319df..a17a38c1ba5491e2001fec5a29c188de67e93d11 100644
@@ -140,6 +140,13 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
          return;
      }
 
Quoted 10 lines

hw/core/platform-bus.c static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev, · line 148

Quoted 6 lines
hw/core/platform-bus.c +6 -0
+    /*
+     * Ensure alignment is at least the host page size so that IOMMU
+     * mappings (e.g. VFIO) work on hosts with large pages such as
+     * aarch64 with 64K pages.
+     */
+    alignment = MAX(alignment, qemu_real_host_page_size());

Do we need to tie this to machine versions? Otherwise I think the memory layout can change underfoot which would break a guest migrated from an old QEMU to new.

OK. Let's extend vfio_known_safe_misalignment() instead as done by commit 851d6d1a0ff2 ("vfio/common: remove spurious tpm-crb-cmd misalignment warning").

Thanks,

C.

#3 lore raw
Quoted 14 lines · Cédric Le Goater
Quoted 12 lines · Peter Maydell
Quoted 10 lines · Cédric Le Goater

On aarch64 hosts with 64K pages, the platform bus MMIO allocator can place device regions (such as the 1KB "tpm-ppi" region) at offsets that are not aligned to the host page size. This causes unnecessary and noisy VFIO IOMMU warnings when starting VMs configured with passed-through PCI devices:

   vfio_listener_valid_section received unaligned region tpm-ppi
     iova=0xc005000 offset_within_region=0x0
     qemu_real_host_page_size=0x10000
Quoted 8 lines
Quoted 2 lines

Why does vfio care about the tpm-ppi region? I thought vfio was only for passthrough devices, not for normal ones.

It's caught by the VFIO listener which doesn't filer per device, it covers the entire address space.

This is a benign address mis-alignment warning of the tpm-ppi memory region and VFIO simply skips the region.

That sounds like the problem then is that VFIO is warning about things that are not in any way going to cause an issue. We should stop it from doing that, not change the rest of the platform because its warnings are over-broad.

Quoted 3 lines

OK. Let's extend vfio_known_safe_misalignment() instead as done by commit 851d6d1a0ff2 ("vfio/common: remove spurious tpm-crb-cmd misalignment warning").

That seems like vfio is gradually accumulating a very specific list of "we know this thing is misaligned" every time. That is clearly wrong -- any device anywhere on the board is allowed to have a non-aligned memory region. Those are totally normal.

I think the vfio code needs to change so that it's only checking the stuff that's actually vfio related. Drop the "we have a whitelist" approach, please.

-- PMM