From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2C91EC01A2 for ; Mon, 23 Mar 2026 08:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NnWZ2/AkloT/k59JvmaxqDj2TbAZJRlNZyGc0ojSFEI=; b=x7q8Xtdsxdul1euDRqfvQQot93 oxpIvp01in/bb8CHNLk5YRQON1QeQgPvsidwXhPHcqiDELUTpN9etsQJ6ShfCWi0PzkEtiivKakQ1 3dDDM+XMr+i34dXC1Adg0Vzxxa3nxP4KB/rPx5iLZeoEHPsUOYU6OcMVaNOZJ5NdpGRfStoaTjN1A fOoklzZWdjmX0npKBS44mTfDMz0f2jRxBAuzPZUdf3o8UBa+r1i2NZW+td+Uhyo8oU+qBsmhYWjGS he+4NKhR7Eba9ZxYFyOqmnakuAMtM7PavpeRMH35sLaOa8EAgFbECyjSGoTVMYFcIIK5KWE0Gx+/0 Ys7I/YTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w4asa-0000000GIQO-2jdO; Mon, 23 Mar 2026 08:43:20 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w4asX-0000000GIQ1-3zAz for linux-arm-kernel@lists.infradead.org; Mon, 23 Mar 2026 08:43:19 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id CA37D4357E; Mon, 23 Mar 2026 08:43:16 +0000 (UTC) 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) 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260323_014318_188368_D3F524E7 X-CRM114-Status: GOOD ( 28.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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.