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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80C94C4332F for ; Mon, 7 Nov 2022 10:54:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C19366B0071; Mon, 7 Nov 2022 05:54:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF17C6B0072; Mon, 7 Nov 2022 05:54:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B06DA8E0001; Mon, 7 Nov 2022 05:54:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9D0D96B0071 for ; Mon, 7 Nov 2022 05:54:45 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7811F1C66FA for ; Mon, 7 Nov 2022 10:54:45 +0000 (UTC) X-FDA: 80106338130.27.31E0345 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 26827140005 for ; Mon, 7 Nov 2022 10:54:44 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 26EAD60F99; Mon, 7 Nov 2022 10:54:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09D53C433D6; Mon, 7 Nov 2022 10:54:39 +0000 (UTC) Date: Mon, 7 Nov 2022 10:54:36 +0000 From: Catalin Marinas To: Christoph Hellwig Cc: Linus Torvalds , Arnd Bergmann , Greg Kroah-Hartman , Will Deacon , Marc Zyngier , Andrew Morton , Herbert Xu , Ard Biesheuvel , Isaac Manjarres , Saravana Kannan , Alasdair Kergon , Daniel Vetter , Joerg Roedel , Mark Brown , Mike Snitzer , "Rafael J. Wysocki" , Robin Murphy , linux-mm@kvack.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3 03/13] iommu/dma: Force bouncing of the size is not cacheline-aligned Message-ID: References: <20221106220143.2129263-1-catalin.marinas@arm.com> <20221106220143.2129263-4-catalin.marinas@arm.com> <20221107094603.GB6055@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221107094603.GB6055@lst.de> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667818485; a=rsa-sha256; cv=none; b=sTjwHNe1omnUge0fBOEeYpeZye2v3lmmkX+SkMHgDk+KfqcRIoE7SQcnUnQFdIqOtnFhuJ 9O9jTfzZyXtO9uTgBvS/80eYcumz0KUs9N931Z/gcIILQksQ6T6ImTuATq/UTeFVzPrwL0 0VDe3jsZlg5dtLRD9uhvaF7f2W+b5ww= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667818485; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EKvMDt8vRKWvSHRbFY3DuaLiQJSo9UQUtdKsUxe6xMM=; b=uw2ji0TLixqjiDP5LB5cnAz8kD8yuYUfsfbMdTAoaDQRUXAQLD17MoSJaUPqZxeLAv/8fV sORb8ysgn3qByjew0wrRQDgbQRjSs6LJhX0A6hTINuqhuVR3rZjEPxfY9k1Uw+BzMdBZ62 7wM1WbaNb50WY3X8fcpkmMFy2jryhB8= X-Stat-Signature: 9dapswpz8qxfx7f7ko71n885io7rf93j X-Rspamd-Queue-Id: 26827140005 Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1667818484-523518 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Nov 07, 2022 at 10:46:03AM +0100, Christoph Hellwig wrote: > > +static inline bool dma_sg_kmalloc_needs_bounce(struct device *dev, > > + struct scatterlist *sg, int nents, > > + enum dma_data_direction dir) > > +{ > > + struct scatterlist *s; > > + int i; > > + > > + if (!IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) || > > + dir == DMA_TO_DEVICE || dev_is_dma_coherent(dev)) > > + return false; > > This part should be shared with dma-direct in a well documented helper. > > > + for_each_sg(sg, s, nents, i) { > > + if (dma_kmalloc_needs_bounce(dev, s->length, dir)) > > + return true; > > + } > > And for this loop iteration I'd much prefer it to be out of line, and > also not available in a global helper. > > But maybe someone can come up with a nice tweak to the dma-iommu > code to not require the extra sglist walk anyway. An idea: we could add another member to struct scatterlist to track the bounced address. We can then do the bouncing in a similar way to iommu_dma_map_sg_swiotlb() but without the iova allocation. The latter would be a common path for both the bounced and non-bounced cases. -- Catalin