From: "Pierre-Clément Tosi" <ptosi@google.com>
To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org
Cc: "Pierre-Clément Tosi" <ptosi@google.com>,
"Marc Zyngier" <maz@kernel.org>,
"Oliver Upton" <oliver.upton@linux.dev>,
"Suzuki K Poulose" <suzuki.poulose@arm.com>,
"Vincent Donnefort" <vdonnefort@google.com>
Subject: [PATCH v3 03/12] KVM: arm64: Pass pointer to __pkvm_init_switch_pgd
Date: Fri, 10 May 2024 12:26:32 +0100 [thread overview]
Message-ID: <20240510112645.3625702-4-ptosi@google.com> (raw)
In-Reply-To: <20240510112645.3625702-1-ptosi@google.com>
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ément Tosi <ptosi@google.com>
---
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/kvm_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_cpus,
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! */
diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c
index bcaeb0fafd2d..45b83f3ed012 100644
--- a/arch/arm64/kvm/hyp/nvhe/setup.c
+++ b/arch/arm64/kvm/hyp/nvhe/setup.c
@@ -314,7 +314,6 @@ void __noreturn __pkvm_init_finalise(void)
int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus,
unsigned long *per_cpu_base, u32 hyp_va_bits)
{
- struct kvm_nvhe_init_params *params;
void *virt = hyp_phys_to_virt(phys);
typeof(__pkvm_init_switch_pgd) *fn;
int ret;
@@ -338,9 +337,8 @@ int __pkvm_init(phys_addr_t phys, unsigned long size, unsigned long nr_cpus,
update_nvhe_init_params();
/* Jump in the idmap page to switch to the new page-tables */
- params = this_cpu_ptr(&kvm_init_params);
fn = (typeof(fn))__hyp_pa(__pkvm_init_switch_pgd);
- fn(__hyp_pa(params), __pkvm_init_finalise);
+ fn(this_cpu_ptr(&kvm_init_params), __pkvm_init_finalise);
unreachable();
}
--
2.45.0.118.g7fe29c98d7-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-05-10 11:27 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-10 11:26 [PATCH v3 00/12] KVM: arm64: Add support for hypervisor kCFI Pierre-Clément Tosi
2024-05-10 11:26 ` [PATCH v3 01/12] KVM: arm64: Fix clobbered ELR in sync abort/SError Pierre-Clément Tosi
2024-05-13 13:55 ` Will Deacon
2024-05-10 11:26 ` [PATCH v3 02/12] KVM: arm64: Fix __pkvm_init_switch_pgd C signature Pierre-Clément Tosi
2024-05-13 14:03 ` Will Deacon
2024-05-10 11:26 ` Pierre-Clément Tosi [this message]
2024-05-13 14:17 ` [PATCH v3 03/12] KVM: arm64: Pass pointer to __pkvm_init_switch_pgd Will Deacon
2024-05-10 11:26 ` [PATCH v3 04/12] KVM: arm64: nVHE: Remove __guest_exit_panic path Pierre-Clément Tosi
2024-05-13 14:27 ` Will Deacon
2024-05-10 11:26 ` [PATCH v3 05/12] KVM: arm64: nVHE: Add EL2h sync exception handler Pierre-Clément Tosi
2024-05-10 11:26 ` [PATCH v3 06/12] KVM: arm64: nVHE: gen-hyprel: Skip R_AARCH64_ABS32 Pierre-Clément Tosi
2024-05-13 14:33 ` Will Deacon
2024-05-10 11:26 ` [PATCH v3 07/12] KVM: arm64: VHE: Mark __hyp_call_panic __noreturn Pierre-Clément Tosi
2024-05-13 14:52 ` Will Deacon
2024-05-10 11:26 ` [PATCH v3 08/12] arm64: Move esr_comment() to <asm/esr.h> Pierre-Clément Tosi
2024-05-13 14:57 ` Will Deacon
2024-05-10 11:26 ` [PATCH v3 09/12] KVM: arm64: VHE: Add test module for hyp kCFI Pierre-Clément Tosi
2024-05-13 17:21 ` Will Deacon
2024-05-29 12:26 ` Pierre-Clément Tosi
2024-06-03 13:10 ` Will Deacon
2024-05-10 11:26 ` [PATCH v3 10/12] KVM: arm64: nVHE: Support CONFIG_CFI_CLANG at EL2 Pierre-Clément Tosi
2024-05-13 17:30 ` Will Deacon
2024-05-29 12:30 ` Pierre-Clément Tosi
2024-06-03 13:09 ` Will Deacon
2024-05-10 11:26 ` [PATCH v3 11/12] KVM: arm64: nVHE: Support test module for hyp kCFI Pierre-Clément Tosi
2024-05-10 11:26 ` [PATCH v3 12/12] KVM: arm64: Improve CONFIG_CFI_CLANG error message Pierre-Clément Tosi
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=20240510112645.3625702-4-ptosi@google.com \
--to=ptosi@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=vdonnefort@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox