From: Marc Zyngier <maz@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oupton@kernel.org>,
Zenghui Yu <yuzenghui@huawei.com>, Will Deacon <will@kernel.org>,
Mostafa Saleh <smostafa@google.com>,
Quentin Perret <qperret@google.com>
Subject: Re: [PATCH 4/5] KVM: arm64: pkvm: Use direct function pointers for cpu_{on,resume}
Date: Mon, 23 Mar 2026 08:43:13 +0000 [thread overview]
Message-ID: <861phb542m.wl-maz@kernel.org> (raw)
In-Reply-To: <CA+EHjTyeuE3aqqmx8Fe4REOM7WstEAp_A0tvMNygPJCLT7V7wQ@mail.gmail.com>
On Sun, 22 Mar 2026 15:49:50 +0000,
Fuad Tabba <tabba@google.com> wrote:
>
> Hi Marc,
>
> On Sat, 21 Mar 2026 at 21:24, Marc Zyngier <maz@kernel.org> wrote:
> >
> > Instead of using a boolean to decide whether a CPU is booting or
> > resuming, just pass an actual function pointer around.
> >
> > This makes the code a bit more straightforward to understand.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> > arch/arm64/include/asm/kvm_asm.h | 3 ++-
> > arch/arm64/kvm/hyp/nvhe/hyp-init.S | 9 +++----
> > arch/arm64/kvm/hyp/nvhe/psci-relay.c | 39 +++++++++++++++++-----------
> > 3 files changed, 29 insertions(+), 22 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
> > index a1ad12c72ebf1..f4c769857fdfc 100644
> > --- a/arch/arm64/include/asm/kvm_asm.h
> > +++ b/arch/arm64/include/asm/kvm_asm.h
> > @@ -291,7 +291,8 @@ asmlinkage void __noreturn hyp_panic_bad_stack(void);
> > asmlinkage void kvm_unexpected_el2_exception(void);
> > struct kvm_cpu_context;
> > void handle_trap(struct kvm_cpu_context *host_ctxt);
> > -asmlinkage void __noreturn __kvm_host_psci_cpu_entry(bool is_cpu_on);
> > +asmlinkage void __noreturn __kvm_host_psci_cpu_on_entry(void);
> > +asmlinkage void __noreturn __kvm_host_psci_cpu_resume_entry(void);
> > void __noreturn __pkvm_init_finalise(void);
> > void kvm_nvhe_prepare_backtrace(unsigned long fp, unsigned long pc);
> > void kvm_patch_vector_branch(struct alt_instr *alt,
> > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
> > index 2e80fcbff2dff..64296b31da73d 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
> > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
> > @@ -173,7 +173,7 @@ SYM_CODE_END(___kvm_hyp_init)
> > * x0: struct kvm_nvhe_init_params PA
> > */
> > SYM_CODE_START(kvm_hyp_cpu_entry)
> > - mov x1, #1 // is_cpu_on = true
> > + ldr x29, =__kvm_host_psci_cpu_on_entry
> > b __kvm_hyp_init_cpu
> >
> > /*
> > @@ -182,11 +182,10 @@ SYM_CODE_START(kvm_hyp_cpu_entry)
> > * x0: struct kvm_nvhe_init_params PA
> > */
> > SYM_CODE_START(kvm_hyp_cpu_resume)
> > - mov x1, #0 // is_cpu_on = false
> > + ldr x29, =__kvm_host_psci_cpu_resume_entry
> >
> > SYM_INNER_LABEL(__kvm_hyp_init_cpu, SYM_L_LOCAL)
> > mov x28, x0 // Stash arguments
> > - mov x29, x1
> >
> > /* Check that the core was booted in EL2. */
> > mrs x0, CurrentEL
> > @@ -204,9 +203,7 @@ SYM_INNER_LABEL(__kvm_hyp_init_cpu, SYM_L_LOCAL)
> > bl ___kvm_hyp_init // Clobbers x0..x2
> >
> > /* Leave idmap -- using BLR is OK, LR is restored from host context */
> > - mov x0, x29
> > - ldr x1, =__kvm_host_psci_cpu_entry
> > - blr x1
> > + blr x29
> >
> > // The core booted in EL1, or the C code unexpectedly returned.
> > // Either way, KVM cannot be initialized on it.
> > diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
> > index c3e196fb8b18f..cc698ceee9c8c 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c
> > +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
> > @@ -200,23 +200,12 @@ static int psci_system_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt)
> > __hyp_pa(init_params), 0);
> > }
> >
> > -asmlinkage void __noreturn __kvm_host_psci_cpu_entry(bool is_cpu_on)
> > +static void __noreturn __kvm_host_psci_cpu_entry(unsigned long pc, unsigned long r0)
> > {
> > - struct psci_boot_args *boot_args;
> > - struct kvm_cpu_context *host_ctxt;
> > -
> > - host_ctxt = host_data_ptr(host_ctxt);
> > -
> > - if (is_cpu_on)
> > - boot_args = this_cpu_ptr(&cpu_on_args);
> > - else
> > - boot_args = this_cpu_ptr(&suspend_args);
> > -
> > - cpu_reg(host_ctxt, 0) = boot_args->r0;
> > - write_sysreg_el2(boot_args->pc, SYS_ELR);
> > + struct kvm_cpu_context *host_ctxt = host_data_ptr(host_ctxt);
> >
> > - if (is_cpu_on)
> > - release_boot_args(boot_args);
> > + cpu_reg(host_ctxt, 0) = r0;
> > + write_sysreg_el2(pc, SYS_ELR);
> >
> > write_sysreg_el1(INIT_SCTLR_EL1_MMU_OFF, SYS_SCTLR);
> > write_sysreg(INIT_PSTATE_EL1, SPSR_EL2);
> > @@ -224,6 +213,26 @@ asmlinkage void __noreturn __kvm_host_psci_cpu_entry(bool is_cpu_on)
> > __host_enter(host_ctxt);
> > }
> >
> > +asmlinkage void __noreturn __kvm_host_psci_cpu_on_entry(void)
> > +{
> > + struct psci_boot_args *boot_args = this_cpu_ptr(&cpu_on_args);
> > + unsigned long pc, r0;
> > +
> > + pc = READ_ONCE(boot_args->pc);
> > + r0 = READ_ONCE(boot_args->r0);
> > +
> > + release_boot_args(boot_args);
> > +
> > + __kvm_host_psci_cpu_entry(pc, r0);
> > +}
> > +
> > +asmlinkage void __noreturn __kvm_host_psci_cpu_resume_entry(void)
> > +{
> > + struct psci_boot_args *boot_args = this_cpu_ptr(&cpu_on_args);
>
> This should be suspend_args:
> + struct psci_boot_args *boot_args = this_cpu_ptr(&suspend_args);
>
Arghhh! How did I miss that??? Thanks a bunch for spotting it!
> With this fixed:
>
> Reviewed-by: Fuad Tabba <tabba@google.com>
Thanks again,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-03-23 8:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-21 21:24 [PATCH 0/5] KVM: arm64: pkvm; Rework aspects of the PSCI relay Marc Zyngier
2026-03-21 21:24 ` [PATCH 1/5] KVM: arm64: pkvm: Move error handling to the end of kvm_hyp_cpu_entry Marc Zyngier
2026-03-22 15:08 ` Fuad Tabba
2026-03-21 21:24 ` [PATCH 2/5] KVM: arm64: pkvm: Simplify BTI handling on CPU boot Marc Zyngier
2026-03-22 15:37 ` Fuad Tabba
2026-03-21 21:24 ` [PATCH 3/5] KVM: arm64: pkvm: Turn __kvm_hyp_init_cpu into an inner label Marc Zyngier
2026-03-22 15:43 ` Fuad Tabba
2026-03-21 21:24 ` [PATCH 4/5] KVM: arm64: pkvm: Use direct function pointers for cpu_{on,resume} Marc Zyngier
2026-03-22 15:49 ` Fuad Tabba
2026-03-23 8:43 ` Marc Zyngier [this message]
2026-03-21 21:24 ` [PATCH 5/5] KVM: arm64: Remove extra ISBs when using msr_hcr_el2 Marc Zyngier
2026-03-22 15:55 ` Fuad Tabba
2026-03-22 15:57 ` [PATCH 0/5] KVM: arm64: pkvm; Rework aspects of the PSCI relay Fuad Tabba
2026-03-23 11:05 ` Marc Zyngier
2026-03-23 12:33 ` Mostafa Saleh
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=861phb542m.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oupton@kernel.org \
--cc=qperret@google.com \
--cc=smostafa@google.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.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.