qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: "Duan, Zhenzhong" <zhenzhong.duan@intel.com>,
	Avihai Horon <avihaih@nvidia.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"clg@redhat.com" <clg@redhat.com>,
	"mst@redhat.com" <mst@redhat.com>,
	"jasowang@redhat.com" <jasowang@redhat.com>,
	"clement.mathieu--drif@eviden.com"
	<clement.mathieu--drif@eviden.com>,
	"eric.auger@redhat.com" <eric.auger@redhat.com>,
	"joao.m.martins@oracle.com" <joao.m.martins@oracle.com>,
	"Hao, Xudong" <xudong.hao@intel.com>,
	"Cabiddu, Giovanni" <giovanni.cabiddu@intel.com>,
	"Gross, Mark" <mark.gross@intel.com>,
	 "Van De Ven, Arjan" <arjan.van.de.ven@intel.com>
Subject: Re: [PATCH v2 2/8] vfio/iommufd: Query dirty bitmap before DMA unmap
Date: Mon, 20 Oct 2025 20:45:10 +0800	[thread overview]
Message-ID: <e7cdcee2-1df1-40fd-8f46-42e8c75185d1@intel.com> (raw)
In-Reply-To: <IA3PR11MB9136BCC9994E40C674FE495792F5A@IA3PR11MB9136.namprd11.prod.outlook.com>

