Check KVM hypercall forward capability and enable it, and set global flag "sdei_enabled" to true if everything works well. Signed-off-by: Heyi Guo <guoheyi@xxxxxxxxxx> Cc: Peter Maydell <peter.maydell@xxxxxxxxxx> Cc: Dave Martin <Dave.Martin@xxxxxxx> Cc: Marc Zyngier <marc.zyngier@xxxxxxx> Cc: Mark Rutland <mark.rutland@xxxxxxx> Cc: James Morse <james.morse@xxxxxxx> --- target/arm/sdei.c | 17 +++++++++++++++++ target/arm/sdei.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/target/arm/sdei.c b/target/arm/sdei.c index efdb681..000545e 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -43,6 +43,7 @@ #define TYPE_QEMU_SDEI "qemu_sdei" #define QEMU_SDEI(obj) OBJECT_CHECK(QemuSDEState, (obj), TYPE_QEMU_SDEI) +bool sdei_enabled; static QemuSDEState *sde_state; typedef struct QemuSDEIBindNotifyEntry { @@ -1465,6 +1466,7 @@ static const VMStateDescription vmstate_sde_state = { static void sdei_initfn(Object *obj) { QemuSDEState *s = QEMU_SDEI(obj); + KVMState *kvm = KVM_STATE(current_machine->accelerator); if (sde_state) { error_report("Only one SDEI dispatcher is allowed!"); @@ -1474,6 +1476,21 @@ static void sdei_initfn(Object *obj) qemu_sde_init(s); qemu_register_reset(qemu_sde_reset, s); + + if (kvm_check_extension(kvm, KVM_CAP_FORWARD_HYPERCALL)) { + int ret; + ret = kvm_vm_enable_cap(kvm, KVM_CAP_FORWARD_HYPERCALL, 0, + KVM_CAP_FORWARD_HYPERCALL_EXCL_PSCI); + if (ret < 0) { + error_report("Enable hypercall forwarding failed: %s", + strerror(-ret)); + abort(); + } + sdei_enabled = true; + info_report("qemu sdei enabled"); + } else { + info_report("KVM does not support forwarding hypercall."); + } } static void qemu_sde_class_init(ObjectClass *klass, void *data) diff --git a/target/arm/sdei.h b/target/arm/sdei.h index feaaf1a..95e7d8d 100644 --- a/target/arm/sdei.h +++ b/target/arm/sdei.h @@ -29,6 +29,8 @@ #define SDEI_MAX_REQ SDEI_1_0_FN(0x12) +extern bool sdei_enabled; + void sdei_handle_request(CPUState *cs, struct kvm_run *run); /* -- 1.8.3.1 _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm