Re: [PATCH v2 3/4] dma-iommu: pass SKIP_CPU_SYNC to swiotlb unmap
From: Will Deacon
Date: Fri Aug 06 2021 - 07:38:13 EST
On Thu, Aug 05, 2021 at 02:26:10PM +0900, David Stevens wrote:
> On Mon, Aug 2, 2021 at 10:54 PM Will Deacon <will@xxxxxxxxxx> wrote:
> >
> > On Fri, Jul 09, 2021 at 12:35:01PM +0900, David Stevens wrote:
> > > From: David Stevens <stevensd@xxxxxxxxxxxx>
> > >
> > > If SKIP_CPU_SYNC isn't already set, then iommu_dma_unmap_(page|sg) has
> > > already called iommu_dma_sync_(single|sg)_for_cpu, so there is no need
> > > to copy from the bounce buffer again.
> > >
> > > Signed-off-by: David Stevens <stevensd@xxxxxxxxxxxx>
> > > ---
> > > drivers/iommu/dma-iommu.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> > > index e79e274d2dc5..0a9a9a343e64 100644
> > > --- a/drivers/iommu/dma-iommu.c
> > > +++ b/drivers/iommu/dma-iommu.c
> > > @@ -505,7 +505,8 @@ static void __iommu_dma_unmap_swiotlb(struct device *dev, dma_addr_t dma_addr,
> > > __iommu_dma_unmap(dev, dma_addr, size);
> > >
> > > if (unlikely(is_swiotlb_buffer(phys)))
> > > - swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs);
> > > + swiotlb_tbl_unmap_single(dev, phys, size, dir,
> > > + attrs | DMA_ATTR_SKIP_CPU_SYNC);
> > > }
> >
> > I think it would be cleaner to drop DMA_ATTR_SKIP_CPU_SYNC in the callers
> > once they've called iommu_dma_sync_*_for_cpu().
>
> Dropping that flag in iommu_dma_unmap_* would result in always copying
> from the swiotlb here, which is the opposite direction of what this
> patch is trying to do.
Sorry, probably poor wording on my part. What I mean is, rather than add
DMA_ATTR_SKIP_CPU_SYNC here, how about having the callers include it
in attrs instead, since they're the ones doing the initial sync?
Will