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.6 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,USER_AGENT_GIT autolearn=unavailable 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 D99C7C432BE for ; Tue, 17 Aug 2021 01:39:38 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 9E89660E90 for ; Tue, 17 Aug 2021 01:39:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9E89660E90 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 smtp1.osuosl.org (Postfix) with ESMTP id 7237A81026; Tue, 17 Aug 2021 01:39:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pTPLepSL-4TU; Tue, 17 Aug 2021 01:39:34 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1B7E08105B; Tue, 17 Aug 2021 01:39:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E9383C001A; Tue, 17 Aug 2021 01:39:30 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5A51FC000E for ; Tue, 17 Aug 2021 01:39:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 55A7E402C9 for ; Tue, 17 Aug 2021 01:39:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=chromium.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 35U03vodC22L for ; Tue, 17 Aug 2021 01:39:26 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by smtp2.osuosl.org (Postfix) with ESMTPS id 56E14402DF for ; Tue, 17 Aug 2021 01:39:26 +0000 (UTC) Received: by mail-pl1-x62f.google.com with SMTP id q2so22843387plr.11 for ; Mon, 16 Aug 2021 18:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rTpdRIu7FpzvBFJwAANhpBrL0QFcTu4ptjq1LAtftzQ=; b=ezZ42GIRfs9eXpeKCSPeUfZMHb1oY8KWX1Zmv/qEJMLBhMLRgHr4ZHj2Iyx5HQ3MmP Z3PYeWqP7NNkbRmfxJEvAHQaFiGbsIfNDRy7t/gkJPLdNtYfYZu8fZwd6DiaBo5hQSE2 I2c4PNhFo9A9maeFjR1CnjRPPIzbjxogbUd/U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rTpdRIu7FpzvBFJwAANhpBrL0QFcTu4ptjq1LAtftzQ=; b=VnKlE6LJvbSblO8Gak3U+wRuHn8h2k74c6azCeXGPgprbBhFy4phN7tLs5SdPEbAgk O9F4EAnWIDPsbNcrlmCmPOMNaYi3lbrx9uEUkTuIZ0qjQx7tYOgSBmCFgPDzq+uwIoeh c66m/uk57u32sKMkAkaWTdXRt1VuFszPhKWOvPaT14a+LiX4F99n8A/28m6NCbk7+zOh NA3vME8GJAU+Us77S53IObwEHQ71e6PUky1CdWKtGJCDM2dUK363CX0eYCOK0N1dX3Dt eCssVNJ3lx61GVIz/g3mb6qABf/JBzQP3a1jAJarUONQOgZ27HpOiwrbFtCq8sdu0Xll Vr4g== X-Gm-Message-State: AOAM530riaRHnr77uxSHnxEhqglSbABF+4y5kyUsmNn5YBrkG0nrDyx3 uRAfclfqcBvYu8KCoiXSbhumdg== X-Google-Smtp-Source: ABdhPJzHt0Q3iODtQezPrYHRIiO+4+NDCtHq9DghJp3azP1e9Y6fx29b/XrikZInLJlJdBmZNNDH2A== X-Received: by 2002:a17:90a:d181:: with SMTP id fu1mr838875pjb.137.1629164365817; Mon, 16 Aug 2021 18:39:25 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:6864:767c:2ff8:749d]) by smtp.gmail.com with UTF8SMTPSA id n185sm409593pfn.171.2021.08.16.18.39.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Aug 2021 18:39:25 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Robin Murphy , Christoph Hellwig Subject: [PATCH v6 3/7] dma-iommu: skip extra sync during unmap w/swiotlb Date: Tue, 17 Aug 2021 10:38:48 +0900 Message-Id: <20210817013852.3222824-4-stevensd@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210817013852.3222824-1-stevensd@google.com> References: <20210817013852.3222824-1-stevensd@google.com> MIME-Version: 1.0 Cc: linux-kernel@vger.kernel.org, Tom Murphy , iommu@lists.linux-foundation.org, David Stevens , Will Deacon 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" From: David Stevens Calling the iommu_dma_sync_*_for_cpu functions during unmap can cause two copies out of the swiotlb buffer. Do the arch sync directly in __iommu_dma_unmap_swiotlb instead to avoid this. This makes the call to iommu_dma_sync_sg_for_cpu for untrusted devices in iommu_dma_unmap_sg no longer necessary, so move that invocation later in the function. Signed-off-by: David Stevens Reviewed-by: Christoph Hellwig --- drivers/iommu/dma-iommu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 8098ce593640..5dd2c517dbf5 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -504,6 +504,9 @@ static void __iommu_dma_unmap_swiotlb(struct device *dev, dma_addr_t dma_addr, if (WARN_ON(!phys)) return; + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && !dev_is_dma_coherent(dev)) + arch_sync_dma_for_cpu(phys, size, dir); + __iommu_dma_unmap(dev, dma_addr, size); if (unlikely(is_swiotlb_buffer(phys))) @@ -853,8 +856,6 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, static void iommu_dma_unmap_page(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction dir, unsigned long attrs) { - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) - iommu_dma_sync_single_for_cpu(dev, dma_handle, size, dir); __iommu_dma_unmap_swiotlb(dev, dma_handle, size, dir, attrs); } @@ -1062,14 +1063,14 @@ static void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, struct scatterlist *tmp; int i; - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) - iommu_dma_sync_sg_for_cpu(dev, sg, nents, dir); - if (dev_is_untrusted(dev)) { iommu_dma_unmap_sg_swiotlb(dev, sg, nents, dir, attrs); return; } + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + iommu_dma_sync_sg_for_cpu(dev, sg, nents, dir); + /* * The scatterlist segments are mapped into a single * contiguous IOVA allocation, so this is incredibly easy. -- 2.33.0.rc1.237.g0d66db33f3-goog _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu