From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8A4CC433F5 for ; Tue, 22 Mar 2022 08:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbiCVIKK (ORCPT ); Tue, 22 Mar 2022 04:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbiCVIKH (ORCPT ); Tue, 22 Mar 2022 04:10:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D9958B02 for ; Tue, 22 Mar 2022 01:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647936516; 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=RDKgDYiBOvXHcRQ85sq8ZIkE8hhZPdi12RYn7yZMjUw=; b=eZmq4a0ftCgQxpHplP4/5yNsk6yg5aVrs+kE/A1ASV/uPjto2OqrjCJscITbr3wL6NNRPj zuAUqxWCf5j7uPnb4DsNODMqqjTx7tUDZekVqOG8PbduZoktO4QKNvASp+AAIrZdRbnueY VGqSRCxg/8AogUh7bH67KJG6xbo0Qn4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-625-ZDCvtjobO4Cgi80HYpcbYQ-1; Tue, 22 Mar 2022 04:08:32 -0400 X-MC-Unique: ZDCvtjobO4Cgi80HYpcbYQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B8B4811E75; Tue, 22 Mar 2022 08:08:32 +0000 (UTC) Received: from gshan.redhat.com (ovpn-12-33.pek2.redhat.com [10.72.12.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 779721121324; Tue, 22 Mar 2022 08:08:26 +0000 (UTC) From: Gavin Shan To: kvmarm@lists.cs.columbia.edu Cc: linux-kernel@vger.kernel.org, eauger@redhat.com, shannon.zhaosl@gmail.com, maz@kernel.org, Jonathan.Cameron@huawei.com, will@kernel.org, pbonzini@redhat.com, james.morse@arm.com, mark.rutland@arm.com, drjones@redhat.com, vkuznets@redhat.com, shan.gavin@gmail.com Subject: [PATCH v5 05/22] KVM: arm64: Support SDEI_EVENT_{ENABLE, DISABLE} hypercall Date: Tue, 22 Mar 2022 16:06:53 +0800 Message-Id: <20220322080710.51727-6-gshan@redhat.com> In-Reply-To: <20220322080710.51727-1-gshan@redhat.com> References: <20220322080710.51727-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This supports SDEI_EVENT_{ENABLE, DISABLE} hypercall. After SDEI event is registered by guest, it won't be delivered to the guest until it's enabled. For unregistration pending event, we can't enable or disable it as the registered event is going to be destroyed after current event is handled. Signed-off-by: Gavin Shan --- arch/arm64/kvm/sdei.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/arch/arm64/kvm/sdei.c b/arch/arm64/kvm/sdei.c index 2458dc666445..4ab58f264992 100644 --- a/arch/arm64/kvm/sdei.c +++ b/arch/arm64/kvm/sdei.c @@ -252,6 +252,51 @@ static unsigned long hypercall_register(struct kvm_vcpu *vcpu) return ret; } +static unsigned long hypercall_enable(struct kvm_vcpu *vcpu, bool enable) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_sdei_kvm *ksdei = kvm->arch.sdei; + struct kvm_sdei_exposed_event *exposed_event; + struct kvm_sdei_registered_event *registered_event; + unsigned long event_num = smccc_get_arg1(vcpu); + int index; + unsigned long ret = SDEI_SUCCESS; + + if (!kvm_sdei_is_supported(event_num)) { + ret = SDEI_INVALID_PARAMETERS; + goto out; + } + + spin_lock(&ksdei->lock); + + /* Check if the registered event exists */ + registered_event = find_registered_event(kvm, event_num); + if (!registered_event) { + ret = SDEI_DENIED; + goto unlock; + } + + /* Check if the event is registered and pending for unregistration */ + exposed_event = registered_event->exposed_event; + index = kvm_sdei_vcpu_index(vcpu, exposed_event); + if (!kvm_sdei_is_registered(registered_event, index) || + kvm_sdei_is_unregister_pending(registered_event, index)) { + ret = SDEI_DENIED; + goto unlock; + } + + /* Update the enablement state */ + if (enable) + kvm_sdei_set_enabled(registered_event, index); + else + kvm_sdei_clear_enabled(registered_event, index); + +unlock: + spin_unlock(&ksdei->lock); +out: + return ret; +} + int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; @@ -282,7 +327,11 @@ int kvm_sdei_hypercall(struct kvm_vcpu *vcpu) ret = hypercall_register(vcpu); break; case SDEI_1_0_FN_SDEI_EVENT_ENABLE: + ret = hypercall_enable(vcpu, true); + break; case SDEI_1_0_FN_SDEI_EVENT_DISABLE: + ret = hypercall_enable(vcpu, false); + break; case SDEI_1_0_FN_SDEI_EVENT_CONTEXT: case SDEI_1_0_FN_SDEI_EVENT_COMPLETE: case SDEI_1_0_FN_SDEI_EVENT_COMPLETE_AND_RESUME: -- 2.23.0