On 08/08/2025 11:06, Duan, Zhenzhong wrote:
>>> Introduce a helper vfio_device_dirty_pages_disabled() to facilicate it.
>>>
>>> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com>
>>
>> This is unfortunately not enough to unblock vIOMMU migration with
>> IOMMUs.
>> Have a look at the first four patches of this series:
>>
>>      https://github.com/jpemartins/qemu/commits/vfio-migration-viommu/
>>
>> These 4 are meant do this (41d778dda00^..d27e5a5db5f4). Feel free to pick
>> them
>> up. I hope to take care of the rest of the series; though I have been heavily
>> preempted internally that I hadn't had the time to clear this series but I 
>> think
>> it's finally coming to an end
> 
> Thanks, that help much, we have internal team in intel needing this relax with
> vIOMMU enabled.
> I'll pick your first 4 patches with mine and send an update.
> 

OK

>>
>> The gist of these first four patches is essentially that we need to query the
>> dirty bitmap before unmap, and we have an extra optimization that let us
>> simply
>> read the Dirty bit (without clearing it) and so the query is much faster as 
>> you
>> don't have a TLB flush.
> 
> I see the legacy backend use dma_unmap_bitmap to do the same thing in one 
> ioctl(),
> will you add that support in kernel?
> IIUC, between query and unmap, there is a window in which we will miss dirty 
> pages
> if a buggy guest still raises DMA.
> 

No. My first version of the kernel patches had something like this (but not
quite done fully correctly), but we deliberately not handle it and we accepted
that race ... as it was a theoretical use-case and not worth the cost/complexity
it would bring i.e. we would have to write protect the IOPTE, flush, then read
the dirty bits and then unmap (for something we are not aware it exists).

See commit 609848132c71 ("iommufd: Add a flag to skip clearing of IOPTE dirty")
for the history and inside there's a link to the thread to the discussion.

This flag is meant to make it easier to get dirty bits given the next operation
is the unmap which will do TLB flush (and also destroy the dirty bit).

        Joao

Reply via email to