Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3030059pxb; Mon, 4 Apr 2022 06:12:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRBTN2E5y+I6EnshVz2Jc21kNs80ZXrq1uWvAasi8LhxcozkU99JYX8Tzgj6s1arE93dpp X-Received: by 2002:a17:90a:888:b0:1ca:a9ac:c866 with SMTP id v8-20020a17090a088800b001caa9acc866mr2890961pjc.203.1649077960845; Mon, 04 Apr 2022 06:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649077960; cv=none; d=google.com; s=arc-20160816; b=ibqMPNIdEPzxVZ9P6sFLi29XPrDYKs9KuLAnc3VMuFxYBNT9bWxA8PpY7Am03OKae4 fP9vDls5NG4FhQVR8mfdsM2Yx9ZhBGox0oz+eKvQuagzb2FopCKSEqi6NhWpFbJPS8K9 muuKFfFsN1NI6VXDsZ3NokiCTTtYqhtQfq00AENcG3xUoqWUHO8gCVTr12p347t93I6N eCQfEdSW9CIkfvj9beOjKrpwoLmoDG1kySTMysLKnKfCLCu0xEXonSgYksrLzIkJZ2eZ 7I24Igl5oJXnk+GcFaUMU6Y5OzsskikeBP5bt1fdTvyGYRmegd1NtbG7Zx7GIu6Upocq 9cDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature:dkim-signature; bh=UxpE6QuX00X/HUxMRxKCgBvn/5U8Qx/FUyad3eii1Ig=; b=LrcCOhKkkSHufjsK1f9lZ/jT6dVnqYxzf1k/f2eNPlBk0lBvELx0HNeaTKYMA//d/C K3KIdXIkBZb1MlczRsX7f09lj+ljO0tApaYbI4f4A7cL5++jr8VRDequ/SxQ76XLaMht x66fQrNypBgqQVwj2FNHalRjPR4VMQgasj326XPHZRQzSSHVaXKHyUYnnOje4JI/89SK JGzrKDq0ONXdTBGIF9uVCNAZWPx+CIbao1WTQ5xvJND59QBF1lcagvT7VWbL3vcj9ZrA PxszuScaZcpM5qE1NiKiye7RsZjrV6m0m21awcHk/iUdrTZKzp3HqzwAl3GTML35hYMl GuKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=NRVaLuof; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=MwFajUTb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170903244900b00156a405c568si3161783pls.231.2022.04.04.06.12.22; Mon, 04 Apr 2022 06:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=NRVaLuof; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=MwFajUTb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351836AbiDBMmm (ORCPT + 99 others); Sat, 2 Apr 2022 08:42:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243665AbiDBMmk (ORCPT ); Sat, 2 Apr 2022 08:42:40 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41AC82980F; Sat, 2 Apr 2022 05:40:48 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6998C5C006C; Sat, 2 Apr 2022 08:40:47 -0400 (EDT) Received: from imap47 ([10.202.2.97]) by compute2.internal (MEProxy); Sat, 02 Apr 2022 08:40:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; bh=UxpE6QuX00X/HUxMRxKCgBvn/5U8Qx /FUyad3eii1Ig=; b=NRVaLuof6uXRM33NFhGt86CNu67E3U7Tmp05Ss1kibfRPQ o7vjPCayxeTRKdkN6IegAgrFzL1r2RZOoWdBSPSt/WCrQusS3vx4ny3IodNnn+58 wvYVkBcNDEvvuJAaEb8mk7e0WCtrb9WgipkqttFflPbsmSk9fNoLoRS289Nqy+j/ R9qmo3RKD35w/CAcA2udmBhtAvAoQERqk+a3qZ+Pd1YAShKdqost+CEEu2jA+FK8 reBv3WsEaB/NKvF8rLN5cu3zAbfEZi12MZ4A1wYyLu0NzNdWGwoC0ey/B+v3izBi QYavYt3rRoXl27qNuYn3tuTii7Q6ls/G/1du5MQg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=UxpE6QuX00X/HUxMR xKCgBvn/5U8Qx/FUyad3eii1Ig=; b=MwFajUTbCnEhaI5WHuhUuCjqstP5km4TS Y7vKUfHF8gt0RRwWqmkuuQTcrVsaOxAj2gqe1FjLkDYT2D9CL3Zi2KKL11e/Bunc /tqVSZyhX/Hm5dwccbPC89GB34FIIrkvckdY7KO9eldWtVT69PRQlUrBJZK/hA3T glggM8C1licbSFTKb/kl+WTbeuuXtlSCYaKR53mK9zTyqcIwj3pb0JTxICPM7aP6 U/I3OOD4J3mw/JgiTQiTN1UwYdiBdaIXSz5GrjSplrJkP8CeKs53qg2An2k+QOyI TJAO+WdJd9RzgdJoQHllHtU1VJrY006eQWKybfVY4kEkcK3/06mLA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeikedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfuvhgv nhcurfgvthgvrhdfuceoshhvvghnsehsvhgvnhhpvghtvghrrdguvghvqeenucggtffrrg htthgvrhhnpefgieegieffuefhtedtjefgteejteefleefgfefgfdvvddtgffhffduhedv feekffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hsvhgvnhesshhvvghnphgvthgvrhdruggvvh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id A654D2740558; Sat, 2 Apr 2022 08:40:46 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-382-g88b93171a9-fm-20220330.001-g88b93171 Mime-Version: 1.0 Message-Id: <28ed16fd-84db-427c-bba0-7f2669f50517@www.fastmail.com> In-Reply-To: References: <20220321165049.35985-1-sven@svenpeter.dev> <20220321165049.35985-5-sven@svenpeter.dev> Date: Sat, 02 Apr 2022 14:40:06 +0200 From: "Sven Peter" To: "Alyssa Rosenzweig" Cc: "Hector Martin" , "Rob Herring" , "Arnd Bergmann" , "Keith Busch" , "axboe@fb.com" , "hch@lst.de" , "sagi@grimberg.me" , "Marc Zyngier" , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org Subject: Re: [PATCH 4/9] soc: apple: Add SART driver Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 21, 2022, at 18:17, Alyssa Rosenzweig wrote: >> +/* >> + * Adds the region [paddr, paddr+size] to the DMA allow list. >> + * >> + * @sart: SART reference >> + * @paddr: Start address of the region to be used for DMA >> + * @size: Size of the region to be used for DMA. >> + */ >> +int apple_sart_add_allowed_region(struct apple_sart *sart, phys_addr_t paddr, >> + size_t size); >> + >> +/* >> + * Removes the region [paddr, paddr+size] from the DMA allow list. >> + * >> + * Note that exact same paddr and size used for apple_sart_add_allowed_region >> + * have to be passed. >> + * >> + * @sart: SART reference >> + * @paddr: Start address of the region no longer used for DMA >> + * @size: Size of the region no longer used for DMA. >> + */ >> +int apple_sart_remove_allowed_region(struct apple_sart *sart, phys_addr_t paddr, >> + size_t size); > > Might it be simpler for add_allowed_region to return a handle that > remove_allowed_region takes instead of paddr+size? Then > remove_allowed_region doesn't have to walk anything, and the requirement > to use the same paddr/size is implicit. I liked that idea and just prototyped it and them remembered why I have the API like it is: In a perfect world this would be an IOMMU and just implement the IOMMU device ops. In a slightly less perfect world this would implement dma_map_ops and transparently allow using the normal DMA API inside the NVMe driver. In Apple's world the NVMe driver needs two separate IOMMU-like filters and you can't have two separate dma_map_ops without ugly hacks. This will usually be used just next to dma_map_coherent and dma_free_coherent and for those you need to keep track of phys_addr, dma_addr and size anyway, e.g. (with the error handling removed here) bfr->buffer = dma_alloc_coherent(anv->dev, size, &iova, GFP_KERNEL); ret = apple_sart_add_allowed_region(anv->sart, iova, size); and later then apple_sart_remove_allowed_region(anv->sart, bfr->iova, bfr->size); dma_free_coherent(anv->dev, bfr->size, bfr->buffer, bfr->iova); Best, Sven