mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Sven Peter" <sven@svenpeter.dev>
To: "Nick Chan" <towinchenmi@gmail.com>,
	"Hector Martin" <marcan@marcan.st>,
	"Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	"Konrad Dybcio" <konrad.dybcio@somainline.org>
Cc: ~postmarketos/upstreaming@lists.sr.ht
Subject: Re: [PATCH v2 4/4] irqchip/apple-aic: Only access system registers on SoCs which provide them
Date: Sat, 31 Aug 2024 12:01:39 +0200	[thread overview]
Message-ID: <43a31087-0e3a-4684-87e3-26c22bd5a4c9@app.fastmail.com> (raw)
In-Reply-To: <20240831055605.3542-6-towinchenmi@gmail.com>



On Sat, Aug 31, 2024, at 07:48, Nick Chan wrote:
> From: Konrad Dybcio <konrad.dybcio@somainline.org>
>
> Starting from the A11 (T8015) SoC, Apple introuced system registers for
> fast IPI and UNCORE PMC control. These sysregs do not exist on earlier
> A7-A10 SoCs and trying to access them results in an instant crash.
>
> Restrict sysreg access within the AIC driver to configurations where
> use_fast_ipi is true to allow AIC to function properly on A7-A10 SoCs.
> As part of the restriction, the IPI-always-ack path in aic_handle_fiq()
> has been removed. If the code path were to be reached, the system is
> fast IPI capable and one of the fast IPI compatibles should be used
> instead.

The last part is a bit weird. This is really just a bug in the driver.
We either have a system with fastipi and then we can handle it.
Or we have a system without fastipi and we shouldn't even try to read
SYS_IMP_APL_IPI_SR_EL1.
Your first sentence  "Restrict sysreg access within the AIC driver to
configurations where use_fast_ipi is true to allow AIC to function properly
on A7-A10 SoCs." already explains what's going on here. You're fixing
a bug where we tried to access SYS_IMP_APL_IPI_SR_EL1 unconditionally.
It just didn't matter so far because there's only upstream support
for M1+ where SYS_IMP_APL_IPI_SR_EL1 always exist.

With a fixed commit message:

Reviewed-by: Sven Peter <sven@svenpeter.dev>

