From: Yi Liu <yi.l.liu@intel.com>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>, <qemu-devel@nongnu.org>
Cc: <alex@shazbot.org>, <clg@redhat.com>, <mst@redhat.com>,
<jasowang@redhat.com>, <clement.mathieu--drif@eviden.com>,
<eric.auger@redhat.com>, <joao.m.martins@oracle.com>,
<avihaih@nvidia.com>, <xudong.hao@intel.com>,
<giovanni.cabiddu@intel.com>, <rohith.s.r@intel.com>,
<mark.gross@intel.com>, <arjan.van.de.ven@intel.com>
Subject: Re: [PATCH v5 7/9] vfio/listener: Construct iotlb entry when unmap memory address space
Date: Tue, 25 Nov 2025 18:04:18 +0800 [thread overview]
Message-ID: <6db6365a-225d-4fbb-ac20-d10c424d364b@intel.com> (raw)
In-Reply-To: <20251106042027.856594-8-zhenzhong.duan@intel.com>
On 2025/11/6 12:20, Zhenzhong Duan wrote:
> If a VFIO device in guest switches from passthrough(PT) domain to block
> domain, the whole memory address space is unmapped, but we passed a NULL
> iotlb entry to unmap_bitmap, then bitmap query didn't happen and we lost
> dirty pages.
this is a good catch. :) Have you observed problem in testing or just
identified it with patch iteration?
> By constructing an iotlb entry with iova = gpa for unmap_bitmap, it can
> set dirty bits correctly.
>
> For IOMMU address space, we still send NULL iotlb because VFIO don't
> know the actual mappings in guest. It's vIOMMU's responsibility to send
> actual unmapping notifications, e.g., vtd_address_space_unmap_in_migration()
>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> Tested-by: Giovannio Cabiddu <giovanni.cabiddu@intel.com>
> ---
> hw/vfio/listener.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c
> index 2109101158..3b48f6796c 100644
> --- a/hw/vfio/listener.c
> +++ b/hw/vfio/listener.c
> @@ -713,14 +713,27 @@ static void vfio_listener_region_del(MemoryListener *listener,
>
> if (try_unmap) {
> bool unmap_all = false;
> + IOMMUTLBEntry entry = {}, *iotlb = NULL;
>
> if (int128_eq(llsize, int128_2_64())) {
> assert(!iova);
> unmap_all = true;
> llsize = int128_zero();
> }
> +
> + /*
> + * Fake an IOTLB entry for identity mapping which is needed by dirty
> + * tracking. In fact, in unmap_bitmap, only translated_addr field is
> + * used to set dirty bitmap.
Just say sync dirty is needed per unmap. So you may add a check
in_migration as well. If not in migration, it is no needed to do it.
> + */
> + if (!memory_region_is_iommu(section->mr)) {
> + entry.iova = iova;
> + entry.translated_addr = iova;
> + iotlb = &entry;
> + }
> +
While, I'm still wondering how to deal with iommu MR case. Let's see a
scenario first. When switching from DMA domain to PT, QEMU will switch
to PT. This shall trigger the vfio_listener_region_del() and unregister
the iommu notifier. This means vIOMMU side needs to do unmap prior to
switching AS. If not, the iommu notifier is gone when vIOMMU wants to
unmap with an IOTLBEvent. For virtual intel_iommu, it is calling
vtd_address_space_unmap_in_migration() prior to calling
vtd_switch_address_space(). So I think you need to tweak the intel_iommu
a bit to suit the order requirement. :)
BTW. should the iommu MRs even go to this try_unmap branch? I think for
such MRs, it relies on the vIOMMU to unmap explicitly (hence trigger the
vfio_iommu_map_notify()).
> ret = vfio_container_dma_unmap(bcontainer, iova, int128_get64(llsize),
> - NULL, unmap_all);
> + iotlb, unmap_all);
> if (ret) {
> error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", "
> "0x%"HWADDR_PRIx") = %d (%s)",
Regards,
Yi Liu
next prev parent reply other threads:[~2025-11-25 9:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 4:20 [PATCH v5 0/9] vfio: relax the vIOMMU check Zhenzhong Duan
2025-11-06 4:20 ` [PATCH v5 1/9] vfio/iommufd: Add framework code to support getting dirty bitmap before unmap Zhenzhong Duan
2025-11-06 4:20 ` [PATCH v5 2/9] vfio/iommufd: Query dirty bitmap before DMA unmap Zhenzhong Duan
2025-11-06 4:20 ` [PATCH v5 3/9] vfio/container-legacy: rename vfio_dma_unmap_bitmap() to vfio_legacy_dma_unmap_get_dirty_bitmap() Zhenzhong Duan
2025-11-06 4:20 ` [PATCH v5 4/9] vfio: Add a backend_flag parameter to vfio_contianer_query_dirty_bitmap() Zhenzhong Duan
2025-11-06 4:20 ` [PATCH v5 5/9] vfio/iommufd: Add IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag support Zhenzhong Duan
2025-11-06 4:20 ` [PATCH v5 6/9] intel_iommu: Fix unmap_bitmap failure with legacy VFIO backend Zhenzhong Duan
2025-11-28 3:51 ` Duan, Zhenzhong
2025-11-06 4:20 ` [PATCH v5 7/9] vfio/listener: Construct iotlb entry when unmap memory address space Zhenzhong Duan
2025-11-25 10:04 ` Yi Liu [this message]
2025-11-26 5:45 ` Duan, Zhenzhong
2025-11-27 13:23 ` Yi Liu
2025-11-28 2:58 ` Duan, Zhenzhong
2025-11-06 4:20 ` [PATCH v5 8/9] vfio/migration: Add migration blocker if VM memory is too large to cause unmap_bitmap failure Zhenzhong Duan
2025-11-25 9:20 ` Yi Liu
2025-11-06 4:20 ` [PATCH v5 9/9] vfio/migration: Allow live migration with vIOMMU without VFs using device dirty tracking Zhenzhong Duan
2025-11-20 9:29 ` [PATCH v5 0/9] vfio: relax the vIOMMU check Duan, Zhenzhong
2025-11-25 7:40 ` Cédric Le Goater
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=6db6365a-225d-4fbb-ac20-d10c424d364b@intel.com \
--to=yi.l.liu@intel.com \
--cc=alex@shazbot.org \
--cc=arjan.van.de.ven@intel.com \
--cc=avihaih@nvidia.com \
--cc=clement.mathieu--drif@eviden.com \
--cc=clg@redhat.com \
--cc=eric.auger@redhat.com \
--cc=giovanni.cabiddu@intel.com \
--cc=jasowang@redhat.com \
--cc=joao.m.martins@oracle.com \
--cc=mark.gross@intel.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rohith.s.r@intel.com \
--cc=xudong.hao@intel.com \
--cc=zhenzhong.duan@intel.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;
as well as URLs for NNTP newsgroup(s).