On Fri, May 19, 2023 at 03:02:24PM +0100, Catalin Marinas wrote: > On Fri, May 19, 2023 at 01:29:38PM +0100, Robin Murphy wrote: > > On 2023-05-18 18:34, Catalin Marinas wrote: > > > + sg_dma_mark_bounced(sg); > > > > I'd prefer to have iommu_dma_map_sg_swiotlb() mark the segments, since > > that's in charge of the actual bouncing. Then we can fold the alignment > > check into dev_use_swiotlb() (with the dev_is_untrusted() condition taking > > priority), and sync/unmap can simply rely on sg_is_dma_bounced() alone. > > With this patch we only set the SG_DMA_BOUNCED on the first element of > the sglist. Do you want to set this flag only on individual elements > being bounced? It makes some sense in principle but the > iommu_dma_unmap_sg() path would need to scan the list again to decide > whether to go the swiotlb path. > > If we keep the SG_DMA_BOUNCED flag only on the first element, I can > change it to your suggestion, assuming I understood it. Can one call: iommu_dma_map_sg(sg, nents); ... iommu_dma_unmap_sg(sg + n, nents - n); (i.e. unmap it in multiple steps) If yes, setting SG_DMA_BOUNCED on the first element only won't work. I don't find this an unlikely scenario, so we maybe we do have to walk the list again in unmap to search for the flag. -- Catalin