[RFC PATCH 31/34] gunyah: allow userspace to set boot cpu context
Karim Manaouil
karim.manaouil at linaro.org
Thu Apr 24 07:13:38 PDT 2025
Allow userspace hypervisor (e.g. Qemu) to set the context of the boot
cpu. At the moment, only the program counter (PC) is needed.
Signed-off-by: Karim Manaouil <karim.manaouil at linaro.org>
---
arch/arm64/kvm/gunyah.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/arm64/kvm/gunyah.c b/arch/arm64/kvm/gunyah.c
index e8037d636e8f..df922be2429e 100644
--- a/arch/arm64/kvm/gunyah.c
+++ b/arch/arm64/kvm/gunyah.c
@@ -1703,6 +1703,24 @@ static int gunyah_vm_rm_notification(struct notifier_block *nb,
}
}
+/*
+ * We only need to set PC to start of kernel
+ */
+static int gunyah_vm_set_boot_ctx(struct gunyah_vm *ghvm)
+{
+ struct kvm_vcpu *vcpu = kvm_get_vcpu(&ghvm->kvm, 0);
+ u64 core_reg = KVM_REG_ARM64 | KVM_REG_SIZE_U64 | KVM_REG_ARM_CORE;
+ struct kvm_one_reg reg;
+ u64 *regaddr;
+
+ reg.id = core_reg | KVM_REG_ARM_CORE_REG(regs.pc);
+ regaddr = core_reg_addr(vcpu, ®);
+
+ /* We only need to set PC atm. regset is 1 */
+ return gunyah_rm_vm_set_boot_context(
+ ghvm->rm, ghvm->vmid, 1, 0, *regaddr);
+}
+
static void gunyah_vm_stop(struct gunyah_vm *ghvm)
{
int ret;
@@ -1790,6 +1808,12 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm)
}
ghvm->vm_status = GUNYAH_RM_VM_STATUS_READY;
+ ret = gunyah_vm_set_boot_ctx(ghvm);
+ if (ret) {
+ pr_warn("Failed to setup boot context: %d\n", ret);
+ goto err;
+ }
+
ret = gunyah_rm_get_hyp_resources(ghvm->rm, ghvm->vmid, &resources);
if (ret) {
pr_warn("Failed to get hyp resources for VM: %d\n", ret);
--
2.39.5
More information about the linux-arm-kernel
mailing list