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 7CC46C25B10 for ; Mon, 13 May 2024 14:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n63N0KvgyNv5+jbtxHP4iGz2v3t+2cL1OpGN3JDaOAM=; b=LEKmDa/niOE2m0 25h1Y6PcRYEuI/SIih6c17G3YhwcT18zoH3X3aBtIK/MKvZc0EynRVDd2b2I+2dHfsXHwSOh0H0uY YIRanNc0kLUxmXcWNnPoo+tPEC4SZcdEcDFTwhVVASBxv9eWv7ozhBUGvvdZSht70z0qmXJ7aXtSt 9W7NuLci3vB3QjxYxVDuaO+WGGijq/3crTRfQ7E0+zBjrnrjcRo4K7z5OOgT7Xti3j7R2+A4s1Bey Qod6LfCHEvGEUm8RC+e32Av+MRAxJMeQJuGGzirNwoxV2BmJ816PwIFyNu9UhgSzIfcXoTtcHtz5z W4wOpHBg/yaOyeGyEmRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6WUc-0000000D9nx-4C3t; Mon, 13 May 2024 14:17:31 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6WUZ-0000000D9mU-3cAl for linux-arm-kernel@lists.infradead.org; Mon, 13 May 2024 14:17:29 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 331E960E07; Mon, 13 May 2024 14:17:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CE98C4AF12; Mon, 13 May 2024 14:17:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715609847; bh=T5fem1/X0SKYUnwohi4fsRk8kuO5KdWTrb8pWSTa7IY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=q2zssrFCNxQaY4ajMUrIS+DzXEyx5EEIs7lefs4SgOR0d9v9xsDFa5SRNn5jmxKh1 3dn+4kp6gsUQHXxiG1nm/GGeNUWHGLrvs31YPCCyfxa5nmEiXHxFZ/P/Ch9D0PKNKT 096OiL1d0B0vpkFMXvRnsav019G9EUcJes13G5xsJr11HKHmxMYeDQ5V9aT6R9vJpk 1ZS2V0wGrsD/agW5VmLaa8Qwxakr5ZAQTdbmDtr3sAJOQHfI1Jx00V6zSpmgWC534z uz04u0OqGSnbHKt+6pDwlsXE7nsUQAeOBwAgrXidrbo33Cd9jPsP0/wIbRzQINhYSf SPSTOz+HAbOPA== Date: Mon, 13 May 2024 15:17:22 +0100 From: Will Deacon To: =?iso-8859-1?Q?Pierre-Cl=E9ment?= Tosi Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , Oliver Upton , Suzuki K Poulose , Vincent Donnefort Subject: Re: [PATCH v3 03/12] KVM: arm64: Pass pointer to __pkvm_init_switch_pgd Message-ID: <20240513141721.GC28749@willie-the-truck> References: <20240510112645.3625702-1-ptosi@google.com> <20240510112645.3625702-4-ptosi@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240510112645.3625702-4-ptosi@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240513_071728_007565_FD9F1CC8 X-CRM114-Status: GOOD ( 20.61 ) 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: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, May 10, 2024 at 12:26:32PM +0100, Pierre-Cl=E9ment Tosi wrote: > Make the function take a VA pointer, instead of a phys_addr_t, to fully > take advantage of the high-level C language and its type checker. > = > Perform all accesses to the kvm_nvhe_init_params before disabling the > MMU, removing the need to access it using physical addresses, which was > the reason for taking a phys_addr_t. > = > Signed-off-by: Pierre-Cl=E9ment Tosi > --- > arch/arm64/include/asm/kvm_hyp.h | 3 ++- > arch/arm64/kvm/hyp/nvhe/hyp-init.S | 12 +++++++++--- > arch/arm64/kvm/hyp/nvhe/setup.c | 4 +--- > 3 files changed, 12 insertions(+), 7 deletions(-) > = > diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kv= m_hyp.h > index 96daf7cf6802..c195e71d0746 100644 > --- a/arch/arm64/include/asm/kvm_hyp.h > +++ b/arch/arm64/include/asm/kvm_hyp.h > @@ -123,7 +123,8 @@ void __noreturn __hyp_do_panic(struct kvm_cpu_context= *host_ctxt, u64 spsr, > #endif > = > #ifdef __KVM_NVHE_HYPERVISOR__ > -void __pkvm_init_switch_pgd(phys_addr_t params, void (*finalize_fn)(void= )); > +void __pkvm_init_switch_pgd(struct kvm_nvhe_init_params *params, > + void (*finalize_fn)(void)); > int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_c= pus, > unsigned long *per_cpu_base, u32 hyp_va_bits); > void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt); > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe= /hyp-init.S > index 2994878d68ea..5a15737b4233 100644 > --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S > @@ -265,7 +265,15 @@ alternative_else_nop_endif > = > SYM_CODE_END(__kvm_handle_stub_hvc) > = > +/* > + * void __pkvm_init_switch_pgd(struct kvm_nvhe_init_params *params, > + * void (*finalize_fn)(void)); > + */ > SYM_FUNC_START(__pkvm_init_switch_pgd) > + /* Load the inputs from the VA pointer before turning the MMU off */ > + ldr x5, [x0, #NVHE_INIT_PGD_PA] > + ldr x0, [x0, #NVHE_INIT_STACK_HYP_VA] > + > /* Turn the MMU off */ > pre_disable_mmu_workaround > mrs x2, sctlr_el2 > @@ -276,15 +284,13 @@ SYM_FUNC_START(__pkvm_init_switch_pgd) > tlbi alle2 > = > /* Install the new pgtables */ > - ldr x3, [x0, #NVHE_INIT_PGD_PA] > - phys_to_ttbr x4, x3 > + phys_to_ttbr x4, x5 > alternative_if ARM64_HAS_CNP > orr x4, x4, #TTBR_CNP_BIT > alternative_else_nop_endif > msr ttbr0_el2, x4 > = > /* Set the new stack pointer */ > - ldr x0, [x0, #NVHE_INIT_STACK_HYP_VA] > mov sp, x0 > = > /* And turn the MMU back on! */ Hmm, if we can hoist the memory accesses all the way like this, then couldn't we just move them into the caller's C code? Maybe that's what we planned to do in the first place, which would explain why the prototype of __pkvm_init_switch_pgd() is out-of-sync. In other words, drop the previous patch and pass in the pgd and SP as arguments to the asm. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel