All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio/listener: Only warn on misalignment for VFIO-owned regions
@ 2026-07-02 16:06 Cédric Le Goater
  2026-07-06 11:46 ` Cédric Le Goater
  2026-07-06 14:20 ` Alex Williamson
  0 siblings, 2 replies; 10+ messages in thread
From: Cédric Le Goater @ 2026-07-02 16:06 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: Alex Williamson, Eric Auger, Stefan Berger, Cédric Le Goater,
	Peter Maydell

Any device on the board can have non-page-aligned memory regions. The
VFIO listener should not warn about misalignment for regions that are
not VFIO-related.

Replace the vfio_known_safe_misalignment() whitelist with a
vfio_get_vfio_device() ownership check: only warn when a VFIO device's
own region is misaligned. For all other regions, emit a trace event
and silently skip. Extract the misalignment test into a
vfio_section_misaligned() helper for readability.

Note: vfio_get_vfio_device() currently only covers VFIO PCI devices,
including vfio-user-pci.  Other VFIO backends (AP, CCW) don't expose
memory regions through this path so this is sufficient for now.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/device.c     |  2 +-
 hw/vfio/listener.c   | 33 +++++++++++++++------------------
 hw/vfio/trace-events |  2 +-
 3 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 1a7f8088aad9583ee96fc303be917fdb2f100df9..3a47109efb35c6dc28719dcc19acb85bef1d26cd 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -439,7 +439,7 @@ bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev,
 
 VFIODevice *vfio_get_vfio_device(Object *obj)
 {
-    if (object_dynamic_cast(obj, TYPE_VFIO_PCI)) {
+    if (object_dynamic_cast(obj, TYPE_VFIO_PCI_DEVICE)) {
         return &VFIO_PCI_DEVICE(obj)->vbasedev;
     } else {
         return NULL;
diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
index c19600e980a8d02217b5d9df4aca8f879ab2c5d5..76b9b02f8163f18d20994e4ec1f914a4d148fa92 100644
--- a/hw/vfio/listener.c
+++ b/hw/vfio/listener.c
@@ -40,7 +40,6 @@
 #include "migration/misc.h"
 #include "migration/qemu-file.h"
 #include "system/tcg.h"
-#include "system/tpm.h"
 #include "vfio-migration-internal.h"
 #include "vfio-helpers.h"
 #include "vfio-listener.h"
@@ -352,20 +351,10 @@ static void vfio_ram_discard_unregister_listener(VFIOContainer *bcontainer,
     g_free(vrdl);
 }
 
-static bool vfio_known_safe_misalignment(MemoryRegionSection *section)
+static bool vfio_section_misaligned(MemoryRegionSection *section)
 {
-    MemoryRegion *mr = section->mr;
-
-    if (!TPM_IS_CRB(mr->owner)) {
-        return false;
-    }
-
-    /* this is a known safe misaligned region, just trace for debug purpose */
-    trace_vfio_known_safe_misalignment(memory_region_name(mr),
-                                       section->offset_within_address_space,
-                                       section->offset_within_region,
-                                       qemu_real_host_page_size());
-    return true;
+    return (section->offset_within_address_space & ~qemu_real_host_page_mask()) !=
+           (section->offset_within_region & ~qemu_real_host_page_mask());
 }
 
 static bool vfio_listener_valid_section(MemoryRegionSection *section,
@@ -379,10 +368,12 @@ static bool vfio_listener_valid_section(MemoryRegionSection *section,
         return false;
     }
 
-    if (unlikely((section->offset_within_address_space &
-                  ~qemu_real_host_page_mask()) !=
-                 (section->offset_within_region & ~qemu_real_host_page_mask()))) {
-        if (!vfio_known_safe_misalignment(section)) {
+    if (unlikely(vfio_section_misaligned(section))) {
+        /*
+         * Only warn for VFIO device regions.  Other VFIO backends
+         * (AP, CCW) don't expose memory regions through this path.
+         */
+        if (vfio_get_vfio_device(memory_region_owner(section->mr))) {
             error_report("%s received unaligned region %s iova=0x%"PRIx64
                          " offset_within_region=0x%"PRIx64
                          " qemu_real_host_page_size=0x%"PRIxPTR,
@@ -390,6 +381,12 @@ static bool vfio_listener_valid_section(MemoryRegionSection *section,
                          section->offset_within_address_space,
                          section->offset_within_region,
                          qemu_real_host_page_size());
+        } else {
+            trace_vfio_listener_region_misaligned(
+                         memory_region_name(section->mr),
+                         section->offset_within_address_space,
+                         section->offset_within_region,
+                         qemu_real_host_page_size());
         }
         return false;
     }
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index f71d0bbc0a5440e4ccd374fac4733af08438e7be..5056b9942027938cd6bc832198acc9809739399f 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -98,7 +98,7 @@ vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to liobn
 vfio_listener_region_add_iommu(const char* name, uint64_t start, uint64_t end) "region_add [iommu] %s 0x%"PRIx64" - 0x%"PRIx64
 vfio_listener_region_del_iommu(const char *name) "region_del [iommu] %s"
 vfio_listener_region_add_ram(uint64_t iova_start, uint64_t iova_end, void *vaddr) "region_add [ram] 0x%"PRIx64" - 0x%"PRIx64" [%p]"
-vfio_known_safe_misalignment(const char *name, uint64_t iova, uint64_t offset_within_region, uintptr_t page_size) "Region \"%s\" iova=0x%"PRIx64" offset_within_region=0x%"PRIx64" qemu_real_host_page_size=0x%"PRIxPTR
+vfio_listener_region_misaligned(const char *name, uint64_t iova, uint64_t offset_within_region, uintptr_t page_size) "Region \"%s\" iova=0x%"PRIx64" offset_within_region=0x%"PRIx64" qemu_real_host_page_size=0x%"PRIxPTR
 vfio_listener_region_add_no_dma_map(const char *name, uint64_t iova, uint64_t size, uint64_t page_size) "Region \"%s\" 0x%"PRIx64" size=0x%"PRIx64" is not aligned to 0x%"PRIx64" and cannot be mapped for DMA"
 vfio_listener_region_skip_dma_map(const char *name, uint64_t iova, uint64_t size) "Region \"%s\" 0x%"PRIx64" size=0x%"PRIx64" marked to skip IOMMU mapping"
 vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRIx64" - 0x%"PRIx64
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-07-06 17:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02 16:06 [PATCH] vfio/listener: Only warn on misalignment for VFIO-owned regions Cédric Le Goater
2026-07-06 11:46 ` Cédric Le Goater
2026-07-06 14:20 ` Alex Williamson
2026-07-06 15:12   ` Cédric Le Goater
2026-07-06 15:27     ` Peter Maydell
2026-07-06 15:42       ` Alex Williamson
2026-07-06 16:12         ` Peter Maydell
2026-07-06 17:16           ` Alex Williamson
2026-07-06 17:29             ` Peter Maydell
2026-07-06 15:34     ` Alex Williamson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.