Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3320089pxb; Sun, 29 Aug 2021 22:02:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvg+hggPwjOFWqPWUvRYfKPJVoqmwa5s1s/WSrPraZGPCe7HO7i7qBdeyyMYq7p4PUqF7E X-Received: by 2002:a17:907:2083:: with SMTP id pv3mr22812984ejb.402.1630299744947; Sun, 29 Aug 2021 22:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630299744; cv=none; d=google.com; s=arc-20160816; b=osvQuV+4dpeccsbj2T1lCQZHALkX36nIjrtNlLBMTB0mMohiIfAfuWZ2sP1Tzeji0z JRPKS4vF4A1sZzAYIumcvgXcttq+kElH0gG5VoyLVU6BJvVIKYs6g4uARf2LIpxLOisW sCLZ/U2RXcW2ljFAZQY9IUpOPKaYILjZxfmcQAzyxcFZtqGpaFXkmza91jZc0keM0XqR RJHmFRbptOFPwwagAbFasUFsWhTfPJuXxiawYR+dxQWhM0pFE0AAsT+gBcmUzVhWqBaV Dcma5hurtdaXh3SMDg81SG8BapuFhhYwxLHnthxMKvEZ1/jG+eDejdXLdxJSuhY/MKgX U/GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p0M0LPeLb2bO15/S2RN1fSV7prFIeL6kElwekRN6sTw=; b=YPQw0WjLNCAo/bYAuhTdGxlY+R+OXNi7e1eQ3LixFTwMKrNvXH4ywKXGZoV/GS4RSo KY2Sqa+HgJnIeiSw9EpLzMHBQ9E697LCji3PJEfIProDr+gk6Aliw6PbgT+/kdiThAp0 ahP3GawxuIqTdhYSe/OIp3DmDdrDVP285qEz+UrXBPEF2Zpm0G+rUL6+aFz9E8RlFgi8 8CYYnfkuK+xG6YQgL6TeKnJumSOAvOBBO/XwHTHZCpeIDU4H40DWb6PCmBa1IQmXqVsu ZKa4N+8pdj1Cy27cMbx+TqmOhtj0epiBDqZFOIcRjOHvTlwoIG9piaWGNoF2pMCjApy+ wZmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S3yczAZA; 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 s10si13972278edw.319.2021.08.29.22.02.02; Sun, 29 Aug 2021 22:02:24 -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=S3yczAZA; 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 S231404AbhH3FBa (ORCPT + 99 others); Mon, 30 Aug 2021 01:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231584AbhH3FBQ (ORCPT ); Mon, 30 Aug 2021 01:01:16 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ACD5C061756 for ; Sun, 29 Aug 2021 22:00:23 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id x4so12305623pgh.1 for ; Sun, 29 Aug 2021 22:00:23 -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=p0M0LPeLb2bO15/S2RN1fSV7prFIeL6kElwekRN6sTw=; b=S3yczAZAkq/yaayh+fEIYgG+OGimGvZhH5pW0o5+iovC3ow6Pk74+0Zxt6ggbkLOWo jgqbWPwxirW+0jI7jK/G+8PoBahK0AljG8xIU1D9eBSChiDAi+8LgtjP5FTYzbLou8HO 8eaM4Z7+N/BJtFEUFc/6fL1rKFHNVJoC+DVk4= 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=p0M0LPeLb2bO15/S2RN1fSV7prFIeL6kElwekRN6sTw=; b=jnEkQAAWM6eLnqboTwu4JzxPntfHvXzRPDP9EALSxHl+1blSsQRGxYRUD5RsT7LC+J urYzc1UIWS98v7BABMnWTo8qbmHWo8RtEco2eL1DpQD5IJsyu3MmC4KI6GV51cFjs26t 2IBe6sq7rjV9hWMXJQsPIHAInEt0Wnuy2aFSPK1nRjPBgvKpN5mhA2QOyQpZcz9y+LvZ 3/UMKGWAAhkNjNgG8ibLrefCk7B9MDJM+51GzCMoF/TdngEfP51BDl5Mcq4HPqfvPlEu Hegdpmzdg1q246K/Uk7z/jPqap5sXtjAhG5nkWRrxQmSLSY2/rtymoXNfyK3Wm1a9rY3 Lfkg== X-Gm-Message-State: AOAM53347V4e9CF2PNQkYeXZnbfU3+bA8urDNa3lDMwaNNWG7aTOLiUt //Z/rCZxg8+ZihfSk64XfsfaFA== X-Received: by 2002:a05:6a00:228a:b0:3e1:a0b2:535b with SMTP id f10-20020a056a00228a00b003e1a0b2535bmr21407462pfe.5.1630299623159; Sun, 29 Aug 2021 22:00:23 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:28a5:1b9f:af1d:5542]) by smtp.gmail.com with UTF8SMTPSA id q21sm15506738pgk.71.2021.08.29.22.00.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Aug 2021 22:00:22 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Robin Murphy , Christoph Hellwig Cc: Joerg Roedel , Will Deacon , Lu Baolu , Tom Murphy , Rajat Jain , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, David Stevens Subject: [PATCH v7 3/7] dma-iommu: skip extra sync during unmap w/swiotlb Date: Mon, 30 Aug 2021 13:59:21 +0900 Message-Id: <20210830045925.4163412-4-stevensd@google.com> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210830045925.4163412-1-stevensd@google.com> References: <20210830045925.4163412-1-stevensd@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Robin Murphy --- 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 12197fdc3b1c..abc528ed653c 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -521,6 +521,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))) @@ -870,8 +873,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); } @@ -1079,14 +1080,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.259.gc128427fd7-goog