Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp206319rwl; Thu, 30 Mar 2023 14:40:10 -0700 (PDT) X-Google-Smtp-Source: AKy350bLG0Y4n1vLMXrikf5+qkNPH/phmpYxJaEGtdXlyv3R2id5VP93Zr+aQMrjI7JgWYWnQSv3 X-Received: by 2002:a17:902:ea01:b0:1a2:175a:6153 with SMTP id s1-20020a170902ea0100b001a2175a6153mr3840350plg.1.1680212410146; Thu, 30 Mar 2023 14:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680212410; cv=none; d=google.com; s=arc-20160816; b=mRY/JU4ECJ08LlAdZ5KnnbKMtoPpJEFNnGra0txIxPyiZR93difxzWT7xoaSBPtyO6 zcz1lRc7XxyaDso+jZYBbM0sw4nY2OTD72nny1K/oZt2Mc2eG6lhPtsqb1OhWgk5gSYw R77u7uKycqZRlQLP9LFYCdkKPNh4zBZCl2tJSS9yXNrjWxT6bQ8xiKu5gMoNL0T5le2Q /i2vROSE80uXZFFZ1j7E4UeYM4aw/L3rydyeZs+h7EODm9T/ZTNjlh9GismphoXFMotj 2eVeY14csyumVHNMPHvI8RD/TvQ/qRr1otKwaNOxfUuGhLAz9kcbgeJAffHKApDIcQez FDYw== 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:feedback-id:dkim-signature :dkim-signature; bh=hpuSAgqfUaqD/ysKyJQwTcBXNZjA8xYFCgAGQ8d1bL8=; b=ErgblR3y/Qq21KT69GvKVu1SqmSirmhwrbxh8y/AfiGWM8bOw/LTkwOTu6iymzdTbA e9tIEyKRZqJbw1GdwCvj4AQwVfTKHlp5fMQoR8zZzC6KhIaKy+qcrHBlxlpAQ6Cw/eMy c7zPxeUIP0xKAE1TGR5c+UvK8hG1DrqQDdjOrh0XaHU/KesLSrYNZqoCURbKWB8yZGBj jdf6NPKCTnpTILvawXyM0F//f8mQ0RSYPYcjIMk2toz5caCYK+FMkwaLkU9fxZ/KoTIG pUEdByjo4R+scAw1D7iQkWfVe5PYuJroh5/aBuNfhWI0FnTdyoXhMXdkJ4bheFXuFE2E zEbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b=vPTfmWAy; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ZRndJORL; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a170902c94800b001a23e0e8fedsi587921pla.4.2023.03.30.14.39.55; Thu, 30 Mar 2023 14:40:10 -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=@arndb.de header.s=fm1 header.b=vPTfmWAy; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ZRndJORL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbjC3Vea (ORCPT + 99 others); Thu, 30 Mar 2023 17:34:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjC3Ve2 (ORCPT ); Thu, 30 Mar 2023 17:34:28 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D790335B5; Thu, 30 Mar 2023 14:34:27 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 5B925320094E; Thu, 30 Mar 2023 17:34:24 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Thu, 30 Mar 2023 17:34:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type: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; t=1680212063; x=1680298463; bh=hp uSAgqfUaqD/ysKyJQwTcBXNZjA8xYFCgAGQ8d1bL8=; b=vPTfmWAyebme5BY4p6 J4ucGHGxrN86sr2fRjD+KS3geiZl6TYAyvsUFTPJV9vgZm+YpnhnUAfkJuQyjcZ0 HsUAp7qWX2x1XpqS/6Avrs5R6vNIeD2d9e0BclI7l4+Xa85yS7RJ7d4zBfAPteQY IqSl4R+T8FOxkEJWL3lxLJOTpvEslf10gn2QFIk8BUptkGAC1qgV7vk6wPe9Et7X 9jJquc17UpAUSDRMARTnPuIVSBD/q6atWEbNYS/Tde0YqW4Rrc97T0IXg06IROeW rxADsu62hJFwbM1wo85cXh3YgY7X/taN2HPLNJWSvyzj1m98x8wrioQ3DIfdaF4V 2+0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id: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=fm2; t=1680212063; x=1680298463; bh=hpuSAgqfUaqD/ ysKyJQwTcBXNZjA8xYFCgAGQ8d1bL8=; b=ZRndJORL0aLLZMdezjvfovMzjPjgD /SKaR2niKqMry7R8FNFZGjh6xUJlJtOb6rhudt5wAj1K9u1sYHvrZpeqlEDxoKFj CTdphfMnjq0IF2XCIbcOBtcqdVkl5LClq/oTtAv9Q5Ek04a3t4xNLzeteriILCbR wFgeLl4JeUAV7iqsnUT3fP1OZ96KKTukwHGEcPp2mXXWnfg6M875wmv6yXpM9OSy 0Yx6bCmmskVhOyGFO/I5Pf+60RdcF2NNRAmXxzKR1nCNajILfNoGjY5Flxnbcdz0 NKA2Ph3MOwJlhjfrjqwQjxoLGItm1DUYfekI3VnjvQGVBMEAu6735U2nQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehledgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehr nhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrdguvgeqnecuggftrfgrth htvghrnhepffehueegteeihfegtefhjefgtdeugfegjeelheejueethfefgeeghfektdek teffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 01C80B60086; Thu, 30 Mar 2023 17:34:22 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-238-g746678b8b6-fm-20230329.001-g746678b8 Mime-Version: 1.0 Message-Id: <6ca5941a-8803-477d-8b40-17292decc5af@app.fastmail.com> In-Reply-To: <20230330204217.47666-2-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20230330204217.47666-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20230330204217.47666-2-prabhakar.mahadev-lad.rj@bp.renesas.com> Date: Thu, 30 Mar 2023 23:34:02 +0200 From: "Arnd Bergmann" To: Prabhakar , "Conor.Dooley" , "Geert Uytterhoeven" , =?UTF-8?Q?Heiko_St=C3=BCbner?= , guoren , "Andrew Jones" , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , "Samuel Holland" , linux-riscv@lists.infradead.org Cc: "Rob Herring" , "Krzysztof Kozlowski" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Linux-Renesas , "Biju Das" , "Lad, Prabhakar" Subject: Re: [PATCH v7 1/6] riscv: mm: dma-noncoherent: Switch using function pointers for cache management Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 Thu, Mar 30, 2023, at 22:42, Prabhakar wrote: > From: Lad Prabhakar > > Currently, selecting which CMOs to use on a given platform is done using > and ALTERNATIVE_X() macro. This was manageable when there were just two > CMO implementations, but now that there are more and more platforms coming > needing custom CMOs, the use of the ALTERNATIVE_X() macro is unmanageable. > > To avoid such issues this patch switches to use of function pointers > instead of ALTERNATIVE_X() macro for cache management (the only drawback > being performance over the previous approach). > > void (*clean_range)(unsigned long addr, unsigned long size); > void (*inv_range)(unsigned long addr, unsigned long size); > void (*flush_range)(unsigned long addr, unsigned long size); > > The above function pointers are provided to be overridden for platforms > needing CMO. > > Convert ZICBOM and T-HEAD CMO to use function pointers. > > Signed-off-by: Lad Prabhakar This is looking pretty good. There are a few things that I still see sticking out, and I think I've mentioned some of them before, but don't remember if there was a reason for doing it like this: > +#ifdef CONFIG_ERRATA_THEAD_CMO I would rename this to not call this an 'ERRATA' but just make it a driver. Not important though, and there was probably a reason you did it like this. > +extern struct riscv_cache_ops noncoherent_cache_ops; > + > +void riscv_noncoherent_register_cache_ops(const struct riscv_cache_ops > *ops); > + > +static inline void riscv_dma_noncoherent_clean(void *vaddr, size_t > size) > +{ > + if (noncoherent_cache_ops.clean_range) { > + unsigned long addr = (unsigned long)vaddr; > + > + noncoherent_cache_ops.clean_range(addr, size); > + } > +} The type case should not be necessary here. Instead I would make the callbacks use 'void *' as well, not 'unsigned long'. It's possible that some future cache controller driver requires passing physical addresses, as is common for last level cache, but as long as all drivers pass virtual addresses, it's easier to do the phys_to_virt() in common code. It also seems wrong to have the fallback be to do nothing when the pointer is NULL, since that cannot actually work when a device is not cache coherent. I would either initialize the function pointer to the zicbom version and remove the NULL check, or keep the pointer NULL and have an explicit 'else zicbom_clean_range()' fallback. > +static void zicbom_register_cmo_ops(void) > +{ > + riscv_noncoherent_register_cache_ops(&zicbom_cmo_ops); > +} > +#else > +static void zicbom_register_cmo_ops(void) {} > +#endif As far as I recall, the #else path here was needed previously to work around a binutils dependency, but with the current code, it should be possible to just always enable CONFIG_RISCV_ISA_ZICBOM when RISCV_DMA_NONCOHERENT is used. Arnd