All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Will Deacon <will@kernel.org>
Cc: Ben Horgan <ben.horgan@arm.com>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Oliver Upton <oupton@kernel.org>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Hyesoo Yu <hyesoo.yu@samsung.com>,
	Quentin Perret <qperret@google.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] arm64: Force the use of CNTVCT_EL0 in __delay()
Date: Thu, 26 Feb 2026 08:16:57 +0000	[thread overview]
Message-ID: <875x7jex6u.wl-maz@kernel.org> (raw)
In-Reply-To: <aZ95V8XIYYysd13m@willie-the-truck>

On Wed, 25 Feb 2026 22:36:07 +0000,
Will Deacon <will@kernel.org> wrote:
> 
> On Mon, Feb 23, 2026 at 02:31:44PM +0000, Marc Zyngier wrote:
> > Crucially, arch_counter_get_cntvct_stable() does disable preemption,
> > and we should preserve it. Something like this:
> > 
> > diff --git a/arch/arm64/lib/delay.c b/arch/arm64/lib/delay.c
> > index d02341303899e..25fb593f95b0c 100644
> > --- a/arch/arm64/lib/delay.c
> > +++ b/arch/arm64/lib/delay.c
> > @@ -32,7 +32,16 @@ static inline unsigned long xloops_to_cycles(unsigned long xloops)
> >   * Note that userspace cannot change the offset behind our back either,
> >   * as the vcpu mutex is held as long as KVM_RUN is in progress.
> >   */
> > -#define __delay_cycles()	__arch_counter_get_cntvct_stable()
> > +static cycles_t __delay_cycles(void)
> > +{
> > +	cycles_t val;
> > +
> > +	preempt_disable();
> > +	val = __arch_counter_get_cntvct_stable();
> > +	preenpt_enable();
> > +
> > +	return val;
> > +}
> 
> (nit: arch_counter_get_cntvct_stable() uses the _notrace() variants of
>  the preempt disable/enable helpers)

That's because arch_counter_get_cntvct_stable() itself is notrace.
I'm not sure we need this function to be notrace as well, but I'll
change that and we can revisit it.

> 
> >  void __delay(unsigned long cycles)
> >  {
> > 
> > The question is whether there is a material benefit in replicating the
> > arch_timer_read_counter() indirection for the virtual counter in order
> > to not pay the price of preempt_disable() when we're on a non-broken
> > system (hopefully the vast majority of implementations).
> 
> That sounds nice, especially as we can assume (for now) that CPUs
> implementing WFIT don't need the cntvct workarounds. However, I can't
> really figure out how to implement it after reminding myself of all the
> fun we had trying to use a static key for these workarounds in the past.
>
> If a CPU being onlined has a timer erratum, we wouldn't be able to
> migrate any tasks in the middle of a preempt-enabled delay loop onto
> it. :/

Why would it be any different than, say, sched_clock(), which
ultimately uses arch_timer_read_counter()? We already rely on this
indirection to do the right thing everywhere, and I don't recall we
have any issue with this.

Anyway, I'll shortly post what I have and we can discuss whether this
is the correct approach.

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.

      reply	other threads:[~2026-02-26  8:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-13 14:16 [PATCH] arm64: Force the use of CNTVCT_EL0 in __delay() Marc Zyngier
2026-02-19 13:27 ` Will Deacon
2026-02-23 11:16 ` Ben Horgan
2026-02-23 14:31   ` Marc Zyngier
2026-02-23 15:14     ` Ben Horgan
2026-02-25 22:36     ` Will Deacon
2026-02-26  8:16       ` Marc Zyngier [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=875x7jex6u.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=ben.horgan@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=hyesoo.yu@samsung.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=oupton@kernel.org \
    --cc=qperret@google.com \
    --cc=stable@vger.kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.