On 2025/10/20 18:00, Duan, Zhenzhong wrote:
> Hi
> 
>> -----Original Message-----
>> From: Avihai Horon <avihaih@nvidia.com>
>> Subject: Re: [PATCH v2 2/8] vfio/iommufd: Query dirty bitmap before DMA
>> unmap
>>
>> Hi,
>>
>> On 17/10/2025 11:22, Zhenzhong Duan wrote:
>>> External email: Use caution opening links or attachments
>>>
>>>
>>> When a existing mapping is unmapped, there could already be dirty bits
>>> which need to be recorded before unmap.
>>>
>>> If query dirty bitmap fails, we still need to do unmapping or else there
>>> is stale mapping and it's risky to guest.
>>>
>>> Co-developed-by: Joao Martins <joao.m.martins@oracle.com>
>>> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
>>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>>> Tested-by: Xudong Hao <xudong.hao@intel.com>
>>> Tested-by: Giovannio Cabiddu <giovanni.cabiddu@intel.com>
>>> ---
>>>    hw/vfio/iommufd.c | 8 +++++++-
>>>    1 file changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>>> index 976c0a8814..404e6249ca 100644
>>> --- a/hw/vfio/iommufd.c
>>> +++ b/hw/vfio/iommufd.c
>>> @@ -74,7 +74,13 @@ static int iommufd_cdev_unmap(const
>> VFIOContainer *bcontainer,
>>>        if (iotlb && vfio_container_dirty_tracking_is_started(bcontainer)) {
>>>            if
>> (!vfio_container_devices_dirty_tracking_is_supported(bcontainer) &&
>>>                bcontainer->dirty_pages_supported) {
>>> -            /* TODO: query dirty bitmap before DMA unmap */
>>> +            ret = vfio_container_query_dirty_bitmap(bcontainer, iova,
>> size,
>>> +
>> iotlb->translated_addr,
>>> +
>> &local_err);
>>> +            if (ret) {
>>> +                error_report_err(local_err);
>>> +            }
>>> +            /* Unmap stale mapping even if query dirty bitmap fails */
>>>                return iommufd_backend_unmap_dma(be, ioas_id, iova,
>> size);
>>
>> If query dirty bitmap fails, shouldn't we unmap and return the query
>> bitmap error to fail migration? Otherwise, migration may succeed with
>> some dirtied pages not being migrated.
> 
> Oh, good catch. Will make below change:
> 
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -65,7 +65,7 @@ static int iommufd_cdev_unmap(const VFIOContainer *bcontainer,
>       uint32_t ioas_id = container->ioas_id;
>       bool need_dirty_sync = false;
>       Error *local_err = NULL;
> -    int ret;
> +    int ret, unmap_ret;
> 
>       if (unmap_all) {
>           size = UINT64_MAX;
> @@ -82,7 +82,14 @@ static int iommufd_cdev_unmap(const VFIOContainer *bcontainer,
>                   error_report_err(local_err);
>               }
>               /* Unmap stale mapping even if query dirty bitmap fails */
> -            return iommufd_backend_unmap_dma(be, ioas_id, iova, size);
> +            unmap_ret = iommufd_backend_unmap_dma(be, ioas_id, iova, size);
> +
> +            /*
> +             * If dirty tracking fails, return the failure to VFIO core to
> +             * fail the migration, or else there will be dirty pages missed
> +             * to be migrated.
> +             */
> +            return unmap_ret ? : ret;
>           }

do we need a async way to fail migration? This unmap path is not
necessarily in the migration path.

Regards,
Yi Liu


  reply	other threads:[~2025-10-20 12:39 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17  8:22 [PATCH v2 0/8] vfio: relax the vIOMMU check Zhenzhong Duan
2025-10-17  8:22 ` [PATCH v2 1/8] vfio/iommufd: Add framework code to support getting dirty bitmap before unmap Zhenzhong Duan
2025-10-20  7:00   ` Cédric Le Goater
2025-10-20 12:44   ` Yi Liu
2025-10-17  8:22 ` [PATCH v2 2/8] vfio/iommufd: Query dirty bitmap before DMA unmap Zhenzhong Duan
2025-10-20  7:00   ` Cédric Le Goater
2025-10-20  8:14   ` Avihai Horon
2025-10-20 10:00     ` Duan, Zhenzhong
2025-10-20 12:45       ` Yi Liu [this message]
2025-10-20 13:04         ` Avihai Horon
2025-10-21  3:30           ` Yi Liu
2025-10-20 12:44   ` Yi Liu
2025-10-17  8:22 ` [PATCH v2 3/8] vfio/container-legacy: rename vfio_dma_unmap_bitmap() to vfio_legacy_dma_unmap_get_dirty_bitmap() Zhenzhong Duan
2025-10-20  7:00   ` Cédric Le Goater
2025-10-20 12:45   ` Yi Liu
2025-10-17  8:22 ` [PATCH v2 4/8] vfio: Add a backend_flag parameter to vfio_contianer_query_dirty_bitmap() Zhenzhong Duan
2025-10-20  7:01   ` Cédric Le Goater
2025-10-20 12:44   ` Yi Liu
2025-10-17  8:22 ` [PATCH v2 5/8] vfio/iommufd: Add IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag support Zhenzhong Duan
2025-10-20  7:01   ` Cédric Le Goater
2025-10-20 12:45   ` Yi Liu
2025-10-17  8:22 ` [PATCH v2 6/8] intel_iommu: Fix unmap_bitmap failure with legacy VFIO backend Zhenzhong Duan
2025-10-20  7:06   ` Cédric Le Goater
2025-10-20  7:38   ` Yi Liu
2025-10-20  8:03     ` Duan, Zhenzhong
2025-10-20  8:37       ` Yi Liu
2025-10-20 10:01         ` Duan, Zhenzhong
2025-10-17  8:22 ` [PATCH v2 7/8] vfio/migration: Add migration blocker if VM memory is too large to cause unmap_bitmap failure Zhenzhong Duan
2025-10-20  8:39   ` Cédric Le Goater
2025-10-20 10:07     ` Duan, Zhenzhong
2025-10-20 12:44   ` Yi Liu
2025-10-21  8:25     ` Duan, Zhenzhong
2025-10-17  8:22 ` [PATCH v2 8/8] vfio/migration: Allow live migration with vIOMMU without VFs using device dirty tracking Zhenzhong Duan
2025-10-20 12:46   ` Yi Liu

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=e7cdcee2-1df1-40fd-8f46-42e8c75185d1@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --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=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).