Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1633871pxy; Mon, 2 Aug 2021 06:43:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGBiAYmuPFWWPKkuvKaKt9rhO+5yV6DI+Fr79pJ7eZP4/h371+XhmeJgBw+taOqJkBIG7U X-Received: by 2002:a05:6638:3824:: with SMTP id i36mr15017907jav.11.1627911782122; Mon, 02 Aug 2021 06:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627911782; cv=none; d=google.com; s=arc-20160816; b=aOjgTT3vlzTi5cJYYAfhOBaytrwwTxFhs5KZOBUZmXNekwc6Z3pXPLNygLLE8uRtNy sCY0JczIW/qgTOdBC8XLJfPjGaFGmZBxEvakpt2WDI8U3yQPnGdyT3WAEr+AN9U33boz /JWqQa7Gq1k/D7PkFJSupyVOb/6VU2T5OQyS8j9qOwULMwXk0edL6xRtuaO51IXi/u+y v/RPk6Xm30MkH+hfaDeuc4Js3zwCrN4MJMKjIeLaGrc3f4xMxHXs5XjuRTvebC5oleN9 QRs8FGM4GS6JIfHmcKO9j2++QWZaueWqaNjmfwaP8B6vfm53zwgLNIOyo/gipP4sFPCA 8yZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=YaiDc9tfBeW0I1HtFWfj+xEFHxy4ziQ14NGtEJeW/ww=; b=LeZ6NaOH4V1vZarocbWfok/xq71Y6l+MTagG0jranIVMiZoXxuu5NofCKi4wVwXymn KWMkMyDMtX1p+Jab4UtHe2snJbNVq36UhFLlxWxTQjfNfcDXoFA9i4Y/3vnmXUPvIQff GfTw52YMgBucHsTjacZPz17Kb4wdfhZ4swZDyB8wRhMJ+18olRrWkEUdRftHBPx3uEt2 SKbQ5WQ9nBNzkNyjFyXROKWJLGzonqdZqzQEFFWyHorY9wMTp2rrPkT5Y1VMzYQMQ7NK 3u4bQ7uOQWngdE6O6cX6fIzaLnBqy/E2SB+nP+3l8IrAN10u/IGiB4lRAmX/1dc7N3Bi ZXuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="d/64efJ5"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si8927577ilq.19.2021.08.02.06.42.50; Mon, 02 Aug 2021 06:43:02 -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=@kernel.org header.s=k20201202 header.b="d/64efJ5"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233875AbhHBNlO (ORCPT + 99 others); Mon, 2 Aug 2021 09:41:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:53164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233826AbhHBNlN (ORCPT ); Mon, 2 Aug 2021 09:41:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 33C2760527; Mon, 2 Aug 2021 13:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627911664; bh=T6TWUTiAj92VMQeo9D2L0JR2kOWfrkEOeOZopIPa0VE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d/64efJ5zA/m+402dzhCDuHrU2jY302WfZWrU+aWmVSFHB1r9t/c9Ab73NR7fKLfe IoAEEoJQ30itvaAF29kVH6quNSN4mjIxSxmydFAcKu51wVrt6JsExy0KpsL9Ri8mT/ iqBVItJ5uzfqnkHnB8CnRj5GQ3mj7oAt/r8joL1VY0vXNpBjh4N0ZwIbNDKBNOBvk6 X20sNlhtmkKu1Dfmp0IdqZB32qAbKqSIax+SRATS7pS+pAZ8fG0zMQ+YD+rY03DsDq csW0RHmrSHGsDqA+wlyUfpWOpADzoo0GYh7LcIuXlSKtrAHWTU8HLodoysKTKP2nJn req52quV0YsyA== Date: Mon, 2 Aug 2021 14:40:59 +0100 From: Will Deacon To: David Stevens Cc: Robin Murphy , Joerg Roedel , Lu Baolu , Tom Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/4] dma-iommu: fix arch_sync_dma for map with swiotlb Message-ID: <20210802134059.GC28547@willie-the-truck> References: <20210709033502.3545820-1-stevensd@google.com> <20210709033502.3545820-3-stevensd@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210709033502.3545820-3-stevensd@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 09, 2021 at 12:35:00PM +0900, David Stevens wrote: > From: David Stevens > > When calling arch_sync_dma, we need to pass it the memory that's > actually being used for dma. When using swiotlb bounce buffers, this is > the bounce buffer. Move arch_sync_dma into the __iommu_dma_map_swiotlb > helper, so it can use the bounce buffer address if necessary. This also > means it is no longer necessary to call iommu_dma_sync_sg_for_device in > iommu_dma_map_sg for untrusted devices. > > Fixes: 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") > Signed-off-by: David Stevens > --- > drivers/iommu/dma-iommu.c | 16 +++++++--------- > 1 file changed, 7 insertions(+), 9 deletions(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index eac65302439e..e79e274d2dc5 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -574,6 +574,9 @@ static dma_addr_t __iommu_dma_map_swiotlb(struct device *dev, phys_addr_t phys, > memset(padding_start, 0, padding_size); > } > > + if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) > + arch_sync_dma_for_device(phys, org_size, dir); I think this relies on the swiotlb buffers residing in the linear mapping (i.e. where phys_to_virt() is reliable), which doesn't look like a safe assumption to me. Will