Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E562C433E1 for ; Mon, 17 Aug 2020 10:06:19 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 456A42067C for ; Mon, 17 Aug 2020 10:06:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fNtFYzWF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 456A42067C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id F19B04C01E; Mon, 17 Aug 2020 06:06:18 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gKwgawZwvf1B; Mon, 17 Aug 2020 06:06:18 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 0A7A64C012; Mon, 17 Aug 2020 06:06:18 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7BB284BF95 for ; Mon, 17 Aug 2020 06:06:16 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iEkBGmhNJOrm for ; Mon, 17 Aug 2020 06:06:15 -0400 (EDT) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 8E95A4BFFA for ; Mon, 17 Aug 2020 06:06:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597658775; 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=8OElRZjP6JXO/OB6PEEqAJaD4uENzrShziqFCI70qwc=; b=fNtFYzWFcjxko4e7gSi4qqXx7dq3zMd0IxYQ9IwAxf22KTD0leZP1nXwbpiUilJodELmwt XGwfiRLX+IuU8YdypiRNGMmhu7Ir9KbaXPDnscAJxI/ru9T5RBt6IVVzNKkpMT/Uhq+kUi WaJ/0o5tjjgcLGJmQTSgPGYZE4KwXKY= 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-362-0PDzaDEtPnOsNfi7f5u3AA-1; Mon, 17 Aug 2020 06:06:13 -0400 X-MC-Unique: 0PDzaDEtPnOsNfi7f5u3AA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6D5B3FE9; Mon, 17 Aug 2020 10:06:12 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-130.bne.redhat.com [10.64.54.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1ACE78414; Mon, 17 Aug 2020 10:06:09 +0000 (UTC) From: Gavin Shan To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 08/18] arm64/kvm: Support SDEI_1_0_FN_SDEI_EVENT_UNREGISTER hypercall Date: Mon, 17 Aug 2020 20:05:21 +1000 Message-Id: <20200817100531.83045-9-gshan@redhat.com> In-Reply-To: <20200817100531.83045-1-gshan@redhat.com> References: <20200817100531.83045-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=gshan@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Cc: maz@kernel.org, shan.gavin@gmail.com, pbonzini@redhat.com X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu This supports SDEI_1_0_FN_SDEI_EVENT_UNREGISTER hypercall by adding function kvm_sdei_hypercall_unregister(). For event owned by KVM itself, the register status is updated accordingly and the event is released if the event isn't needed. For passthrou event, the event is also unregistered from the underly firmware in that case. Signed-off-by: Gavin Shan --- arch/arm64/kvm/sdei.c | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/arch/arm64/kvm/sdei.c b/arch/arm64/kvm/sdei.c index 320b79528211..63d621dc9711 100644 --- a/arch/arm64/kvm/sdei.c +++ b/arch/arm64/kvm/sdei.c @@ -343,6 +343,77 @@ static unsigned long kvm_sdei_hypercall_enable(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_event *event = NULL; + struct kvm_sdei_kvm_event *kevent = NULL; + unsigned long event_num = smccc_get_arg1(vcpu); + unsigned long event_type; + int index = 0; + unsigned long ret = SDEI_SUCCESS; + + /* Validate event number */ + if (!kvm_sdei_num_is_valid(event_num)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + } + + if (!(kvm_sdei_data && kvm_sdei_data->supported) && + kvm_sdei_num_is_virt(event_num)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + } + + /* Find the event */ + spin_lock(&kvm_sdei_lock); + event = kvm_sdei_find_event(kvm, event_num, &kevent, NULL, NULL); + if (!kevent) { + ret = SDEI_INVALID_PARAMETERS; + goto unlock; + } + + /* Sanity check */ + spin_lock(&event->lock); + if (kevent->users) { + ret = SDEI_PENDING; + goto unlock_event; + } + + event_type = event->priv ? event->priv->type : event->event->type; + index = (event_type == SDEI_EVENT_TYPE_PRIVATE) ? vcpu->vcpu_idx : 0; + if (!test_bit(index, kevent->registered)) { + ret = SDEI_DENIED; + goto unlock_event; + } + + /* Update status and destroy it if needed */ + clear_bit(index, kevent->registered); + clear_bit(index, kevent->enabled); + if (!bitmap_empty(kevent->registered, KVM_MAX_VCPUS)) + goto unlock_event; + + rb_erase(&kevent->node, &event->root); + kfree(kevent); + event->count--; + if (event->count) + goto unlock_event; + + spin_unlock(&event->lock); + list_del(&event->link); + if (event->event) + kvm_sdei_unregister_event(event->event); + kfree(event); + goto unlock; + +unlock_event: + spin_unlock(&event->lock); +unlock: + spin_unlock(&kvm_sdei_lock); +out: + return ret; +} + static unsigned long kvm_sdei_reset(struct kvm *kvm, unsigned int types) { struct kvm_sdei_event *e, *event = NULL; @@ -429,6 +500,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 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm