From: Marc Zyngier <maz@kernel.org>
To: Andre Przywara <andre.przywara@arm.com>
Cc: Alexandru Elisei <alexandru.elisei@arm.com>,
Will Deacon <will@kernel.org>,
Julien Thierry <julien.thierry.kdev@gmail.com>,
<kvm@vger.kernel.org>, <kvmarm@lists.linux.dev>
Subject: Re: [PATCH kvmtool v3 6/6] arm64: Generate HYP timer interrupt specifiers
Date: Tue, 23 Sep 2025 19:16:19 +0100 [thread overview]
Message-ID: <86bjn111cc.wl-maz@kernel.org> (raw)
In-Reply-To: <20250923172115.4a739ac5@donnerap.manchester.arm.com>
On Tue, 23 Sep 2025 17:21:15 +0100,
Andre Przywara <andre.przywara@arm.com> wrote:
>
> On Mon, 4 Aug 2025 15:47:55 +0100
> Alexandru Elisei <alexandru.elisei@arm.com> wrote:
>
> Hi,
>
> > On Tue, Jul 29, 2025 at 10:57:45AM +0100, Andre Przywara wrote:
> > > From: Marc Zyngier <maz@kernel.org>
> > >
> > > FEAT_VHE introduced a non-secure EL2 virtual timer, along with its
> > > interrupt line. Consequently the arch timer DT binding introduced a fifth
> > > interrupt to communicate this interrupt number.
> > >
> > > Refactor the interrupts property generation code to deal with a variable
> > > number of interrupts, and forward five interrupts instead of four in case
> > > nested virt is enabled.
> > >
> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > > ---
> > > arm64/arm-cpu.c | 4 +---
> > > arm64/include/kvm/timer.h | 2 +-
> > > arm64/timer.c | 29 ++++++++++++-----------------
> > > 3 files changed, 14 insertions(+), 21 deletions(-)
> > >
> > > diff --git a/arm64/arm-cpu.c b/arm64/arm-cpu.c
> > > index 1e456f2c6..abdd6324f 100644
> > > --- a/arm64/arm-cpu.c
> > > +++ b/arm64/arm-cpu.c
> > > @@ -12,11 +12,9 @@
> > >
> > > static void generate_fdt_nodes(void *fdt, struct kvm *kvm)
> > > {
> > > - int timer_interrupts[4] = {13, 14, 11, 10};
> > > -
> > > gic__generate_fdt_nodes(fdt, kvm->cfg.arch.irqchip,
> > > kvm->cfg.arch.nested_virt);
> > > - timer__generate_fdt_nodes(fdt, kvm, timer_interrupts);
> > > + timer__generate_fdt_nodes(fdt, kvm);
> > > pmu__generate_fdt_nodes(fdt, kvm);
> > > }
> > >
> > > diff --git a/arm64/include/kvm/timer.h b/arm64/include/kvm/timer.h
> > > index 928e9ea7a..81e093e46 100644
> > > --- a/arm64/include/kvm/timer.h
> > > +++ b/arm64/include/kvm/timer.h
> > > @@ -1,6 +1,6 @@
> > > #ifndef ARM_COMMON__TIMER_H
> > > #define ARM_COMMON__TIMER_H
> > >
> > > -void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm, int *irqs);
> > > +void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm);
> > >
> > > #endif /* ARM_COMMON__TIMER_H */
> > > diff --git a/arm64/timer.c b/arm64/timer.c
> > > index 861f2d994..2ac6144f9 100644
> > > --- a/arm64/timer.c
> > > +++ b/arm64/timer.c
> > > @@ -5,31 +5,26 @@
> > > #include "kvm/timer.h"
> > > #include "kvm/util.h"
> > >
> > > -void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm, int *irqs)
> > > +void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm)
> > > {
> > > const char compatible[] = "arm,armv8-timer\0arm,armv7-timer";
> > > u32 cpu_mask = gic__get_fdt_irq_cpumask(kvm);
> > > - u32 irq_prop[] = {
> > > - cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI),
> > > - cpu_to_fdt32(irqs[0]),
> > > - cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW),
> > > + int irqs[5] = {13, 14, 11, 10, 12};
> > > + int nr = ARRAY_SIZE(irqs);
> > > + u32 irq_prop[nr * 3];
> > >
> > > - cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI),
> > > - cpu_to_fdt32(irqs[1]),
> > > - cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW),
> > > + if (!kvm->cfg.arch.nested_virt)
> > > + nr--;
> >
> > I'm confused.
> >
> > FEAT_VHE introduced the EL2 virtual timer, and my interpretation of the Arm ARM
> > is that the EL2 virtual timer is present if an only if FEAT_VHE:
> >
> > "In an implementation of the Generic Timer that includes EL3, if EL3 can use
> > AArch64, the following timers are implemented:
> > [..]
> > * When FEAT_VHE is implemented, a Non-secure EL2 virtual timer."
> >
> > Is my interpretation correct?
> >
> > KVM doesn't allow FEAT_VHE and FEAT_E2H0 to coexist (in
> > nested.c::limit_nv_id_reg()), to force E2H to be RES0. Assuming my interpretion
> > is correct, shouldn't the check be:
>
> Even at the risk of going even deeper into that nitpicking rabbit hole:
> "If FEAT_E2H0 is implemented, then FEAT_VHE is implemented."
This is written as such not to make ARMv8.0 illegal, as E2H is RES0
there. Yes, this is odd, but there is a logic behind it.
> So we have that timer, regardless of FEAT_E2H0, and regardless of whether
> HCR_EL2.E2H is actually 0 or 1?
> And indeed the configuration stanza and the pseudocode in "D24.10.9
> CNTHV_CTL_EL2, Counter-timer Virtual Timer Control Register (EL2)" do not
> mention SCR_EL2.E2H0 at all, just FEAT_VHE.
That's mostly a KVM bug. If we want to pretend we don't have VHE, then
CNTHV_*_EL2 must UNDEF, which isn't a big deal.
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2025-09-23 18:16 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 9:57 [PATCH kvmtool v3 0/6] arm64: Nested virtualization support Andre Przywara
2025-07-29 9:57 ` [PATCH kvmtool v3 1/6] Sync kernel UAPI headers with v6.16 Andre Przywara
2025-07-29 9:57 ` [PATCH kvmtool v3 2/6] arm64: Initial nested virt support Andre Przywara
2025-08-04 14:41 ` Alexandru Elisei
2025-08-04 17:45 ` Marc Zyngier
2025-09-16 12:15 ` Andre Przywara
2025-07-29 9:57 ` [PATCH kvmtool v3 3/6] arm64: nested: add support for setting maintenance IRQ Andre Przywara
2025-08-04 14:43 ` Alexandru Elisei
2025-08-04 17:51 ` Marc Zyngier
2025-09-16 12:16 ` Andre Przywara
2025-07-29 9:57 ` [PATCH kvmtool v3 4/6] arm64: add counter offset control Andre Przywara
2025-08-04 14:45 ` Alexandru Elisei
2025-08-04 17:57 ` Marc Zyngier
2025-09-16 12:17 ` Andre Przywara
2025-07-29 9:57 ` [PATCH kvmtool v3 5/6] arm64: add FEAT_E2H0 support Andre Przywara
2025-08-04 14:45 ` Alexandru Elisei
2025-08-04 18:11 ` Marc Zyngier
2025-07-29 9:57 ` [PATCH kvmtool v3 6/6] arm64: Generate HYP timer interrupt specifiers Andre Przywara
2025-08-04 14:47 ` Alexandru Elisei
2025-08-04 18:15 ` Marc Zyngier
2025-09-23 16:21 ` Andre Przywara
2025-09-23 18:16 ` Marc Zyngier [this message]
2025-07-29 10:03 ` [PATCH kvmtool v3 0/6] arm64: Nested virtualization support Marc Zyngier
2025-09-08 13:25 ` Will Deacon
2025-09-16 8:51 ` Andre Przywara
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=86bjn111cc.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=alexandru.elisei@arm.com \
--cc=andre.przywara@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--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