>
> Signed-off-by: Konrad Dybcio <konrad.dybcio@somainline.org>
> Co-developed-by: Nick Chan <towinchenmi@gmail.com>
> Signed-off-by: Nick Chan <towinchenmi@gmail.com>
> ---
>  drivers/irqchip/irq-apple-aic.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c
> index 01a3c79054f5..a6d812afb10d 100644
> --- a/drivers/irqchip/irq-apple-aic.c
> +++ b/drivers/irqchip/irq-apple-aic.c
> @@ -234,6 +234,7 @@ enum fiq_hwirq {
>  	AIC_NR_FIQ
>  };
> 
> +/* True if UNCORE/UNCORE2 and Sn_... IPI registers are present and 
> used (A11+) */
>  static DEFINE_STATIC_KEY_TRUE(use_fast_ipi);
>  /* True if SYS_IMP_APL_IPI_RR_LOCAL_EL1 exists for local fast IPIs 
> (M1+) */
>  static DEFINE_STATIC_KEY_TRUE(use_local_fast_ipi);
> @@ -550,14 +551,9 @@ static void __exception_irq_entry 
> aic_handle_fiq(struct pt_regs *regs)
>  	 * we check for everything here, even things we don't support yet.
>  	 */
> 
> -	if (read_sysreg_s(SYS_IMP_APL_IPI_SR_EL1) & IPI_SR_PENDING) {
> -		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 (static_branch_likely(&use_fast_ipi) &&
> +	    (read_sysreg_s(SYS_IMP_APL_IPI_SR_EL1) & IPI_SR_PENDING))
> +		aic_handle_ipi(regs);
> 
>  	if (TIMER_FIRING(read_sysreg(cntp_ctl_el0)))
>  		generic_handle_domain_irq(aic_irqc->hw_domain,
> @@ -592,8 +588,9 @@ static void __exception_irq_entry 
> aic_handle_fiq(struct pt_regs *regs)
>  					  AIC_FIQ_HWIRQ(irq));
>  	}
> 
> -	if (FIELD_GET(UPMCR0_IMODE, read_sysreg_s(SYS_IMP_APL_UPMCR0_EL1)) == 
> UPMCR0_IMODE_FIQ &&
> -			(read_sysreg_s(SYS_IMP_APL_UPMSR_EL1) & UPMSR_IACT)) {
> +	if (static_branch_likely(&use_fast_ipi) &&
> +	    (FIELD_GET(UPMCR0_IMODE, read_sysreg_s(SYS_IMP_APL_UPMCR0_EL1)) 
> == UPMCR0_IMODE_FIQ) &&
> +	    (read_sysreg_s(SYS_IMP_APL_UPMSR_EL1) & UPMSR_IACT)) {
>  		/* Same story with uncore PMCs */
>  		pr_err_ratelimited("Uncore PMC FIQ fired. Masking.\n");
>  		sysreg_clear_set_s(SYS_IMP_APL_UPMCR0_EL1, UPMCR0_IMODE,
> @@ -830,7 +827,8 @@ static int aic_init_cpu(unsigned int cpu)
>  	/* Mask all hard-wired per-CPU IRQ/FIQ sources */
> 
>  	/* Pending Fast IPI FIQs */
> -	write_sysreg_s(IPI_SR_PENDING, SYS_IMP_APL_IPI_SR_EL1);
> +	if (static_branch_likely(&use_fast_ipi))
> +		write_sysreg_s(IPI_SR_PENDING, SYS_IMP_APL_IPI_SR_EL1);
> 
>  	/* Timer FIQs */
>  	sysreg_clear_set(cntp_ctl_el0, 0, ARCH_TIMER_CTRL_IT_MASK);
> @@ -851,8 +849,9 @@ static int aic_init_cpu(unsigned int cpu)
>  			   FIELD_PREP(PMCR0_IMODE, PMCR0_IMODE_OFF));
> 
>  	/* Uncore PMC FIQ */
> -	sysreg_clear_set_s(SYS_IMP_APL_UPMCR0_EL1, UPMCR0_IMODE,
> -			   FIELD_PREP(UPMCR0_IMODE, UPMCR0_IMODE_OFF));
> +	if (static_branch_likely(&use_fast_ipi))
> +		sysreg_clear_set_s(SYS_IMP_APL_UPMCR0_EL1, UPMCR0_IMODE,
> +				   FIELD_PREP(UPMCR0_IMODE, UPMCR0_IMODE_OFF));
> 
>  	/* Commit all of the above */
>  	isb();
> -- 
> 2.46.0

      reply	other threads:[~2024-08-31 10:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-31  5:48 [PATCH v2 0/4] Add support for A7-A11 AIC Nick Chan
2024-08-31  5:48 ` [PATCH v2 1/4] dt-bindings: apple,aic: Document A7-A11 compatibles Nick Chan
2024-08-31  6:34   ` Krzysztof Kozlowski
2024-08-31  6:43   ` Sven Peter
2024-08-31  5:48 ` [PATCH v2 2/4] irqchip/apple-aic: Skip unnecessary setting of use_fast_ipi Nick Chan
2024-08-31  6:48   ` Sven Peter
2024-08-31  5:48 ` [PATCH v2 3/4] irqchip/apple-aic: Add a new "Global fast IPIs only" feature level Nick Chan
2024-08-31  7:05   ` Sven Peter
2024-08-31  5:48 ` [PATCH v2 4/4] irqchip/apple-aic: Only access system registers on SoCs which provide them Nick Chan
2024-08-31 10:01   ` Sven Peter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43a31087-0e3a-4684-87e3-26c22bd5a4c9@app.fastmail.com \
    --to=sven@svenpeter.dev \
    --cc=alyssa@rosenzweig.io \
    --cc=asahi@lists.linux.dev \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=robh@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=towinchenmi@gmail.com \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®