Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5216140rwr; Mon, 1 May 2023 01:57:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6a2m6SG6f8h0kGyigGsFzrP51kgMZ2FSgNcS4okhe/p19NGtisWWvXFVoH7yBct5mPeIKe X-Received: by 2002:a05:6a00:1885:b0:63d:2d8c:7fd5 with SMTP id x5-20020a056a00188500b0063d2d8c7fd5mr20130023pfh.12.1682931477823; Mon, 01 May 2023 01:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682931477; cv=none; d=google.com; s=arc-20160816; b=0GEYQbKPzL0mFmFgIvJUxTtlLcl6vOmANhaq/SdUtSLbq3eTd3CVXZsaUqUzipXEWO 2V530oI76EQ17Vu+FCcNHaMYyzYVBlpjBH8PS8SJoQJfTsyrN6GFoPlCKYbjWs/Zp9hW VEfvAhFYZWGAfhS1jdxRMGhQJLat90A6VGHb2tVvyCK+xcnUnr1edTiCrNfYn7gjr7tZ fGlKX/Wib1UthumwPmwoiS5OeFIID049T3GfePJD7wHAgwgNQQE8fiRg8UiECaTENml/ GBf7SvYyMrOWWShXtizPHaXO+SDMe/7WMskknHAZKL53wxwX/YjOCS6gsCpvHUUMw2qO Jovw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=fb1RnOTrCk8VLumgM2sDQgqQMmzlWPyVLgmwfuEsEY0=; b=ZDXGDGkdLrNTd0+CVG6V15Bqj5A8XNqkTkbomjIH4A2xIW1J4TbkOoohPPVhxrSAzt 2cG2qe0jJrYpVX2uZM6CxhWFmRxk9H02Nq6WntI+sMLH7bZG5lbkCdJ9CcluUZLUX9No M3ArSU3uzQPaumH/ZX5KspqD0oVnTRn53sauygiU883O1YThhmkVWUh5txT+XprpLSM9 ae1QfokDrGX7Qd1EDTy5gYDIgQIx/rQnTurZ+FOs3dPTK9q9BojjcI/P5TJC6JNI3lmm uC/LUQwUvPJxhuOeXd6aIeA+tBfrILWW1hiABpvTXr1MG+SLnENel34QDrUoIPA5iEga 7Y8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HNxaObCA; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k190-20020a6284c7000000b0063f24efaf7bsi23886277pfd.390.2023.05.01.01.57.44; Mon, 01 May 2023 01:57:57 -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=@kernel.org header.s=k20201202 header.b=HNxaObCA; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232385AbjEAIqF (ORCPT + 99 others); Mon, 1 May 2023 04:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232181AbjEAIpp (ORCPT ); Mon, 1 May 2023 04:45:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A701BF9; Mon, 1 May 2023 01:45:22 -0700 (PDT) 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 7A0B361B51; Mon, 1 May 2023 08:45:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B354EC4339C; Mon, 1 May 2023 08:44:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682930699; bh=rulYTavJHhA8ZwocaiHU3PzLTExyBoYBA0lghA9SugY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=HNxaObCA9lyDwDGVwTwMCQoLnBsk8ts0CWOgtKT4HHE6qzZF9tjBSSrKt1xyIG7Qf L+2pOcLf+cFiyCkkLIh3nw1c7nqU4/L5s7TK2dfZsJsPbPt0A01HA7TxN4qQN25yCc +jzWtLSV9KgyBzvcTWZAviBQPMQAXsbCjRN/AFV8ufVnwuqoDLxsDlTsVnnDDBhYuK NjstBFeqaGReiaf6TiietDkZ9HISUXO+0cqctzJU6OLo8DFUKh2GSZILzEOhk62f0C xQHRiBEIcsKI3w5zngnpv+Z2CvQvvu2V6lHT4SpGtzq8HumvhI7r+G09bId5wT4/Xv pptMcaJAf9jqQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ptP9V-00CFJx-9A; Mon, 01 May 2023 09:44:57 +0100 Date: Mon, 01 May 2023 09:44:52 +0100 Message-ID: <86ttwwh24b.wl-maz@kernel.org> From: Marc Zyngier To: Anup Patel Cc: Anup Patel , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Atish Patra , Alistair Francis , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v2 5/9] irqchip: Add RISC-V incoming MSI controller driver In-Reply-To: References: <20230103141409.772298-1-apatel@ventanamicro.com> <20230103141409.772298-6-apatel@ventanamicro.com> <867cxqoic8.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: anup@brainfault.org, apatel@ventanamicro.com, palmer@dabbelt.com, paul.walmsley@sifive.com, tglx@linutronix.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, atishp@atishpatra.org, Alistair.Francis@wdc.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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, 01 May 2023 09:28:16 +0100, Anup Patel wrote: >=20 > On Fri, Jan 13, 2023 at 3:40=E2=80=AFPM Marc Zyngier wro= te: > > > > On Tue, 03 Jan 2023 14:14:05 +0000, > > Anup Patel wrote: > > > > > > The RISC-V advanced interrupt architecture (AIA) specification defines > > > a new MSI controller for managing MSIs on a RISC-V platform. This new > > > MSI controller is referred to as incoming message signaled interrupt > > > controller (IMSIC) which manages MSI on per-HART (or per-CPU) basis. > > > (For more details refer https://github.com/riscv/riscv-aia) > > > > And how about IPIs, which this driver seems to be concerned about? >=20 > Okay, I will mention about IPIs in the commit description. >=20 > > > > > > > > This patch adds an irqchip driver for RISC-V IMSIC found on RISC-V > > > platforms. > > > > > > Signed-off-by: Anup Patel > > > --- > > > drivers/irqchip/Kconfig | 14 +- > > > drivers/irqchip/Makefile | 1 + > > > drivers/irqchip/irq-riscv-imsic.c | 1174 +++++++++++++++++++++++++= ++ > > > include/linux/irqchip/riscv-imsic.h | 92 +++ > > > 4 files changed, 1280 insertions(+), 1 deletion(-) > > > create mode 100644 drivers/irqchip/irq-riscv-imsic.c > > > create mode 100644 include/linux/irqchip/riscv-imsic.h > > > > > > diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig > > > index 9e65345ca3f6..a1315189a595 100644 > > > --- a/drivers/irqchip/Kconfig > > > +++ b/drivers/irqchip/Kconfig > > > @@ -29,7 +29,6 @@ config ARM_GIC_V2M > > > > > > config GIC_NON_BANKED > > > bool > > > - > > > config ARM_GIC_V3 > > > bool > > > select IRQ_DOMAIN_HIERARCHY > > > @@ -548,6 +547,19 @@ config SIFIVE_PLIC > > > select IRQ_DOMAIN_HIERARCHY > > > select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP > > > > > > +config RISCV_IMSIC > > > + bool > > > + depends on RISCV > > > + select IRQ_DOMAIN_HIERARCHY > > > + select GENERIC_MSI_IRQ_DOMAIN > > > + > > > +config RISCV_IMSIC_PCI > > > + bool > > > + depends on RISCV_IMSIC > > > + depends on PCI > > > + depends on PCI_MSI > > > + default RISCV_IMSIC > > > > This should definitely tell you that this driver needs splitting. >=20 > The code under "#ifdef CONFIG_RISCV_IMSIC_PCI" is hardly 40 lines > so I felt it was too small to deserve its own source file. It at least needs its own patch. >=20 > > > > > + > > > config EXYNOS_IRQ_COMBINER > > > bool "Samsung Exynos IRQ combiner support" if COMPILE_TEST > > > depends on (ARCH_EXYNOS && ARM) || COMPILE_TEST > > > diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile > > > index 87b49a10962c..22c723cc6ec8 100644 > > > --- a/drivers/irqchip/Makefile > > > +++ b/drivers/irqchip/Makefile > > > @@ -96,6 +96,7 @@ obj-$(CONFIG_QCOM_MPM) +=3D ir= q-qcom-mpm.o > > > obj-$(CONFIG_CSKY_MPINTC) +=3D irq-csky-mpintc.o > > > obj-$(CONFIG_CSKY_APB_INTC) +=3D irq-csky-apb-intc.o > > > obj-$(CONFIG_RISCV_INTC) +=3D irq-riscv-intc.o > > > +obj-$(CONFIG_RISCV_IMSIC) +=3D irq-riscv-imsic.o > > > obj-$(CONFIG_SIFIVE_PLIC) +=3D irq-sifive-plic.o > > > obj-$(CONFIG_IMX_IRQSTEER) +=3D irq-imx-irqsteer.o > > > obj-$(CONFIG_IMX_INTMUX) +=3D irq-imx-intmux.o > > > diff --git a/drivers/irqchip/irq-riscv-imsic.c b/drivers/irqchip/irq-= riscv-imsic.c > > > new file mode 100644 > > > index 000000000000..4c16b66738d6 > > > --- /dev/null > > > +++ b/drivers/irqchip/irq-riscv-imsic.c > > > @@ -0,0 +1,1174 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > +/* > > > + * Copyright (C) 2021 Western Digital Corporation or its affiliates. > > > + * Copyright (C) 2022 Ventana Micro Systems Inc. > > > + */ > > > + > > > +#define pr_fmt(fmt) "riscv-imsic: " fmt > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > +#define IMSIC_DISABLE_EIDELIVERY 0 > > > +#define IMSIC_ENABLE_EIDELIVERY 1 > > > +#define IMSIC_DISABLE_EITHRESHOLD 1 > > > +#define IMSIC_ENABLE_EITHRESHOLD 0 > > > + > > > +#define imsic_csr_write(__c, __v) \ > > > +do { \ > > > + csr_write(CSR_ISELECT, __c); \ > > > + csr_write(CSR_IREG, __v); \ > > > +} while (0) > > > + > > > +#define imsic_csr_read(__c) \ > > > +({ \ > > > + unsigned long __v; \ > > > + csr_write(CSR_ISELECT, __c); \ > > > + __v =3D csr_read(CSR_IREG); \ > > > + __v; \ > > > +}) > > > + > > > +#define imsic_csr_set(__c, __v) \ > > > +do { \ > > > + csr_write(CSR_ISELECT, __c); \ > > > + csr_set(CSR_IREG, __v); \ > > > +} while (0) > > > + > > > +#define imsic_csr_clear(__c, __v) \ > > > +do { \ > > > + csr_write(CSR_ISELECT, __c); \ > > > + csr_clear(CSR_IREG, __v); \ > > > +} while (0) > > > + > > > +struct imsic_mmio { > > > + phys_addr_t pa; > > > + void __iomem *va; > > > + unsigned long size; > > > +}; > > > + > > > +struct imsic_priv { > > > + /* Global configuration common for all HARTs */ > > > + struct imsic_global_config global; > > > + > > > + /* MMIO regions */ > > > + u32 num_mmios; > > > + struct imsic_mmio *mmios; > > > + > > > + /* Global state of interrupt identities */ > > > + raw_spinlock_t ids_lock; > > > + unsigned long *ids_used_bimap; > > > + unsigned long *ids_enabled_bimap; > > > + unsigned int *ids_target_cpu; > > > + > > > + /* Mask for connected CPUs */ > > > + struct cpumask lmask; > > > + > > > + /* IPI interrupt identity */ > > > + u32 ipi_id; > > > + u32 ipi_lsync_id; > > > + > > > + /* IRQ domains */ > > > + struct irq_domain *base_domain; > > > + struct irq_domain *pci_domain; > > > + struct irq_domain *plat_domain; > > > +}; > > > + > > > +struct imsic_handler { > > > + /* Local configuration for given HART */ > > > + struct imsic_local_config local; > > > + > > > + /* Pointer to private context */ > > > + struct imsic_priv *priv; > > > +}; > > > + > > > +static bool imsic_init_done; > > > + > > > +static int imsic_parent_irq; > > > +static DEFINE_PER_CPU(struct imsic_handler, imsic_handlers); > > > + > > > +const struct imsic_global_config *imsic_get_global_config(void) > > > +{ > > > + struct imsic_handler *handler =3D this_cpu_ptr(&imsic_handlers); > > > + > > > + if (!handler || !handler->priv) > > > + return NULL; > > > + > > > + return &handler->priv->global; > > > +} > > > +EXPORT_SYMBOL_GPL(imsic_get_global_config); > > > + > > > +const struct imsic_local_config *imsic_get_local_config(unsigned int= cpu) > > > +{ > > > + struct imsic_handler *handler =3D per_cpu_ptr(&imsic_handlers, = cpu); > > > + > > > + if (!handler || !handler->priv) > > > + return NULL; > > > > How can this happen? >=20 > These are redundant checks. I will drop. >=20 > > > > > + > > > + return &handler->local; > > > +} > > > +EXPORT_SYMBOL_GPL(imsic_get_local_config); > > > > Why are these symbols exported? They have no user, so they shouldn't > > even exist here. I also seriously doubt there is a valid use case for > > exposing this information to the rest of the kernel. >=20 > The imsic_get_global_config() is used by APLIC driver and KVM RISC-V > module whereas imsic_get_local_config() is only used by KVM RISC-V. >=20 > The KVM RISC-V AIA irqchip patches are available in riscv_kvm_aia_v1 > branch at: https://github.com/avpatel/linux.git. I have not posted KVM RI= SC-V > patches due various interdependencies. Then the symbols can wait, can't they? It'd make more sense if the KVM-dependent bits were brought together with the KVM patches. Even better, you'd use some level of abstraction between KVM and the irqchip code. GIC makes some heavy use of irq_set_vcpu_affinity() as a private API with KVM, and I'd suggest you look into something similar. [...] > > > +#ifdef CONFIG_SMP > > > +static void __imsic_id_smp_sync(struct imsic_priv *priv) > > > +{ > > > + struct imsic_handler *handler; > > > + struct cpumask amask; > > > + int cpu; > > > + > > > + cpumask_and(&amask, &priv->lmask, cpu_online_mask); > > > > Can't this race against a CPU going down? >=20 > Yes, it can race if a CPU goes down while we are in this function > but this won't be a problem because the imsic_starting_cpu() > will unconditionally do imsic_ids_local_sync() when the CPU is > brought-up again. I will add a multiline comment block explaining > this. I'd rather you avoid the race instead of papering over it. >=20 > > > > > + for_each_cpu(cpu, &amask) { > > > + if (cpu =3D=3D smp_processor_id()) > > > + continue; > > > + > > > + handler =3D per_cpu_ptr(&imsic_handlers, cpu); > > > + if (!handler || !handler->priv || !handler->local.msi_v= a) { > > > + pr_warn("CPU%d: handler not initialized\n", cpu= ); > > > > How many times are you going to do that? On each failing synchronisatio= n? >=20 > My bad for adding these paranoid checks. I remove these checks > wherever possible. >=20 > > > > > + continue; > > > + } > > > + > > > + writel(handler->priv->ipi_lsync_id, handler->local.msi_= va); > > > > As I understand it, this is a "behind the scenes" IPI. Why isn't that > > a *real* IPI? >=20 > Yes, that's correct. The ID enable bits are per-CPU accessible only > via CSRs hence we have a special "behind the scenes" IPI to > synchronize state of ID enable bits. My question still stands: why isn't this a *real*, Linux visible IPI? This sideband signalling makes everything hard to follow, hard to debug, and screws up accounting. > > Please split the whole guest stuff out. It is totally unused! >=20 > The number of guest IDs is used by KVM RISC-V AIA support which > is in the pipeline. The KVM RISC-V only need imsic_get_global_config() > and imsic_get_local_config(). The "nr_guest_ids" is part of the > IMSIC global config. And yet it isn't needed for a minimal driver, which what I'd like to see at first. Shoving the kitchen sink into an initial patch isn't a great way to get it merged. M. --=20 Without deviation from the norm, progress is not possible.