> From: Zhao, Yan Y <yan.y.zhao@xxxxxxxxx> > Sent: Monday, May 13, 2024 3:11 PM > On Fri, May 10, 2024 at 10:57:28AM -0600, Alex Williamson wrote: > > On Fri, 10 May 2024 18:31:13 +0800 > > Yan Zhao <yan.y.zhao@xxxxxxxxx> wrote: > > > > > > The dma->cache_flush_required is to mark whether pages in a vfio_dma > requires > > > cache flush in the subsequence mapping into the first non-coherent > domain > > > and page unpinning. > > > > How do we arrive at a sequence where we have dma- > >cache_flush_required > > that isn't the result of being mapped into a domain with > > !domain->enforce_cache_coherency? > Hmm, dma->cache_flush_required IS the result of being mapped into a > domain with > !domain->enforce_cache_coherency. > My concern only arrives from the actual code sequence, i.e. > dma->cache_flush_required is set to true before the actual mapping. > > If we rename it to dma->mapped_noncoherent and only set it to true after > the > actual successful mapping, it would lead to more code to handle flushing for > the > unwind case. > Currently, flush for unwind is handled centrally in vfio_unpin_pages_remote() > by checking dma->cache_flush_required, which is true even before a full > successful mapping, so we won't miss flush on any pages that are mapped > into a > non-coherent domain in a short window. > What about storing a vfio_iommu pointer in vfio_dma? Or pass an extra parameter to vfio_unpin_pages_remote()...