Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4256934rwl; Sat, 7 Jan 2023 14:27:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXvktScio0XQsuHRxcTPOHYIbDHjT1KvCoPw4hWdbtjgxeydB0KPhCnaWgWtwSl+FaPSkFKB X-Received: by 2002:a17:902:ccce:b0:189:e577:c83e with SMTP id z14-20020a170902ccce00b00189e577c83emr70534026ple.36.1673130477812; Sat, 07 Jan 2023 14:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673130477; cv=none; d=google.com; s=arc-20160816; b=qkN7Gc/Xyncb2F39pLza1RoLAOuMdbJS4RonOY5b66ZDGQe9veeTER8RqBU3UcO+fL wOkTeHK7AgMSkNT0cVigZ8jlGozqtMtLLGbjOHrmwnge58N9wxhp/vDOTKiYIXCTE0rW e9yrXcT5v/HTGUp/mJWoP9rtTsEKDZq86xJoQefmV2d4YimZOLDKVsM5fxSciGRFdtLT pdZLEdrEoopk0Ck5/3RXDxMtpGE/5Cu+t8gnuUeyV1efuYGYJ9Ue5z24PfXRb+TX8QMu 6rMHk7+kN/vjqRtgcz73EpOP+oao9YoX/65RltZKAcLak5nnAcszYnwNmc5LwL5koKBU xnjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gwxE7Q9iHOTdeXe9x0xc4tBxUf+n7UexqnsTO4hvkXM=; b=TlSt5tHZ5w2xwJ8lmFNGg/cn50hE8TgIPRtDyJ4lXy0tR9JxWwl9I1Izh4awj3emZF OjBgIuRRfRREzvOSNSQxc1HdvTBsVJYuO44LXAt6s7SUe/sOuqski4cp2dEZ1eYeS6vc v98nR3/PM0v+cFkLjI11lmhQhSco+5XGWHckrQg0vOq9aLqdN25ROVzzpTfVRiKV3Nsq dNigkVzXuhlEB6v6gicSF515EJSKhaUlABPCdZdTkWAqtQXA+mIs+qklqpty8Ve2Cf4V WeYbWqK1zdYOuZYI4c973MfpgRh/xkdTysCEePY+U0VpIt/megYZUlFT+ANqk9/Qx8iu B+Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZbAbVUr3; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a170902d50200b00192721d6a97si5637657plg.499.2023.01.07.14.27.49; Sat, 07 Jan 2023 14:27:57 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=ZbAbVUr3; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232629AbjAGWLa (ORCPT + 55 others); Sat, 7 Jan 2023 17:11:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230205AbjAGWL2 (ORCPT ); Sat, 7 Jan 2023 17:11:28 -0500 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9918919C12; Sat, 7 Jan 2023 14:11:24 -0800 (PST) Received: by mail-qk1-x731.google.com with SMTP id 4so629300qky.12; Sat, 07 Jan 2023 14:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gwxE7Q9iHOTdeXe9x0xc4tBxUf+n7UexqnsTO4hvkXM=; b=ZbAbVUr3Lpgd9HbMzmrplqDRU7F9ZmhdS/WOWnrm5QsA3ZHS8H/q8AXtl2apXFcB2i 4fH94d8P3kMe47oEKid2CHFmkhKfp52TKQp9r/M9WgUGgB3me5MnXNrJu5G31xOOCQ9W SL47eG/cvrJ4InF8P+G+QAkxgehYitj3zhkIrs+Ke9F8OtjYk17GHueH4S2cTQ/vK425 WsLs9JEOS+sQmzjuxS5BdE3OeaL5kyIFtd1By6S/SFvh7Sl5eki59VTItoqlTwO7mR8V upPvg7+XN8W7vTxMy4Z/j0WTt871+if9bcSmJcmdYQimwNYvE9/RTEKaQ/KyT89wxo8W guIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gwxE7Q9iHOTdeXe9x0xc4tBxUf+n7UexqnsTO4hvkXM=; b=24WvVmap8ThanIVN4zA3zd1gdc0pdyZPBvP/lO3eO+9xz5ezwyHjMBqJyc4b2x1EAc 7y0TNHSAQlIYeEY06umf+kLqCyJOft6PZIJQDyFKwmpfPzhMkdlfSaMcztdQ7nWD/k1N xWx0piuYJc8hyl2phDX3GPUQGjMFZ4jmlyQzOn2Mc3idDwIfx57c/Jgl7h9Cn2g1RoUO VbJ4sGXbLqWs1xVvS6Huej7yr07RU6o+plVLIZYlSbNysDXhHV+YCq97AggoWXYCNU/u MC3SqEz6i6dRFR6QcQR+ePR5SLKjtJoMKbMvKQekE+AlQd8OWzChbJEUy/mY8HYThlWq pQsQ== X-Gm-Message-State: AFqh2komNA8rjlVmJItNQPm93FXY0/ICoHI3z34tzuR836qAuT1oP4bH VWsMVlEGwQAvijEG5/HFMAzzAZkF3jDRrTUwkWM= X-Received: by 2002:ae9:e8d1:0:b0:702:257f:74fc with SMTP id a200-20020ae9e8d1000000b00702257f74fcmr2323663qkg.519.1673129483571; Sat, 07 Jan 2023 14:11:23 -0800 (PST) MIME-Version: 1.0 References: <20230106185526.260163-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20230106185526.260163-2-prabhakar.mahadev-lad.rj@bp.renesas.com> <6f7d06ef-d74d-4dfc-9b77-6ae83e0d7816@app.fastmail.com> In-Reply-To: <6f7d06ef-d74d-4dfc-9b77-6ae83e0d7816@app.fastmail.com> From: "Lad, Prabhakar" Date: Sat, 7 Jan 2023 22:10:56 +0000 Message-ID: Subject: Re: [RFC PATCH v6 1/6] riscv: mm: dma-noncoherent: Switch using function pointers for cache management To: Arnd Bergmann Cc: "Conor.Dooley" , Geert Uytterhoeven , =?UTF-8?Q?Heiko_St=C3=BCbner?= , guoren , Andrew Jones , Paul Walmsley , Palmer Dabbelt , Albert Ou , "open list:RISC-V ARCHITECTURE" , open list , devicetree@vger.kernel.org, Linux-Renesas , "Lad, Prabhakar" , Philipp Tomsich , Nathan Chancellor , Atish Patra , Anup Patel , Tsukasa OI , Jisheng Zhang , Mayuresh Chitale Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Hi Arnd, Thank you for the review. On Fri, Jan 6, 2023 at 10:31 PM Arnd Bergmann wrote: > > On Fri, Jan 6, 2023, at 19:55, Prabhakar wrote: > > From: Lad Prabhakar > > > > The current implementation of CMO was handled using the ALTERNATIVE_X() > > macro; this was manageable when there were a limited number of platforms > > using this. Now that we are having more and more platforms coming through > > with the CMO the use of the ALTERNATIVE_X() macro becomes unmanageable. > > > > To avoid such issues this patch switches to use of function pointers > > instead of ALTERNATIVE_X() macro for cache management (the only draw 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 where platforms > > using standard approach and for platforms who want handle the operation > > based on the operation the below function pointer is provided: > > > > void (*riscv_dma_noncoherent_cmo_ops)(void *vaddr, size_t size, > > enum dma_data_direction dir, > > enum dma_noncoherent_ops ops); > > > > In the current patch we have moved the ZICBOM and T-Head CMO to use > > function pointers. > > > > Signed-off-by: Lad Prabhakar > > This looks like a nice improvement! I have a few suggestions > for improvements, but no objections here. > > > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c > > index fac5742d1c1e..826b2ba3e61e 100644 > > --- a/arch/riscv/errata/thead/errata.c > > +++ b/arch/riscv/errata/thead/errata.c > ... > > @@ -44,6 +106,15 @@ static bool errata_probe_cmo(unsigned int stage, > > > > riscv_cbom_block_size = L1_CACHE_BYTES; > > riscv_noncoherent_supported(); > > + > > + memset(&thead_cmo_ops, 0x0, sizeof(thead_cmo_ops)); > > + if (IS_ENABLED(CONFIG_ERRATA_THEAD_CMO)) { > > + thead_cmo_ops.clean_range = &thead_cmo_clean_range; > > + thead_cmo_ops.inv_range = &thead_cmo_inval_range; > > + thead_cmo_ops.flush_range = &thead_cmo_flush_range; > > + riscv_noncoherent_register_cache_ops(&thead_cmo_ops); > > + } > > The implementation here looks reasonable, just wonder whether > the classification as an 'errata' makes sense. I would probably > consider this a 'driver' at this point, but that's just > a question of personal preference. > zicbom is a CPU feature that doesn't have any DT node and hence no driver and similarly for T-HEAD SoC. Also the arch_setup_dma_ops() happens quite early before driver probing due to which we get WARN() messages during bootup hence I have implemented it as errata; as errata patching happens quite early. > For the operations structure, I think a 'static const struct > riscv_cache_ops' is more intuitive than assigning the > members individually. OK. > > + > > +enum dma_noncoherent_ops { > > + NON_COHERENT_SYNC_DMA_FOR_DEVICE = 0, > > + NON_COHERENT_SYNC_DMA_FOR_CPU, > > + NON_COHERENT_DMA_PREP, > > + NON_COHERENT_DMA_PMEM, > > +}; > > + > > +/* > > + * struct riscv_cache_ops - Structure for CMO function pointers > > + * @clean_range: Function pointer for clean cache > > + * @inv_range: Function pointer for invalidate cache > > + * @flush_range: Function pointer for flushing the cache > > + * @riscv_dma_noncoherent_cmo_ops: Function pointer for platforms who > > want > > + * to handle CMO themselves. If this function pointer is set rest of > > the > > + * function pointers will be NULL. > > + */ > > +struct riscv_cache_ops { > > + 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); > > + void (*riscv_dma_noncoherent_cmo_ops)(void *vaddr, size_t size, > > + enum dma_data_direction dir, > > + enum dma_noncoherent_ops ops); > > +}; > > I don't quite see how the fourth operation is used here. > Are there cache controllers that need something beyond > clean/inv/flush? > This is for platforms that dont follow standard cache operations (like done in patch 5/6) and there drivers decide on the operations depending on the ops and dir. > > + > > +#else > > + > > +static void riscv_noncoherent_register_cache_ops(struct > > riscv_cache_ops *ops) {} > > + > > +static inline void riscv_dma_noncoherent_clean(void *vaddr, size_t > > size) {} > > + > > +static inline void riscv_dma_noncoherent_flush(void *vaddr, size_t > > size) {} > > + > > +static inline void riscv_dma_noncoherent_inval(void *vaddr, size_t > > size) {} > > I think you can drop the #else path here: if there is no > noncoherent DMA, then nothing should ever call these > functions, right? > Yes it shouldn't be called. > > + > > +#ifdef CONFIG_RISCV_ISA_ZICBOM > ... > > +struct riscv_cache_ops zicbom_cmo_ops = { > > + .clean_range = &zicbom_cmo_clean_range, > > + .inv_range = &zicbom_cmo_inval_range, > > + .flush_range = &zicbom_cmo_flush_range, > > +}; > > +#else > > +struct riscv_cache_ops zicbom_cmo_ops = { > > + .clean_range = NULL, > > + .inv_range = NULL, > > + .flush_range = NULL, > > + .riscv_dma_noncoherent_cmo_ops = NULL, > > +}; > > +#endif > > +EXPORT_SYMBOL(zicbom_cmo_ops); > > Same here: If the ZICBOM ISA is disabled, nothing should > reference zicbom_cmo_ops. OK. Cheers, Prabhakar