From: Alex Williamson <alex@shazbot.org>
To: "Cédric Le Goater" <clg@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
Eric Auger <eric.auger@redhat.com>,
Stefan Berger <stefanb@linux.ibm.com>,
Peter Maydell <peter.maydell@linaro.org>,
alex@shazbot.org
Subject: Re: [PATCH] vfio/listener: Only warn on misalignment for VFIO-owned regions
Date: Mon, 6 Jul 2026 08:20:23 -0600 [thread overview]
Message-ID: <20260706082023.7ee830b8@shazbot.org> (raw)
In-Reply-To: <20260702160640.3875666-1-clg@redhat.com>
On Thu, 2 Jul 2026 18:06:40 +0200
Cédric Le Goater <clg@redhat.com> wrote:
> 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.
I thought the whole point was to warn when there are non-vfio devices
that we cannot insert into the DMA map. 851d6d1a0ff2 added tpm-crb-cmd
to an ignore list because it's not a DMA target. The intention of that
ignore list was to continue to evaluate devices that are misaligned
and either add them to the ignore list or determine they could be a
valid DMA target and correct the alignment.
Can this even legitimately trigger with a vfio-pci device? Thanks,
Alex
>
> 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
next prev parent reply other threads:[~2026-07-06 14:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20260706082023.7ee830b8@shazbot.org \
--to=alex@shazbot.org \
--cc=clg@redhat.com \
--cc=eric.auger@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanb@linux.ibm.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 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.