[PATCH v5 17/22] KVM: arm64: Support SDEI event notifier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The owner of the SDEI event may want to know if the injected event
has been delivered and handled. For example, Async PF cancels the
injected SDEI event at early stage of the work, driven by the
event has been completed asynchronously.

This supports SDEI event state updating by introducing notifier
mechanism. It's notable the notifier (handler) should be capable of
migration.

Signed-off-by: Gavin Shan <gshan@xxxxxxxxxx>
---
 arch/arm64/include/asm/kvm_sdei.h | 10 +++++++
 arch/arm64/kvm/sdei.c             | 45 +++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/arch/arm64/include/asm/kvm_sdei.h b/arch/arm64/include/asm/kvm_sdei.h
index 54c730acd298..2480ec0e9824 100644
--- a/arch/arm64/include/asm/kvm_sdei.h
+++ b/arch/arm64/include/asm/kvm_sdei.h
@@ -18,6 +18,14 @@
 
 struct kvm_vcpu;
 
+typedef void (*kvm_sdei_notifier)(struct kvm_vcpu *vcpu,
+				  unsigned long num,
+				  unsigned int state);
+enum {
+	KVM_SDEI_NOTIFY_DELIVERED,
+	KVM_SDEI_NOTIFY_COMPLETED,
+};
+
 struct kvm_sdei_exposed_event {
 	struct kvm_sdei_exposed_event_state	state;
 	struct kvm				*kvm;
@@ -165,6 +173,8 @@ KVM_SDEI_REGISTERED_EVENT_FUNC(unregister_pending)
 void kvm_sdei_init_vm(struct kvm *kvm);
 void kvm_sdei_create_vcpu(struct kvm_vcpu *vcpu);
 int kvm_sdei_hypercall(struct kvm_vcpu *vcpu);
+int kvm_sdei_register_event_notifier(struct kvm *kvm, unsigned long num,
+				     kvm_sdei_notifier notifier);
 int kvm_sdei_inject_event(struct kvm_vcpu *vcpu,
 			  unsigned long num, bool immediate);
 int kvm_sdei_cancel_event(struct kvm_vcpu *vcpu, unsigned long num);
diff --git a/arch/arm64/kvm/sdei.c b/arch/arm64/kvm/sdei.c
index 3019ac196e76..9f1959653318 100644
--- a/arch/arm64/kvm/sdei.c
+++ b/arch/arm64/kvm/sdei.c
@@ -353,6 +353,7 @@ static unsigned long hypercall_complete(struct kvm_vcpu *vcpu, bool resume)
 	struct kvm_sdei_registered_event *registered_event;
 	struct kvm_sdei_vcpu_event *vcpu_event;
 	struct kvm_sdei_vcpu_regs_state *regs;
+	kvm_sdei_notifier notifier = NULL;
 	unsigned long ret = SDEI_SUCCESS;
 	int index;
 
@@ -397,6 +398,7 @@ static unsigned long hypercall_complete(struct kvm_vcpu *vcpu, bool resume)
 	 */
 	registered_event = vcpu_event->registered_event;
 	exposed_event = registered_event->exposed_event;
+	notifier = (kvm_sdei_notifier)(exposed_event->state.notifier);
 	index = kvm_sdei_vcpu_index(vcpu, exposed_event);
 	if (kvm_sdei_is_unregister_pending(registered_event, index)) {
 		kvm_sdei_clear_enabled(registered_event, index);
@@ -413,6 +415,12 @@ static unsigned long hypercall_complete(struct kvm_vcpu *vcpu, bool resume)
 	spin_unlock(&vsdei->lock);
 	spin_unlock(&ksdei->lock);
 
+	/* Notifier */
+	if (notifier) {
+		notifier(vcpu, exposed_event->state.num,
+			 KVM_SDEI_NOTIFY_COMPLETED);
+	}
+
 	return ret;
 }
 
@@ -986,6 +994,35 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu)
 	return 1;
 }
 
+int kvm_sdei_register_event_notifier(struct kvm *kvm,
+				     unsigned long num,
+				     kvm_sdei_notifier notifier)
+{
+	struct kvm_sdei_kvm *ksdei = kvm->arch.sdei;
+	struct kvm_sdei_exposed_event *exposed_event = NULL;
+	int ret = 0;
+
+	if (!ksdei) {
+		ret = -EPERM;
+		goto out;
+	}
+
+	spin_lock(&ksdei->lock);
+
+	exposed_event = find_exposed_event(kvm, num);
+	if (!exposed_event) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+
+	exposed_event->state.notifier = (unsigned long)notifier;
+
+unlock:
+	spin_unlock(&ksdei->lock);
+out:
+	return ret;
+}
+
 int kvm_sdei_inject_event(struct kvm_vcpu *vcpu,
 			  unsigned long num,
 			  bool immediate)
@@ -1100,6 +1137,7 @@ void kvm_sdei_deliver_event(struct kvm_vcpu *vcpu)
 	struct kvm_sdei_registered_event *registered_event;
 	struct kvm_sdei_vcpu_event *vcpu_event;
 	struct kvm_sdei_vcpu_regs_state *regs;
+	kvm_sdei_notifier notifier = NULL;
 	unsigned long pstate;
 	int index;
 
@@ -1129,6 +1167,7 @@ void kvm_sdei_deliver_event(struct kvm_vcpu *vcpu)
 
 	registered_event = vcpu_event->registered_event;
 	exposed_event = registered_event->exposed_event;
+	notifier = (kvm_sdei_notifier)(exposed_event->state.notifier);
 	if (kvm_sdei_is_critical(exposed_event->state.priority)) {
 		vsdei->critical_event = vcpu_event;
 		vsdei->state.critical_num = vcpu_event->state.num;
@@ -1179,6 +1218,12 @@ void kvm_sdei_deliver_event(struct kvm_vcpu *vcpu)
 
 unlock:
 	spin_unlock(&vsdei->lock);
+
+	/* Notifier */
+	if (notifier) {
+		notifier(vcpu, exposed_event->state.num,
+			 KVM_SDEI_NOTIFY_DELIVERED);
+	}
 }
 
 void kvm_sdei_init_vm(struct kvm *kvm)
-- 
2.23.0

_______________________________________________
kvmarm mailing list
kvmarm@xxxxxxxxxxxxxxxxxxxxx
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm



[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux