From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A42A1382F1F; Mon, 23 Mar 2026 08:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774255397; cv=none; b=Ss8zkkZBBS6XAL/3IFewJ45gyCkndBuv3ywV+g1DqnR6XRhbKLP6Q4jcS7b/8HCFveK6EvR1IvR3ubGqx+5AfmrdQxEhdqG2u3a3tcEBRFpAHiyHZpWpsCVgv4VpM6n6zxuSaKFBIPk6msSDMKNUlHqkrGBiN780brUZl3l+2sk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774255397; c=relaxed/simple; bh=hI/WjybrpXzNAFHT59gckSTLPeS76ZpD3rBAeQW1h9c=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=CktP0oFPlBN/uj8pi0R44gulh95DL1bh0Mcsk+E2gNjf9VleS3xxVOfZ3HHlPP5Jku/vvzS0/hZbupjwGX8TVZ9BLis/QCGXPA46q6lWpPWm9sxDx5YMny43LULX43n/Th427Yq9/tQI2bdkZwL2wtgtNPdBlE//gp8G0Ty4lzk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DfFJTb2M; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DfFJTb2M" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3FF9C4CEF7; Mon, 23 Mar 2026 08:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774255396; bh=hI/WjybrpXzNAFHT59gckSTLPeS76ZpD3rBAeQW1h9c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DfFJTb2MjyLWtiPK7zTRtKLsbcec9JdUoHG8fssvfSEbZmJXK651jyHFUwT6PvcTH 7B0BYGTKAIC+IxfHSxE2bRmrhGgjxI5P7DKV9cuUaWv3lMSyfm00yqpzBY9EWxldLC fDW6h6IUy8dCb2Q+X5U96pMm6VGUdXeBDFhxRHTGPrzyYl4ijDoHKkYIRHmcg7Sz0L rGK348RJoQxwGZqLyVZcOCB0PYyHN3p1O8tGHCvG0E2Fdf4Mk2pL2Z9vS98nBFyy7Y PfOmkIIn4zSnRjKZHUIryr18QsBRNBI8G3A/VdI4Nv1yXDi+o36A+xG9zkszu+C9Zx USFEaMiEBXiXA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w4asU-00000004da4-0iGU; Mon, 23 Mar 2026 08:43:14 +0000 Date: Mon, 23 Mar 2026 08:43:13 +0000 Message-ID: <861phb542m.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Joey Gouly , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Will Deacon , Mostafa Saleh , Quentin Perret Subject: Re: [PATCH 4/5] KVM: arm64: pkvm: Use direct function pointers for cpu_{on,resume} In-Reply-To: References: <20260321212419.2803972-1-maz@kernel.org> <20260321212419.2803972-5-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: tabba@google.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, joey.gouly@arm.com, suzuki.poulose@arm.com, oupton@kernel.org, yuzenghui@huawei.com, will@kernel.org, smostafa@google.com, qperret@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Sun, 22 Mar 2026 15:49:50 +0000, Fuad Tabba wrote: > > Hi Marc, > > On Sat, 21 Mar 2026 at 21:24, Marc Zyngier 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 > > --- > > 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 Thanks again, M. -- Without deviation from the norm, progress is not possible.