public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
To: Marc Zyngier <maz@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
	Will Deacon <will@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Valentin Schneider <valentin.schneider@arm.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Russell King <linux@armlinux.org.uk>,
	kernel-team@android.com
Subject: Re: [PATCH 0/3] arm64: Fix cpuidle with pseudo-NMI enabled
Date: Fri, 11 Jun 2021 10:41:34 +0100	[thread overview]
Message-ID: <20210611094134.GA2789@lpieralisi> (raw)
In-Reply-To: <87eed8reyd.wl-maz@kernel.org>

On Fri, Jun 11, 2021 at 09:19:22AM +0100, Marc Zyngier wrote:
> Hi Lorenzo,
> 
> On Thu, 10 Jun 2021 17:28:23 +0100,
> Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:
> > 
> > On Tue, Jun 08, 2021 at 06:27:12PM +0100, Marc Zyngier wrote:
> > > It appears that although cpu_do_idle() is correctly dealing with the
> > > PMR/DAIF duality, the PSCI cpu-suspend code has been left unaware of
> > > it.
> > > 
> > > On a system that uses PSCI for idle (such as the Ampere Altra I have
> > > access to), the kernel dies as soon as it enters idle (interrupts are
> > > off at the GIC CPU interface level). Boo.
> > 
> > After investigating a bit I realised that this should depend on
> > ICC_CTLR_EL3.PMHE - if that's clear the PMR should not affect the
> > GICR->CPU IRQ forwarding (or WakeRequest signal generation when the
> > GICR_WAKER.ProcessorSleep==1).
> 
> You lost me here. I don't see what PMHE has to do here. It is solely
> used for 1:N distribution, and is the only way PMR does affect the
> propagation of interrupts to the CPU interface. Fortunately, nobody
> uses 1:N.
> 
> > IIUC if PMHE == 0, the PMR plays no role in wfi completion (and
> > WakeSignal generation for a CPU/GICR in quiescent state).
> 
> Of course it does. PMR gates interrupts *before* they are signalled to
> the CPU, meaning that if you keep interrupt masked at the PMR level,
> you will never wake up from WFI. Or am I missing your point entirely?

For "simple" wfi (as in executing the wfi instruction) yes. The
IRQs are forwarded to the CPU interface that filters the IRQs based
on priorities and signal the I/F "pin" so that the core wakes up
and wfi completes - forgive me my misunderstanding.

For deep sleep states where GICR_WAKER.ProcessorSleep == 1, the
WakeSignal (ie CPU reset) is generated independently of the PMR
value AFAIK. This means that even *if* an IRQ is supposed to be
masked by the PMR it would wake up a sleeping core _anyway_.

This behaviour is different from shallow C-states (and simple wfi).

That's why I asked what path is causing trouble in
psci_cpu_suspend_enter().

> > I assume on Ampere Altra PMHE == 1.
> 
> No, it is 0, as indicated by:
> 
> <quote>
> [    0.000000] GICv3: Pseudo-NMIs enabled using relaxed ICC_PMR_EL1 synchronisation
> </quote>
> 
> > This changes almost nothing to the need for this patchset but
> > at least we clarify this behaviour.
> > 
> > Also, we should not be writing ICC_PMR_EL1 when
> > GICR_WAKER.ProcessorSleep == 1 (which may be set in
> > gic_cpu_pm_notifier()), this can hang the system.
> 
> Why? PMR defines what interrupts will be presented to the CPU
> interface and trigger an exception. It doesn't affect putting the CPU
> to sleep nor the wake-up.

I don't think we are allowed to have traffic between the CPU IF and
the GICR when ProcessorSleep == 1. So, again IIUC, we can't write
the PMR (if PMHE == 1) after putting the GICR in ProcessorSleep ==1 
because this would sync with the GICR.

> > I wonder whether this arm_cpuidle_{save,restore}_context() should
> > be moved into the gic_cpu_pm_notifier() itself - which would
> > solve also the PSCI suspend issue Sudeep raised - it would be
> 
> Moving from PMR to DAIF masking is something we only do on particular
> spots (exception entry/exit, guest entry/exit) as it affects the
> behaviour of simple things such as local_irq_*(). Moving it to a
> higher level feels super dangerous.

Yes it is dangerous and ugly. It is also true that what needs to
be saved/restore on idle entry is becoming extremely complicated
and hard to track across kernel subsystems and that's unfortunate
too, that's what is causing these bugs.

Thanks,
Lorenzo

> > a bit ugly though (CPU PM notifiers are run in S2R and CPUidle
> > automatically and this would work for any S2R/CPUidle backend
> > other than PSCI even though that does not/will never exist on
> > arm64 ;-))
> >
> > https://lore.kernel.org/linux-arm-kernel/20210608182044.ayqa6fbab4jyz7kp@bogus
> > 
> > I still believe this series is right - just raised these points
> > for discussion.
> 
> Thanks,
> 
> 	M.
> 
> -- 
> Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-06-11  9:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 17:27 [PATCH 0/3] arm64: Fix cpuidle with pseudo-NMI enabled Marc Zyngier
2021-06-08 17:27 ` [PATCH 1/3] arm64: Add cpuidle context save/restore helpers Marc Zyngier
2021-06-11 16:46   ` Lorenzo Pieralisi
2021-06-12 12:04     ` Marc Zyngier
2021-06-16 12:07       ` Lorenzo Pieralisi
2021-06-08 17:27 ` [PATCH 2/3] arm64: Convert cpu_do_idle() to using cpuidle context helpers Marc Zyngier
2021-06-11 16:48   ` Lorenzo Pieralisi
2021-06-08 17:27 ` [PATCH 3/3] PSCI: Use cpuidle context helpers in psci_cpu_suspend_enter() Marc Zyngier
2021-06-08 18:20   ` Sudeep Holla
2021-06-11 16:49   ` Lorenzo Pieralisi
2021-06-09 14:46 ` [PATCH 0/3] arm64: Fix cpuidle with pseudo-NMI enabled Valentin Schneider
2021-06-09 14:58 ` Valentin Schneider
2021-06-10 16:28 ` Lorenzo Pieralisi
2021-06-10 17:43   ` Sudeep Holla
2021-06-11  8:24     ` Marc Zyngier
2021-06-11  8:19   ` Marc Zyngier
2021-06-11  9:41     ` Lorenzo Pieralisi [this message]
2021-06-11 11:32       ` Marc Zyngier

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=20210611094134.GA2789@lpieralisi \
    --to=lorenzo.pieralisi@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=kernel-team@android.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=valentin.schneider@arm.com \
    --cc=will@kernel.org \
    /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