On 2023/2/13 10:24, Tian, Kevin wrote:
From: Jason Gunthorpejgg@nvidia.com Sent: Saturday, February 11, 2023 8:45 AM
On Fri, Feb 10, 2023 at 04:51:10PM -0700, Alex Williamson wrote:
On Tue, 7 Feb 2023 13:17:54 -0800 Nicolin Chennicolinc@nvidia.com wrote:
qemu has a need to replace the translations associated with a domain when the guest does large-scale operations like switching between an IDENTITY domain and, say, dma-iommu.c.
Currently, it does this by replacing all the mappings in a single domain, but this is very inefficient and means that domains have to be per-device rather than per-translation.
Provide a high-level API to allow replacements of one domain with another. This is similar to a detach/attach cycle except it doesn't force the group to go to the blocking domain in-between.
By removing this forced blocking domain the iommu driver has the opportunity to implement an atomic replacement of the domains to the greatest extent its hardware allows.
It could be possible to adderss this by simply removing the protection from the iommu_attach_group(), but it is not so clear if that is safe for the few users. Thus, add a new API to serve this new purpose.
Atomic replacement allows the qemu emulation of the viommu to be
more
complete, as real hardware has this ability.
I was under the impression that we could not atomically switch a device's domain relative to in-flight DMA.
it's possible as long as the mappings for in-flight DMA don't change in the transition.
It also requires the mappings in old and new domains are identical. In another word, any IOVA should be translated to a same result no matter through the old domain, the new domain, or hardware caches.
A similar replacement has been implemented in the code. For example, the Intel IOMMU driver dynamically transforms a large range (2M or 1G) mapping from discrete 4k pages to a super pages to improve the paging cache efficiency.
Best regards, baolu