Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1012903pxb; Wed, 6 Apr 2022 06:43:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6EeH7uCnjpj2tcKM5IUzjo5a2hXlGBqkAFJ7FKHNcdjf2EcoQCV5uhnRsYfJeb7IYnuaI X-Received: by 2002:a17:902:d384:b0:156:b53d:949d with SMTP id e4-20020a170902d38400b00156b53d949dmr8566462pld.134.1649252595100; Wed, 06 Apr 2022 06:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649252595; cv=none; d=google.com; s=arc-20160816; b=iUb5dnGw9JheWszAX812a8Mp6grHtO/5jLJBFHOyFUbnz+SbmCWas4ngZGsF3pnx3I f9ygzkDpvkXjpbyOVHiyhltH6xYtncXc5t/yvyCdZfNsJ2Pa8sE/WSdu45Bo58yVP3ur kpxkaIvJpqJm8wLeoOKsBwP6lo6vS0pL0lbSrXjIcSjmJqdVtBWbQn0egxVvp4kangfb GzhGkVcIlngS7cTI6tVUs6YqNI+TpZgaHTXCekSjGWA1xlgrsoIcMjbUMOkPeJ3HvZaf 96eRdi/7TT3ZBWeFkpTl4le9IeItz+4tGDM2uI6D06RRV2sTXKhhV68aWC74qB+aFlVX aHEA== 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=f7SyYZI4nz+qs5qaMDg1riUJfz1XkXCuG6WXTU/lNCQ=; b=NZUTFHisJqepxo7mfm4qBIdDRSF5DHt4EMNSUAcGBiTdCDZTWF3Sl6b6TKFYE+5qyX E+DVD/B3yUDSmQJccMI8L3/kUl8a6i+xaqyPvLij6vox5H8gG9zlRtIvl6yGYTCVfvHc cC0bAQih1kxDD4jZDfmNlektdKLM00chDTcE8bMT5mQLzD9NgscAe0FEzj8NkMfMC2YF +ITe1i58LBNwQTEYwZ7O+f1zcf6BnnH4FpLu9PCcvKh2E7BW0yGe74VnkDzeEE/c4gjN HK0420/pGBZKNgN9HJfdJa/Z9+Zs98/3L03b4SPJBIe/IgUpeytszHauHKPzG4Z/CDpz Y8Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=abLQr7Oc; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=UeVodiwW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p126-20020a634284000000b0039942b9fcbasi7277152pga.529.2022.04.06.06.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:43:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=abLQr7Oc; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=UeVodiwW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CD0660D714; Wed, 6 Apr 2022 04:33:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1454551AbiDEWiw (ORCPT + 99 others); Tue, 5 Apr 2022 18:38:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1457347AbiDEQDH (ORCPT ); Tue, 5 Apr 2022 12:03:07 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40C5825E9E; Tue, 5 Apr 2022 08:37:27 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 4F6E23201464; Tue, 5 Apr 2022 11:37:25 -0400 (EDT) Received: from imap47 ([10.202.2.97]) by compute2.internal (MEProxy); Tue, 05 Apr 2022 11:37:26 -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=f7SyYZI4nz+qs5qaMDg1riUJfz1XkX CuG6WXTU/lNCQ=; b=abLQr7Ocox7EC2QOocUVper/aOyFWncLbJ1SWNpn1FgdoE oFjH6XS6gAddBS5s3IaBrxIUWW+yGYgKFJiYiEb0PK8Fd8bZ62aLn+EoMPkvkHFG ZFNXxQWyE4j94LuxavQmpSANyzqQoQw+c/ZRF094grUvUCzHhDgJEmGW5N/C54Nr ZZX9/J+C8pc8b22K9aCU44ziKFWg8Aw1DoRnXI86Mxa+lSmPuorMtDjvJv5CCuR7 VWlU1dP0LXpSdrWH/EgO/Q6Yt/n2GSdGRGiK63mExuRceE8IF901tSfv/R5k8VJR +7S5uBKQJHhihPJ+FK9pLvK6dQsZSM5M4iIfNwmw== 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=f7SyYZI4nz+qs5qaM Dg1riUJfz1XkXCuG6WXTU/lNCQ=; b=UeVodiwW8PmkEP9EPOHfnWy0CCe0guLPF DliOMGO4FfQEz5RrQA9EawpvoUPmY2N4p1Y7hJAhXalO7KNhhjB9hrJzTKQryP13 BRhjKbc0Uhhae7wmBkB/+Fo7rz7Ekz5+cWeXOJ2KBQmidkgdtNAzXIEa6cnKj6gi 1EN0qK4VrO/0tTJM7IeFT5mRwIXqQwwJkuHJmIas+yyVgxcHUzTSCTmXCcaRx7xy knHKVCSSxf1IVkwBMTOVVhwIstsUlpUzQYMKKD+SXnSMXkbA1MutFKYiEFW1SG3r df+ISBqWong8Pjrx9tT1G5Yr/ia7zrmk+U01T4XEeMRJI4FDcDf9Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudejgedgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfuvhgv nhcurfgvthgvrhdfuceoshhvvghnsehsvhgvnhhpvghtvghrrdguvghvqeenucggtffrrg htthgvrhhnpefgieegieffuefhtedtjefgteejteefleefgfefgfdvvddtgffhffduhedv feekffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hsvhgvnhesshhvvghnphgvthgvrhdruggvvh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1381327407F6; Tue, 5 Apr 2022 11:37:24 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-385-g3a17909f9e-fm-20220404.001-g3a17909f Mime-Version: 1.0 Message-Id: In-Reply-To: References: <20220321165049.35985-1-sven@svenpeter.dev> <20220321165049.35985-5-sven@svenpeter.dev> Date: Tue, 05 Apr 2022 17:37:03 +0200 From: "Sven Peter" To: "Rob Herring" , "Arnd Bergmann" Cc: "Hector Martin" , "Alyssa Rosenzweig" , "Keith Busch" , "axboe@fb.com" , "hch@lst.de" , "sagi@grimberg.me" , "Marc Zyngier" , DTML , "Linux ARM" , "Linux Kernel Mailing List" , 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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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, Apr 4, 2022, at 16:58, Rob Herring wrote: > On Sat, Apr 02, 2022 at 09:07:17PM +0200, Arnd Bergmann wrote: >> On Sat, Apr 2, 2022 at 2:38 PM Sven Peter wrote: >> > On Mon, Mar 21, 2022, at 18:07, Arnd Bergmann wrote: >> > > On Mon, Mar 21, 2022 at 5:50 PM Sven Peter wrote: >> > >> The NVMe co-processor on the Apple M1 uses a DMA address filter called >> > >> SART for some DMA transactions. This adds a simple driver used to >> > >> configure the memory regions from which DMA transactions are allowed. >> > >> >> > >> Co-developed-by: Hector Martin >> > >> Signed-off-by: Hector Martin >> > >> Signed-off-by: Sven Peter >> > > >> > > Can you add some explanation about why this uses a custom interface >> > > instead of hooking into the dma_map_ops? >> > >> > Sure. >> > In a perfect world this would just be an IOMMU implementation but since >> > SART can't create any real IOVA space using pagetables it doesn't fit >> > inside that subsytem. >> > >> > In a slightly less perfect world I could just implement dma_map_ops here >> > but that won't work either because not all DMA buffers of the NVMe >> > device have to go through SART and those allocations happen >> > inside the same device and would use the same dma_map_ops. >> > >> > The NVMe controller has two separate DMA filters: >> > >> > - NVMMU, which must be set up for any command that uses PRPs and >> > ensures that the DMA transactions only touch the pages listed >> > inside the PRP structure. NVMMU itself is tightly coupled >> > to the NVMe controller: The list of allowed pages is configured >> > based on command's tag id and even commands that require no DMA >> > transactions must be listed inside NVMMU before they are started. >> > - SART, which must be set up for some shared memory buffers (e.g. >> > log messages from the NVMe firmware) and for some NVMe debug >> > commands that don't use PRPs. >> > SART is only loosely coupled to the NVMe controller and could >> > also be used together with other devices. It's also the only >> > thing that changed between M1 and M1 Pro/Max/Ultra and that's >> > why I decided to separate it from the NVMe driver. >> > >> > I'll add this explanation to the commit message. >> >> Ok, thanks. >> >> > >> +static void sart2_get_entry(struct apple_sart *sart, int index, u8 *flags, >> > >> + phys_addr_t *paddr, size_t *size) >> > >> +{ >> > >> + u32 cfg = readl_relaxed(sart->regs + APPLE_SART2_CONFIG(index)); >> > >> + u32 paddr_ = readl_relaxed(sart->regs + APPLE_SART2_PADDR(index)); >> > > >> > > Why do you use the _relaxed() accessors here and elsewhere in the driver? >> > >> > This device itself doesn't do any DMA transactions so it needs no memory >> > synchronization barriers. Only the consumer (i.e. rtkit and nvme) read/write >> > from/to these buffers (multiple times) and they have the required barriers >> > in place whenever they are used. >> > >> > These buffers so far are only allocated at probe time though so even using >> > the normal writel/readl here won't hurt performance at all. I can just use >> > those if you prefer or alternatively add a comment why _relaxed is fine here. >> > >> > This is a bit similar to the discussion for the pinctrl series last year [1]. >> >> I think it's better to only use the _relaxed version where it actually helps, >> with a comment about it, and use the normal version elsewhere, in >> particular in functions that you have copied from the normal nvme driver. >> I had tried to compare some of your code with the other version and >> was rather confused by that. > > Oh good, I tell folks the opposite (and others do too). We don't accept > random explicit barriers without explanation, but implicit ones are > okay? The resulting code on arm32 is also pretty horrible with the L2x0 > and OMAP sync hooks not that that matters here. > > I don't really care too much which way we go, but we should document one > rule and follow that. I don't have a strong opinion either. Arnd's approach is currently documented in Documentation/driver-api/device-io.rst fwiw: On architectures that require an expensive barrier for serializing against DMA, these "relaxed" versions of the MMIO accessors only serialize against each other, but contain a less expensive barrier operation. A device driver might use these in a particularly performance sensitive fast path, with a comment that explains why the usage in a specific location is safe without the extra barriers. Sven