Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp275328pxt; Wed, 4 Aug 2021 22:37:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE0oC6gn0PMMoUF1ONiRUln2x1Zl5WseIATHxZfUYoJFGH5W09NptktzK50tyja01hLWdj X-Received: by 2002:a17:906:616:: with SMTP id s22mr3016394ejb.210.1628141868897; Wed, 04 Aug 2021 22:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628141868; cv=none; d=google.com; s=arc-20160816; b=Zrxmk54C/anIXHDT4TfzpKGw3m7Y03/fPudfTRFjZuNvhpQzGCEgU3UcOuIEQDDTu/ 9M+J0vTmTyvMQFScKMR8kuWN2fhLOgsguL48fBncYw+gpTbIBf4LpBN0ISoXIkCxaZtV +3xGy7trdwpWh29IefOJxXPM4eELHHywV80H9MvzkPZ4iN8OfY4WYQbWfIDTVKzScsrf VYhnsh5ymqnJUpMPoJoK3n7OIeBa1meEj7RQx1/p97AluUaHbMsuBph/H2THcRiBwntS 9DheusKWg2h0FhvYZE8Sgve5NvCCx2EJ2hPZLslL8TkxIOpjOM+Lj8CL/Xp7OhzQoQLv KtCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SAWYlvs5XtqLwUaEqS2qwqUPDupygtRRMcwg/DOIhsg=; b=VaEo3ekjRpGUuVRALoDXIHouQy7k1nUrQqQPJ/pRYe+qXJmQr5cS5MGI/gVbo4v1Yi QdiyPh9gsoPQLtBddo39j1uuk57DJkXmvltxS6q4Vme7Y6S0jwXT5ceX9fQeMFBIPmuc WkQw9AwDhsO/dm6y4bvPp/dnx1mpb0ZTrypLVxhNW5B64hSkMF0c1bLjTqO741ugQGNv ebQw740DtMugvNdEC/wG+41oX7rLK2lfjQI7YRga3Bta4fgrB5Khqa0BRhofBLYpDDYl tFYIYZLrKBxWrEqZCLRl2MKBxhbMAKzGoAWM4m/9QOu5GmsHpSdhY662N93K7VrqyyPG jw1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nPobvWYZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w27si4323849ejf.294.2021.08.04.22.37.23; Wed, 04 Aug 2021 22:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nPobvWYZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbhHEF0h (ORCPT + 99 others); Thu, 5 Aug 2021 01:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbhHEF0h (ORCPT ); Thu, 5 Aug 2021 01:26:37 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ED82C061765 for ; Wed, 4 Aug 2021 22:26:22 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id g6so2361581qvj.8 for ; Wed, 04 Aug 2021 22:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SAWYlvs5XtqLwUaEqS2qwqUPDupygtRRMcwg/DOIhsg=; b=nPobvWYZhXvZVrEvTwMU2dN2uActZpK/cmTowjhr6t4tZ/uQJTV2sYljb33SV3+52s RaEEuEtlXJg0GNli7EjvCKg1OdX457q6ggegb6fm0jHB0hquE0l21h7u4prEoW3YJUIZ +vSH8yX8Y0CNRYy1NI4biFTXdCLBLa5M10cBw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SAWYlvs5XtqLwUaEqS2qwqUPDupygtRRMcwg/DOIhsg=; b=F6/ozJ+/qMu39WJfYBbmQaaEXRgwCODMGw/VzrwSk2dDrCy8DAx/vwnJ/WI+mCKdT6 9lGF5Z0vryqRLQUhhyj3MoPSvsKOO3v0nE3GL6IXAXzCoyci886WyrGnHScsKK11ggpH WbADyDWcTobSSR6dKJjHqGLUtnDP9fDIYeZ2ne7PQM1eJ2qL9F8OFqPoaFgfspbTdAHi 0ikS1L6pESf1t0jSsyf3zxO5CcbjlAxUJ+GGzUPGBY/x2KPpnAdDKk0Un3XBPsDUcAqi K2jcV0Tl+e2BnMWHzrr0v2CdRSlefp2yoW4H6lPmR4s0CKU9tTRD1dlqHyxpm3akcQAA J8aQ== X-Gm-Message-State: AOAM530OvCH2laa+T5cRWhhpE3xlP3TXu4HLSLjUqmcl793to7ntjlNy S7BzzYI4oDEzvtkiowogJ+ExL9Tcpx32V1rGrP4rIw== X-Received: by 2002:a05:6214:e4e:: with SMTP id o14mr3391377qvc.55.1628141181770; Wed, 04 Aug 2021 22:26:21 -0700 (PDT) MIME-Version: 1.0 References: <20210709033502.3545820-1-stevensd@google.com> <20210709033502.3545820-4-stevensd@google.com> <20210802135446.GE28547@willie-the-truck> In-Reply-To: <20210802135446.GE28547@willie-the-truck> From: David Stevens Date: Thu, 5 Aug 2021 14:26:10 +0900 Message-ID: Subject: Re: [PATCH v2 3/4] dma-iommu: pass SKIP_CPU_SYNC to swiotlb unmap To: Will Deacon Cc: Robin Murphy , Joerg Roedel , Lu Baolu , Tom Murphy , iommu@lists.linux-foundation.org, open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 2, 2021 at 10:54 PM Will Deacon wrote: > > On Fri, Jul 09, 2021 at 12:35:01PM +0900, David Stevens wrote: > > From: David Stevens > > > > 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 > > --- > > 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. This change is aiming to address the case where DMA_ATTR_SKIP_CPU_SYNC isn't passed to dma_unmap_*. In that case, there are calls to swiotlb_sync_single_for_cpu from iommu_dma_sync_*_for_cpu, and calls to swiotlb_tlb_unmap_single here. That means we copy from the swiotlb twice. Adding the DMA_ATTR_SKIP_CPU_SYNC flag here skips the second copy. -David > Will