lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220403153911.12332-5-gshan@redhat.com>
Date:   Sun,  3 Apr 2022 23:38:57 +0800
From:   Gavin Shan <gshan@...hat.com>
To:     kvmarm@...ts.cs.columbia.edu
Cc:     linux-kernel@...r.kernel.org, eauger@...hat.com, oupton@...gle.com,
        Jonathan.Cameron@...wei.com, vkuznets@...hat.com, will@...nel.org,
        shannon.zhaosl@...il.com, james.morse@....com,
        mark.rutland@....com, maz@...nel.org, pbonzini@...hat.com,
        shan.gavin@...il.com
Subject: [PATCH v6 04/18] KVM: arm64: Support SDEI_EVENT_REGISTER hypercall

This supports SDEI_EVENT_REGISTER hypercall, which is used by guest
to register event. The event won't be raised until it's registered
and enabled. For those KVM owned events, they can't be registered
if they aren't exposed.

Signed-off-by: Gavin Shan <gshan@...hat.com>
---
 arch/arm64/kvm/sdei.c | 78 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/arch/arm64/kvm/sdei.c b/arch/arm64/kvm/sdei.c
index 3507e33ec00e..89c1b231cb60 100644
--- a/arch/arm64/kvm/sdei.c
+++ b/arch/arm64/kvm/sdei.c
@@ -25,6 +25,81 @@ static struct kvm_sdei_exposed_event exposed_events[] = {
 	for (idx = 0, event = &exposed_events[0];	\
 	     idx < ARRAY_SIZE(exposed_events);		\
 	     idx++, event++)
+#define kvm_sdei_for_each_event(vsdei, event, idx)	\
+	for (idx = 0, event = &vsdei->events[0];	\
+	     idx < ARRAY_SIZE(exposed_events);		\
+	     idx++, event++)
+
+static struct kvm_sdei_event *find_event(struct kvm_vcpu *vcpu,
+					 unsigned int num)
+{
+	struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei;
+	struct kvm_sdei_event *event;
+	int i;
+
+	kvm_sdei_for_each_event(vsdei, event, i) {
+		if (event->exposed_event->num == num)
+			return event;
+	}
+
+	return NULL;
+}
+
+static unsigned long hypercall_register(struct kvm_vcpu *vcpu)
+{
+	struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei;
+	struct kvm_sdei_event *event;
+	unsigned int num = smccc_get_arg(vcpu, 1);
+	unsigned long ep_address = smccc_get_arg(vcpu, 2);
+	unsigned long ep_arg = smccc_get_arg(vcpu, 3);
+	unsigned long route_mode = smccc_get_arg(vcpu, 4);
+	unsigned long route_affinity = smccc_get_arg(vcpu, 5);
+	unsigned long ret = SDEI_SUCCESS;
+
+	if (!kvm_sdei_is_supported(num)) {
+		ret = SDEI_INVALID_PARAMETERS;
+		goto out;
+	}
+
+	if (route_mode != SDEI_EVENT_REGISTER_RM_ANY &&
+	    route_mode != SDEI_EVENT_REGISTER_RM_PE) {
+		ret = SDEI_INVALID_PARAMETERS;
+		goto out;
+	}
+
+	spin_lock(&vsdei->lock);
+
+	/*
+	 * The event should have been existing. Otherwise, the event
+	 * isn't exposed yet.
+	 */
+	event = find_event(vcpu, num);
+	if (!event) {
+		ret = SDEI_INVALID_PARAMETERS;
+		goto unlock;
+	}
+
+	/*
+	 * Check if the event has been registered or pending for
+	 * unregistration.
+	 */
+	if (kvm_sdei_is_registered(event) ||
+	    kvm_sdei_is_unregister_pending(event)) {
+		ret = SDEI_DENIED;
+		goto unlock;
+	}
+
+	event->route_mode     = route_mode;
+	event->route_affinity = route_affinity;
+	event->ep_address     = ep_address;
+	event->ep_arg         = ep_arg;
+	kvm_sdei_set_registered(event);
+
+unlock:
+	spin_unlock(&vsdei->lock);
+out:
+	return ret;
+}
 
 int kvm_sdei_call(struct kvm_vcpu *vcpu)
 {
@@ -47,6 +122,9 @@ int kvm_sdei_call(struct kvm_vcpu *vcpu)
 	}
 
 	switch (func) {
+	case SDEI_1_0_FN_SDEI_EVENT_REGISTER:
+		ret = hypercall_register(vcpu);
+		break;
 	default:
 		ret = SDEI_NOT_SUPPORTED;
 	}
-- 
2.23.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