[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250424141341.841734-20-karim.manaouil@linaro.org>
Date: Thu, 24 Apr 2025 15:13:26 +0100
From: Karim Manaouil <karim.manaouil@...aro.org>
To: linux-kernel@...r.kernel.org,
kvm@...r.kernel.org,
linux-arm-msm@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
kvmarm@...ts.linux.dev
Cc: Karim Manaouil <karim.manaouil@...aro.org>,
Alexander Graf <graf@...zon.com>,
Alex Elder <elder@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
Fuad Tabba <tabba@...gle.com>,
Joey Gouly <joey.gouly@....com>,
Jonathan Corbet <corbet@....net>,
Marc Zyngier <maz@...nel.org>,
Mark Brown <broonie@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Oliver Upton <oliver.upton@...ux.dev>,
Paolo Bonzini <pbonzini@...hat.com>,
Prakruthi Deepak Heragu <quic_pheragu@...cinc.com>,
Quentin Perret <qperret@...gle.com>,
Rob Herring <robh@...nel.org>,
Srinivas Kandagatla <srini@...nel.org>,
Srivatsa Vaddagiri <quic_svaddagi@...cinc.com>,
Will Deacon <will@...nel.org>,
Haripranesh S <haripran@....qualcomm.com>,
Carl van Schaik <cvanscha@....qualcomm.com>,
Murali Nalajala <mnalajal@...cinc.com>,
Sreenivasulu Chalamcharla <sreeniva@....qualcomm.com>,
Trilok Soni <tsoni@...cinc.com>,
Stefan Schmidt <stefan.schmidt@...aro.org>,
Elliot Berman <quic_eberman@...cinc.com>
Subject: [RFC PATCH 19/34] gunyah: Add hypercalls for running a vCPU
From: Elliot Berman <quic_eberman@...cinc.com>
Add hypercall to donate CPU time to a vCPU.
Signed-off-by: Elliot Berman <quic_eberman@...cinc.com>
Reviewed-by: Srivatsa Vaddagiri <quic_svaddagi@...cinc.com>
Signed-off-by: Karim Manaouil <karim.manaouil@...aro.org>
---
arch/arm64/gunyah/gunyah_hypercall.c | 37 ++++++++++++++++++++++++++++
include/linux/gunyah.h | 35 ++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c
index 1302e128be6e..fee21df42c17 100644
--- a/arch/arm64/gunyah/gunyah_hypercall.c
+++ b/arch/arm64/gunyah/gunyah_hypercall.c
@@ -39,6 +39,7 @@ EXPORT_SYMBOL_GPL(arch_is_gunyah_guest);
#define GUNYAH_HYPERCALL_HYP_IDENTIFY GUNYAH_HYPERCALL(0x8000)
#define GUNYAH_HYPERCALL_MSGQ_SEND GUNYAH_HYPERCALL(0x801B)
#define GUNYAH_HYPERCALL_MSGQ_RECV GUNYAH_HYPERCALL(0x801C)
+#define GUNYAH_HYPERCALL_VCPU_RUN GUNYAH_HYPERCALL(0x8065)
/* clang-format on */
/**
@@ -113,5 +114,41 @@ enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size,
}
EXPORT_SYMBOL_GPL(gunyah_hypercall_msgq_recv);
+/**
+ * gunyah_hypercall_vcpu_run() - Donate CPU time to a vcpu
+ * @capid: capability ID of the vCPU to run
+ * @resume_data: Array of 3 state-specific resume data
+ * @resp: Filled reason why vCPU exited when return value is GUNYAH_ERROR_OK
+ *
+ * See also:
+ * https://github.com/quic/gunyah-hypervisor/blob/develop/docs/api/gunyah_api.md#run-a-proxy-scheduled-vcpu-thread
+ */
+enum gunyah_error
+gunyah_hypercall_vcpu_run(u64 capid, unsigned long *resume_data,
+ struct gunyah_hypercall_vcpu_run_resp *resp)
+{
+ struct arm_smccc_1_2_regs args = {
+ .a0 = GUNYAH_HYPERCALL_VCPU_RUN,
+ .a1 = capid,
+ .a2 = resume_data[0],
+ .a3 = resume_data[1],
+ .a4 = resume_data[2],
+ /* C language says this will be implictly zero. Gunyah requires 0, so be explicit */
+ .a5 = 0,
+ };
+ struct arm_smccc_1_2_regs res;
+
+ arm_smccc_1_2_hvc(&args, &res);
+ if (res.a0 == GUNYAH_ERROR_OK) {
+ resp->sized_state = res.a1;
+ resp->state_data[0] = res.a2;
+ resp->state_data[1] = res.a3;
+ resp->state_data[2] = res.a4;
+ }
+
+ return res.a0;
+}
+EXPORT_SYMBOL_GPL(gunyah_hypercall_vcpu_run);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls");
diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h
index 573e3bbd4cb6..f86f14018734 100644
--- a/include/linux/gunyah.h
+++ b/include/linux/gunyah.h
@@ -219,4 +219,39 @@ enum gunyah_error gunyah_hypercall_msgq_send(u64 capid, size_t size, void *buff,
enum gunyah_error gunyah_hypercall_msgq_recv(u64 capid, void *buff, size_t size,
size_t *recv_size, bool *ready);
+struct gunyah_hypercall_vcpu_run_resp {
+ union {
+ enum {
+ /* clang-format off */
+ /* VCPU is ready to run */
+ GUNYAH_VCPU_STATE_READY = 0,
+ /* VCPU is sleeping until an interrupt arrives */
+ GUNYAH_VCPU_STATE_EXPECTS_WAKEUP = 1,
+ /* VCPU is powered off */
+ GUNYAH_VCPU_STATE_POWERED_OFF = 2,
+ /* VCPU is blocked in EL2 for unspecified reason */
+ GUNYAH_VCPU_STATE_BLOCKED = 3,
+ /* VCPU has returned for MMIO READ */
+ GUNYAH_VCPU_ADDRSPACE_VMMIO_READ = 4,
+ /* VCPU has returned for MMIO WRITE */
+ GUNYAH_VCPU_ADDRSPACE_VMMIO_WRITE = 5,
+ /* VCPU blocked on fault where we can demand page */
+ GUNYAH_VCPU_ADDRSPACE_PAGE_FAULT = 7,
+ /* clang-format on */
+ } state;
+ u64 sized_state;
+ };
+ u64 state_data[3];
+};
+
+enum {
+ GUNYAH_ADDRSPACE_VMMIO_ACTION_EMULATE = 0,
+ GUNYAH_ADDRSPACE_VMMIO_ACTION_RETRY = 1,
+ GUNYAH_ADDRSPACE_VMMIO_ACTION_FAULT = 2,
+};
+
+enum gunyah_error
+gunyah_hypercall_vcpu_run(u64 capid, unsigned long *resume_data,
+ struct gunyah_hypercall_vcpu_run_resp *resp);
+
#endif
--
2.39.5
Powered by blists - more mailing lists