From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BBCCC4338F for ; Thu, 5 Aug 2021 05:29:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DE9F60F58 for ; Thu, 5 Aug 2021 05:29:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231617AbhHEF0i (ORCPT ); Thu, 5 Aug 2021 01:26:38 -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-Google-Smtp-Source: ABdhPJwliKWoxLiTKjhaiCktAIkaJ/XWbOQ6RdbyHxj8/NjoJYsYviXy+qLt7OPWwt6dfpKxWyMiB9EhxZZyd+mymtc= 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,URIBL_RED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2623FC4338F for ; Thu, 5 Aug 2021 05:26:27 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F63060F58 for ; Thu, 5 Aug 2021 05:26:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8F63060F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 4B9344038A; Thu, 5 Aug 2021 05:26:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2W9VDEtPDpbD; Thu, 5 Aug 2021 05:26:25 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 2CCB740266; Thu, 5 Aug 2021 05:26:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 09371C0010; Thu, 5 Aug 2021 05:26:25 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id B3F7FC000E for ; Thu, 5 Aug 2021 05:26:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A8C35402EA for ; Thu, 5 Aug 2021 05:26:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NbHw7FyS-NWd for ; Thu, 5 Aug 2021 05:26:23 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by smtp4.osuosl.org (Postfix) with ESMTPS id E75B140266 for ; Thu, 5 Aug 2021 05:26:22 +0000 (UTC) Received: by mail-qv1-xf29.google.com with SMTP id s11so2366554qvz.7 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=SjZqpR73+Hq7FaJeDbhxqod8tGXONvvHXLFYNP4OFp0yiZcqqSVCKUrgJRfhYtgVRp vPmIiFBZv4H9871GNy1dNKmQHn7c5s2IXMp97UO77U+PWDuGj4RR+Mut3F8aHKhxtYcl ZJJ0WFFh0f9xSOp8ktBy6kmo/AqI8xbPKAfkopjBnMDZeMKQXu4JyEh84u5sFKx98Sbf wsOB1ieY4yTB9ooim2552nkF0D9WDzmlsSYYZnLge128nvuUjrKsaPby0taKQ+LR1oFJ y1MxKxYny/b8rYU5HIHr2FZt75b4g8ImcPvlxEoMEHpeArA/5NXrEOhs6wjehCIsyMig 9v8Q== X-Gm-Message-State: AOAM532V+m6C2MSB6bVqoJzUO7zYFlAqUOlzojIpVpLOKlpQ4hIpc6xg usYvpyzBTPtIfBM/2hOe634lnuqc8cWO+YOlVoYOTA== X-Google-Smtp-Source: ABdhPJwliKWoxLiTKjhaiCktAIkaJ/XWbOQ6RdbyHxj8/NjoJYsYviXy+qLt7OPWwt6dfpKxWyMiB9EhxZZyd+mymtc= 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: open list , Tom Murphy , iommu@lists.linux-foundation.org, Robin Murphy X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" 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 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu