Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp413161pxm; Fri, 25 Feb 2022 10:23:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoWz1Tg16uVigeoPHOB7AVfMPTQOhmhmyJckiCSgx6thMHGH2oBLnxAtDkci4zeGJw3JR1 X-Received: by 2002:a05:6a00:b49:b0:4cf:432f:9cd9 with SMTP id p9-20020a056a000b4900b004cf432f9cd9mr8807534pfo.10.1645813434090; Fri, 25 Feb 2022 10:23:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645813434; cv=none; d=google.com; s=arc-20160816; b=Vda8RybrSGFxMUgLNSGKXCMf4cmM3l0aJTlPAL3RNSM7yXhfZQOMoPNSTs6nd2jXQ5 N4bTppLG+gl3LIV/yIuZG3jYFnOd1HTXu6LJuxMHTKDbRDIpIhxKy6qeHqbqTrPaoMki FItGIwGJpREjcgeUlHR24iIdO6xzegb3ESFSsAPIKM37Zz4XOxqiqOtyVAnguM9xgAjV PW6KkuKwn+0jGpWZ5cRQ2IzvMH7mmpDa/JuGg4tqBHFbWI5oN7EGmtVbfhaHzD6SXGO5 lmpcTp+5qkLUMfzzLSD0rfi1sD9V+eotgevm6jB5X2NWJgAmmRPy5exWlBQyPpHmHFiV CgKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=pXlj0aLGTLRlKS+hA61fEQri2aSN3SggfBAhnUKPYrw=; b=TfBg4CBtIWYtK1zKLGTWyuECeremhSB6L2wtyGp1m8DdeYM+OsMcs4FcB0u2umInkg HKgOCTQ51rCVougCXfdfnFYvpyobdHBLXhIqJo0xTCB2OhBsmYsL9W5Co1mzB/8A3OfW ppSEwme7ufYIiv0+yM/DV73rJeUYNCQPOWxQNlUOXaoTDvmg7gLP2ctXmERhZZryA3Ei g7C7vrjODb5Vkbj3aVN6GYRfY623NA/mGNoUFdSsxn/UqV/zjHPmEKh8qY6pD38mt04q 6kEXZzYHIWXYAF4fGCmYDjuW9BZITuxPjp8gI80FKZnNtLrGlD9epbOq7+HMdfMP2Dte PK0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dvMXNfEp; 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 a13-20020a170902710d00b0014ed3d4b5d3si2208483pll.384.2022.02.25.10.23.37; Fri, 25 Feb 2022 10:23:54 -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=@kernel.org header.s=k20201202 header.b=dvMXNfEp; 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 S240371AbiBYOkB (ORCPT + 99 others); Fri, 25 Feb 2022 09:40:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbiBYOkA (ORCPT ); Fri, 25 Feb 2022 09:40:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84FBA1D21D1; Fri, 25 Feb 2022 06:39:28 -0800 (PST) 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 1A738614BD; Fri, 25 Feb 2022 14:39:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AEAEC340E7; Fri, 25 Feb 2022 14:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645799967; bh=cNgfaXX/ZY2ofKk0wyVNQWz4wXK1w3ilqbl4W9JFkyQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dvMXNfEp5LbXneNtmXndDp6B4ROeUk4WyLcH3nwf6ImqOwMzQvlPqEFJM2qEUSiSn gVh/AmdWq7Cqr5hGjd8II945ud7TiUXtTqSnIQjesKin91DmTgISJTs+NV05TiaWLY RNJOmY0uuhTa938PoQnNxCQlOews8NGtk5V3dElPnYvNMvdUKgJD3SGOW3wZ6rn3On w8+HeRrHlfLy3e1+a9SR4S9hi0ipxh6ZYRzgeRFD+IxshliLFDdICby0cUIvr1CN7G l44qdugBtMNxITvpEIu0sD/Ctm+EUk6xGPvbUuzrrCVoDrgs/TL7YqNn1DM0jhrbCA TeCSBXkgWSb3A== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nNbkj-00AYAh-6t; Fri, 25 Feb 2022 14:39:25 +0000 Date: Fri, 25 Feb 2022 14:39:24 +0000 Message-ID: <87mtif2eoz.wl-maz@kernel.org> From: Marc Zyngier To: Hector Martin Cc: Thomas Gleixner , Rob Herring , Sven Peter , Alyssa Rosenzweig , Mark Kettenis , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v2 3/7] irqchip/apple-aic: Add Fast IPI support In-Reply-To: <20220224130741.63924-4-marcan@marcan.st> References: <20220224130741.63924-1-marcan@marcan.st> <20220224130741.63924-4-marcan@marcan.st> 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/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: marcan@marcan.st, tglx@linutronix.de, robh+dt@kernel.org, sven@svenpeter.dev, alyssa@rosenzweig.io, mark.kettenis@xs4all.nl, linux-arm-kernel@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.1 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 Thu, 24 Feb 2022 13:07:37 +0000, Hector Martin wrote: > > The newer AICv2 present in t600x SoCs does not have legacy IPI support > at all. Since t8103 also supports Fast IPIs, implement support for this > first. The legacy IPI code is left as a fallback, so it can be > potentially used by older SoCs in the future. > > The vIPI code is shared; only the IPI firing/acking bits change for Fast > IPIs. > > Signed-off-by: Hector Martin > --- > drivers/irqchip/irq-apple-aic.c | 122 ++++++++++++++++++++++++++++---- > 1 file changed, 109 insertions(+), 13 deletions(-) > > diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c > index 38091ebb9403..613e0ebdabdc 100644 > --- a/drivers/irqchip/irq-apple-aic.c > +++ b/drivers/irqchip/irq-apple-aic.c > @@ -24,7 +24,7 @@ > * - Default "this CPU" register view and explicit per-CPU views > * > * In addition, this driver also handles FIQs, as these are routed to the same > - * IRQ vector. These are used for Fast IPIs (TODO), the ARMv8 timer IRQs, and > + * IRQ vector. These are used for Fast IPIs, the ARMv8 timer IRQs, and > * performance counters (TODO). > * > * Implementation notes: > @@ -52,9 +52,11 @@ > #include > #include > #include > +#include > #include > #include > #include > +#include > #include > #include > #include > @@ -106,7 +108,6 @@ > > /* > * IMP-DEF sysregs that control FIQ sources > - * Note: sysreg-based IPIs are not supported yet. > */ > > /* Core PMC control register */ > @@ -155,6 +156,10 @@ > #define SYS_IMP_APL_UPMSR_EL1 sys_reg(3, 7, 15, 6, 4) > #define UPMSR_IACT BIT(0) > > +/* MPIDR fields */ > +#define MPIDR_CPU(x) MPIDR_AFFINITY_LEVEL(x, 0) > +#define MPIDR_CLUSTER(x) MPIDR_AFFINITY_LEVEL(x, 1) > + > #define AIC_NR_FIQ 4 > #define AIC_NR_SWIPI 32 > > @@ -173,11 +178,44 @@ > #define AIC_TMR_EL02_PHYS AIC_TMR_GUEST_PHYS > #define AIC_TMR_EL02_VIRT AIC_TMR_GUEST_VIRT > > +DEFINE_STATIC_KEY_TRUE(use_fast_ipi); > + > +struct aic_info { > + int version; > + > + /* Features */ > + bool fast_ipi; > +}; > + > +static const struct aic_info aic1_info = { > + .version = 1, > +}; > + > +static const struct aic_info aic1_fipi_info = { > + .version = 1, > + > + .fast_ipi = true, > +}; > + > +static const struct of_device_id aic_info_match[] = { > + { > + .compatible = "apple,t8103-aic", > + .data = &aic1_fipi_info, > + }, > + { > + .compatible = "apple,aic", > + .data = &aic1_info, > + }, > + {} > +}; > + > struct aic_irq_chip { > void __iomem *base; > struct irq_domain *hw_domain; > struct irq_domain *ipi_domain; > int nr_hw; > + > + struct aic_info info; > }; > > static DEFINE_PER_CPU(uint32_t, aic_fiq_unmasked); > @@ -386,8 +424,12 @@ static void __exception_irq_entry aic_handle_fiq(struct pt_regs *regs) > */ > > if (read_sysreg_s(SYS_IMP_APL_IPI_SR_EL1) & IPI_SR_PENDING) { > - pr_err_ratelimited("Fast IPI fired. Acking.\n"); > - write_sysreg_s(IPI_SR_PENDING, SYS_IMP_APL_IPI_SR_EL1); > + if (static_branch_likely(&use_fast_ipi)) { > + aic_handle_ipi(regs); > + } else { > + pr_err_ratelimited("Fast IPI fired. Acking.\n"); > + write_sysreg_s(IPI_SR_PENDING, SYS_IMP_APL_IPI_SR_EL1); > + } > } > > if (TIMER_FIRING(read_sysreg(cntp_ctl_el0))) > @@ -563,6 +605,22 @@ static const struct irq_domain_ops aic_irq_domain_ops = { > * IPI irqchip > */ > > +static void aic_ipi_send_fast(int cpu) > +{ > + u64 mpidr = cpu_logical_map(cpu); > + u64 my_mpidr = read_cpuid_mpidr(); > + u64 cluster = MPIDR_CLUSTER(mpidr); > + u64 idx = MPIDR_CPU(mpidr); > + > + if (MPIDR_CLUSTER(my_mpidr) == cluster) > + write_sysreg_s(FIELD_PREP(IPI_RR_CPU, idx), > + SYS_IMP_APL_IPI_RR_LOCAL_EL1); > + else > + write_sysreg_s(FIELD_PREP(IPI_RR_CPU, idx) | FIELD_PREP(IPI_RR_CLUSTER, cluster), > + SYS_IMP_APL_IPI_RR_GLOBAL_EL1); > + isb(); I think you have an ordering issue with this, see below. > +} > + > static void aic_ipi_mask(struct irq_data *d) > { > u32 irq_bit = BIT(irqd_to_hwirq(d)); > @@ -588,8 +646,12 @@ static void aic_ipi_unmask(struct irq_data *d) > * If a pending vIPI was unmasked, raise a HW IPI to ourselves. > * No barriers needed here since this is a self-IPI. > */ > - if (atomic_read(this_cpu_ptr(&aic_vipi_flag)) & irq_bit) > - aic_ic_write(ic, AIC_IPI_SEND, AIC_IPI_SEND_CPU(smp_processor_id())); > + if (atomic_read(this_cpu_ptr(&aic_vipi_flag)) & irq_bit) { > + if (static_branch_likely(&use_fast_ipi)) > + aic_ipi_send_fast(smp_processor_id()); > + else > + aic_ic_write(ic, AIC_IPI_SEND, AIC_IPI_SEND_CPU(smp_processor_id())); > + } > } > > static void aic_ipi_send_mask(struct irq_data *d, const struct cpumask *mask) > @@ -617,8 +679,12 @@ static void aic_ipi_send_mask(struct irq_data *d, const struct cpumask *mask) > smp_mb__after_atomic(); > > if (!(pending & irq_bit) && > - (atomic_read(per_cpu_ptr(&aic_vipi_enable, cpu)) & irq_bit)) > - send |= AIC_IPI_SEND_CPU(cpu); > + (atomic_read(per_cpu_ptr(&aic_vipi_enable, cpu)) & irq_bit)) { > + if (static_branch_likely(&use_fast_ipi)) > + aic_ipi_send_fast(cpu); OK, this is suffering from the same issue that GICv3 has, which is that memory barriers don't provide order against sysregs. You need a DSB for that, which is a pain. Something like this: diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index 602c8b274170..579f22b72339 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -736,6 +736,15 @@ static void aic_ipi_send_fast(int cpu) u64 cluster = MPIDR_CLUSTER(mpidr); u64 idx = MPIDR_CPU(mpidr); + /* + * A DSB is required here in to order prior writes to memory + * with system register accesses having a side effect + * (matching the behaviour of the IPI registers). Make sure we + * only order stores with in the IS domain, keeping as light + * as possible. + */ + dsb(ishst); + if (MPIDR_CLUSTER(my_mpidr) == cluster) write_sysreg_s(FIELD_PREP(IPI_RR_CPU, idx), SYS_IMP_APL_IPI_RR_LOCAL_EL1); Thanks, M. -- Without deviation from the norm, progress is not possible.