Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp611113pxh; Tue, 9 Nov 2021 16:09:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJxweGAOgJW+zs+ee4RFf6TzWE8XfxNAVZLSUzgao3YqXC4n1xmSL8xMcMM7ErwER74OFMTx X-Received: by 2002:a5d:9ecc:: with SMTP id a12mr3406372ioe.102.1636502974796; Tue, 09 Nov 2021 16:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636502974; cv=none; d=google.com; s=arc-20160816; b=xItASL22cw1czgwoQFIzEEn7wjh5+h+HbwzxEkvkIotaFdBEpk5xXz1+dC/zVw5rZX 74EhZX0OL1Bw8wPoFTtsVvxbaT5jvMH4edf1oRCMoGdefOSHKEEuA/T+EIoeW6gGRi49 RHs8l+L9XOFU3Nc5w7vXfAOAd4engSWvaBWoOC4M1F6JuBYNmazIpbHL+olwWZrOiNTh pGv7fNTNsh8zga7HyDJMaTlyb6Ge70g8BMKs4eJV5HoBchXf5qA0zohEdb+/GZOeqQSO CfjQWaEl50VikI0m/ERWxbxZS587ybKSzv57qQnGptt1N9GqRplVx9kacPh+elZDQby4 x4IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=C+tFRg598ce+Pkksxlpyq2K1tm7az89DtXstWpm6hqc=; b=YMpmUtJhZKptpKPMfiY7F8nuKs0BFh+OndDwlOg+aIwC7YpvNDoxg78bNpscamAs9N B90TGwZhFszreg++XQhpX0vEh7cEgihMUeufHuFJ2ffjkOHHiiS9k+BS+mqELcFuXXm+ JHXlGQIDLWYBS0G5Gwp7BGnmE0D65RFGKO6ZIeGPCBwhRDpt26OZDQaRdDhzZPcBPoiC 8SWRvjASu9Ov6yrzIT003+B64EKzmFP6eiijHTLzx3RjFCHrpp7cGu7M2N/UlLy01NKt pJdG8dEp7NSJ3aWl0ElRqwuwWxZCPBrEBt2tJa3Bfz14ThuB0anBKzyPGcSDeg9oFQAP 4hCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IVok75bK; 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 h22si30208853jal.48.2021.11.09.16.09.22; Tue, 09 Nov 2021 16:09:34 -0800 (PST) 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=IVok75bK; 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 S240711AbhKIRHx (ORCPT + 97 others); Tue, 9 Nov 2021 12:07:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53777 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231883AbhKIRHw (ORCPT ); Tue, 9 Nov 2021 12:07:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636477506; 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=C+tFRg598ce+Pkksxlpyq2K1tm7az89DtXstWpm6hqc=; b=IVok75bKRuqJ1xnsFrmUsT7EMxVT6RsSKDEQ8SfRsUqCBge7tUSxCuxhUe3rFHximH5Qol hZvXJxqo9D0+RHwLMRf1K3WxLCSQsbmKxANTBTqslVu/Vq5BgvJWQIH0AXJXE1uHg4PO5E rnebcXTYycmGQj1Bi92Xb5p5fY8yygE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-yYhtFs_OP_mwdUqO9QiHMw-1; Tue, 09 Nov 2021 12:05:05 -0500 X-MC-Unique: yYhtFs_OP_mwdUqO9QiHMw-1 Received: by mail-wm1-f70.google.com with SMTP id m18-20020a05600c3b1200b0033283ea5facso629242wms.1 for ; Tue, 09 Nov 2021 09:05:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=C+tFRg598ce+Pkksxlpyq2K1tm7az89DtXstWpm6hqc=; b=ZR909O6yiD+MB3Lb9nZJlKLXT3K24FvEsSy7toytzwfJZDZ2Cb++kzruxvqVDtpWq3 UPantXaG8RvN4YZErGzpech4qC/LRRUQnYX0tcu6dApMl8jTbhfiIPt1U6xY/FfcGH7s Je9lJ5RKMH+DdNRFBvG66uFX9JwyMakqcpJ50Tcm89iGB6NHbJljHKlkLMPEnWJFu/fQ L54ymQ1RUQSuFQ8xpeqjzJkDedA+4MmHQ/9LJDDbRBqZiqNkd3RB89fMsyYOBDzmhdRJ MenqpOfI66A+W8CgS+8vxtD7SGRTJUWAQhpXD+Nbrdpnvg1cBHxE2o0uymAvzPIh1RxV 39uQ== X-Gm-Message-State: AOAM531mkAZvGwirvMWewv0naC+tGGaofD/9E0xWs9K13sV1UnQmoE+R SgjcOGCse6+2G7PcHKKRtltkyQIHrSk27FNQ5lwbyD8QoiBf0KlY9ZuevSUilkhjA45dyBtte7b dyOlqAW+eZsqT5GDT+cJRxLNb X-Received: by 2002:adf:e2c5:: with SMTP id d5mr11472495wrj.338.1636477503999; Tue, 09 Nov 2021 09:05:03 -0800 (PST) X-Received: by 2002:adf:e2c5:: with SMTP id d5mr11472455wrj.338.1636477503802; Tue, 09 Nov 2021 09:05:03 -0800 (PST) Received: from ?IPv6:2a01:e0a:59e:9d80:527b:9dff:feef:3874? ([2a01:e0a:59e:9d80:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id o12sm26601930wrc.85.2021.11.09.09.05.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Nov 2021 09:05:03 -0800 (PST) Subject: Re: [PATCH v4 07/21] KVM: arm64: Support SDEI_EVENT_UNREGISTER hypercall To: Gavin Shan , kvmarm@lists.cs.columbia.edu Cc: maz@kernel.org, linux-kernel@vger.kernel.org, Jonathan.Cameron@huawei.com, pbonzini@redhat.com, will@kernel.org References: <20210815001352.81927-1-gshan@redhat.com> <20210815001352.81927-8-gshan@redhat.com> From: Eric Auger Message-ID: <100a4aa0-6c2d-2fec-6f11-c7e64946ef0b@redhat.com> Date: Tue, 9 Nov 2021 18:05:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210815001352.81927-8-gshan@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/15/21 2:13 AM, Gavin Shan wrote: > 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; don't you want to record the fact the unregistration is outstanding to perform subsequent actions? Otherwise nothing will hapen when the current executing handlers complete? > + goto unlock; > + } > + > + /* Check if it has been registered */ > + kse = kske->kse; > + index = (kse->state.type == SDEI_EVENT_TYPE_PRIVATE) ? > + vcpu->vcpu_idx : 0; you could have an inline for the above as this is executed in many functions. even including the code below. > + 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)) { a refcount mechanism would be cleaner I think. > + 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: >