Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp597100pxy; Sat, 14 Aug 2021 17:17:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBqvgFERPYM9MO4gtOFqputqNwTHDmTjBIdRQ//mk/50wq26dFdSbT452xEW1/8l6nPXyp X-Received: by 2002:a17:906:f298:: with SMTP id gu24mr3049237ejb.334.1628986645322; Sat, 14 Aug 2021 17:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628986645; cv=none; d=google.com; s=arc-20160816; b=LTMl3THfvJsX4obItmYc9JYx3gXtD2QppzUCjne0uhoos5ek04qDYRws6YtawDoRl3 m+/sYsRuym8xzyr15D2llytOYEv1WujneMrTtRkNJO7lt4x88L5BpBiGtywgvfNjsvlD 6ROQOElzg8f20LLMVR1DZ9EBov5dTMzGAnY9/cg6cUeZegK+BgASdYgi2UFpPqK8KpK1 O6MzjTVImWZS7xdqJc6z4vXjUrPeIfHe3oXfGs7grAj9Evdx8cO8SFQCjeVyOOgvQTdP FEw9IPX3LIdneu2UeUuNmaqtfoX1GINSdLIhfMHxigKdyMTPj5rAhlCRT6HqTnrd/kSS ermQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iEhGG0hnD1JDiId4QQ1JcUjDqHGQb063cTr4+JPyYkw=; b=FZE+dD2jUxgytScqcZU09aL6OY3l+LGhg7pRLqhBu74sSeXV4O3XIMi6es4uSDq3ZI XU3Iw2sT7SP8M6NuIMHLfvja28elbKx4MbgWhl6g84Z/r+luvLMucOIdG4A58Sbc/wO0 2Md0m8Nn2B3lE+W9x28zmMV8zUT5Qjy7rcuarJ/qR0TQ4t7CeScWEX2pCyMwoYCDVXHs 0UV//bvspLkJoEVQ6LIsN37VZau44Rm+rDjJD3VZPm6EPCWNX6cOn6uDrSfZqPs0wk8q hYe1GgFq+XJ2Wq2aOyXsIcaOq6HxhNQoXgjdO+Buw+0NRdJcN9p+VeIyOjNZKhwaSZSV erjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V3rSIq7/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si5843572edt.123.2021.08.14.17.17.02; Sat, 14 Aug 2021 17:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V3rSIq7/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235664AbhHOAPj (ORCPT + 99 others); Sat, 14 Aug 2021 20:15:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27557 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235368AbhHOAPY (ORCPT ); Sat, 14 Aug 2021 20:15:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628986494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iEhGG0hnD1JDiId4QQ1JcUjDqHGQb063cTr4+JPyYkw=; b=V3rSIq7/T3BUYh3sO+oJYg+oORDvvxScsR915SwMYdxQmASxPMx41e2a4/PkThsX5ep9SE 5A0LgQBWz8EYKrEsUs8J8Y9A7TEN598EtqzSTmpD8O5WwuDue6uB8+3AuXeVwfksxd5cVS 11XJWbbkR+ajbmwkbri4NoVpVm64rSQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-Kn7aLsCnPGOB51pYeTnCAQ-1; Sat, 14 Aug 2021 20:14:51 -0400 X-MC-Unique: Kn7aLsCnPGOB51pYeTnCAQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9498B801AC0; Sun, 15 Aug 2021 00:14:49 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-103.bne.redhat.com [10.64.54.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1FD7210016FF; Sun, 15 Aug 2021 00:14:44 +0000 (UTC) From: Gavin Shan To: kvmarm@lists.cs.columbia.edu Cc: linux-kernel@vger.kernel.org, james.morse@arm.com, mark.rutland@arm.com, Jonathan.Cameron@huawei.com, will@kernel.org, maz@kernel.org, pbonzini@redhat.com Subject: [PATCH v4 07/21] KVM: arm64: Support SDEI_EVENT_UNREGISTER hypercall Date: Sun, 15 Aug 2021 08:13:38 +0800 Message-Id: <20210815001352.81927-8-gshan@redhat.com> In-Reply-To: <20210815001352.81927-1-gshan@redhat.com> References: <20210815001352.81927-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This supports SDEI_EVENT_UNREGISTER hypercall. It's used by the guest to unregister SDEI event. The SDEI event won't be raised to the guest or specific vCPU after it's unregistered successfully. It's notable the SDEI event is disabled automatically on the guest or specific vCPU once it's unregistered successfully. Signed-off-by: Gavin Shan --- arch/arm64/kvm/sdei.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/arch/arm64/kvm/sdei.c b/arch/arm64/kvm/sdei.c index b4162efda470..a3ba69dc91cb 100644 --- a/arch/arm64/kvm/sdei.c +++ b/arch/arm64/kvm/sdei.c @@ -308,6 +308,65 @@ static unsigned long kvm_sdei_hypercall_context(struct kvm_vcpu *vcpu) return ret; } +static unsigned long kvm_sdei_hypercall_unregister(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_vcpu *vsdei = vcpu->arch.sdei; + struct kvm_sdei_event *kse = NULL; + struct kvm_sdei_kvm_event *kske = NULL; + unsigned long event_num = smccc_get_arg1(vcpu); + int index = 0; + unsigned long ret = SDEI_SUCCESS; + + /* Sanity check */ + if (!(ksdei && vsdei)) { + ret = SDEI_NOT_SUPPORTED; + goto out; + } + + if (!kvm_sdei_is_valid_event_num(event_num)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + } + + /* Check if the KVM event exists */ + spin_lock(&ksdei->lock); + kske = kvm_sdei_find_kvm_event(kvm, event_num); + if (!kske) { + ret = SDEI_INVALID_PARAMETERS; + goto unlock; + } + + /* Check if there is pending events */ + if (kske->state.refcount) { + ret = SDEI_PENDING; + goto unlock; + } + + /* Check if it has been registered */ + kse = kske->kse; + index = (kse->state.type == SDEI_EVENT_TYPE_PRIVATE) ? + vcpu->vcpu_idx : 0; + if (!kvm_sdei_is_registered(kske, index)) { + ret = SDEI_DENIED; + goto unlock; + } + + /* The event is disabled when it's unregistered */ + kvm_sdei_clear_enabled(kske, index); + kvm_sdei_clear_registered(kske, index); + if (kvm_sdei_empty_registered(kske)) { + list_del(&kske->link); + kfree(kske); + } + +unlock: + spin_unlock(&ksdei->lock); +out: + return ret; +} + int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) { u32 func = smccc_get_function(vcpu); @@ -333,6 +392,8 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) case SDEI_1_0_FN_SDEI_EVENT_COMPLETE: case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME: case SDEI_1_0_FN_SDEI_EVENT_UNREGISTER: + ret = kvm_sdei_hypercall_unregister(vcpu); + break; case SDEI_1_0_FN_SDEI_EVENT_STATUS: case SDEI_1_0_FN_SDEI_EVENT_GET_INFO: case SDEI_1_0_FN_SDEI_EVENT_ROUTING_SET: -- 2.23.0