Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp394768pxb; Thu, 19 Aug 2021 02:01:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTfip79VjDHbebO8+ThoUimEhtaN+dWr228y0dqe2pRw1TwfDHZs9JTnUAmoRpBylL6FJ5 X-Received: by 2002:a92:2614:: with SMTP id n20mr8157472ile.53.1629363686927; Thu, 19 Aug 2021 02:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629363686; cv=none; d=google.com; s=arc-20160816; b=dOCxXtUz3MByYgF6DFvGhaZkzDqwvk8VjFdkhIov36Foffoiqf6OmmInL714zW6Ppl IOwbmNUYNk3C14dw08mPaAyTjpvi503XskFbRo95FsFa88L1pwqYxPfhfUd8HpwYBxtC G/DrCQCCa3r1sIVpVJ00C3WSJXygS5wElI0t50HwJf9cfHrFQ68TM7FD2YD3EmAUeCZo /R/09YbUXA1TqAbCwp5xgp+B80IJ0pDsUIQnMQ6Q/dMHApCNMrllUiNaEyuCHn/vEdbF zIisVvbzVN/SXvrN0BgPuv/w2nxy6HEz1GqvHOig+Ow7ZSfeq6sBndAdLpl4basuMrcR 269Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=/8Sj1JcSx1E12PGZ91ZjQzCh/pEnaE5j+eHflF8ZWI0=; b=SlvGKpM8BfyOxFLF4D4+J1H8TmXu0ekYVpwjQGkOZVDzJLkz6K0jgKviNMdDmeJBfc MTCyIGFk+cAHIhWFlDJGRd2ohNYCiuEp63PbUeQPXKMnxKaaqRohFfoplsxwrUqv9IOG 6Lvq6RMCNlp74tAs4jZ6ZFJhTgl9knq/FIJZKpBEMfkb2DC93vgBID0pB7BYdkuYenTf 4NpEiXwefoLwMcQkGtIi7r2LshcsdAjEJpgVyWU+Hc42/aU20AvqtvSZp3ZAykIoGAmz 40q/4ASk0Zmwp453GMVDeS48INZITUDqIIXENbhGFaZgaJB77ZwNVa80UE996/eHvZbm hqKQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b13si2662945ilq.35.2021.08.19.02.01.12; Thu, 19 Aug 2021 02:01:26 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbhHSJA1 (ORCPT + 99 others); Thu, 19 Aug 2021 05:00:27 -0400 Received: from foss.arm.com ([217.140.110.172]:33262 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236353AbhHSJA0 (ORCPT ); Thu, 19 Aug 2021 05:00:26 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4C4D01FB; Thu, 19 Aug 2021 01:59:50 -0700 (PDT) Received: from [10.57.36.146] (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1444F3F40C; Thu, 19 Aug 2021 01:59:48 -0700 (PDT) Subject: Re: [PATCH v6 3/7] dma-iommu: skip extra sync during unmap w/swiotlb To: David Stevens , Christoph Hellwig Cc: Joerg Roedel , Will Deacon , Lu Baolu , Tom Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20210817013852.3222824-1-stevensd@google.com> <20210817013852.3222824-4-stevensd@google.com> From: Robin Murphy Message-ID: Date: Thu, 19 Aug 2021 09:59:47 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210817013852.3222824-4-stevensd@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-08-17 02:38, David Stevens wrote: > 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. Reviewed-by: Robin Murphy > 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. >