Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp295924ybh; Tue, 17 Mar 2020 23:36:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsqnLpWw1N/W4jMc/ZiGElGmbLnCZugIGY8vO59GFYKUswdmCO99wt7TlssfI5UT0QnRYbg X-Received: by 2002:a9d:1708:: with SMTP id i8mr2629266ota.250.1584513379848; Tue, 17 Mar 2020 23:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584513379; cv=none; d=google.com; s=arc-20160816; b=DqNMPL22tcWE8cWW1EpzChLflevY1q04qXBvOCyf323YdjaPtM5pZ3ycvZiwDXEdgj dhYg5yPCyA+SvUCYJhXupO+Q+hKP+uom07mtT1OFrS+3r5i6PT/3QPiCGvLaG2eSlbf0 jabTCEovUDIE7lXpb39Kk50J1ATgtKGO44rRhx+59ICIuLT2A1vF46hOMPQzJ4YNE2c7 cZsWxY4LYIAQm1D6Rn2t5J9vyQgv4LIp8iqSsfs6iuac3X2aqv48Eli4yPntiqqncXoM 4+kwyiHe4t9/4LWcStS5TyXAterxWms1VZ4oGQR3pN7gvSzE2V38YX09febzTvNX7s12 UDrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=9ZwXAmJLxjtBnfp5gy5ZpSmnHmu5vhD9HNIChXb7/w0=; b=Q141UZ+Hp5KgTKuyCtfQGadJYU5jFugxasfWKavIKU9iZWRgDs7X6NzXIkiyIVO807 NRQWaFGgFwvP6Dv3qwW+qCbAnwdLfb49+STsmrPmP0qqu3uOKi6tJCdo64l9gwZ6CBid NhcQG+WC14SFyWgUSjX42Nf4As2vaGl7E6EEoDUyIbFPxXTHBnTKb4J2ztbhIwy+JIIY Pba+yEzj621i8a1uBNRCvb05Ail61mgXfF6Vv/KFoH8B4ZN8aRbbQ1UYliBMv7SepI0t VkfM53/RuwELDEZiEFuL9jdUf8+WMFiW6rvCRyNcTTaXDj9oxBM3PgasfAY0Q8n2GPtR 9nag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si3046007otk.127.2020.03.17.23.36.07; Tue, 17 Mar 2020 23:36:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbgCRGfb (ORCPT + 99 others); Wed, 18 Mar 2020 02:35:31 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:37890 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726478AbgCRGfb (ORCPT ); Wed, 18 Mar 2020 02:35:31 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 687BA464783BCDA51C81; Wed, 18 Mar 2020 14:35:13 +0800 (CST) Received: from [127.0.0.1] (10.173.222.27) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Wed, 18 Mar 2020 14:35:07 +0800 Subject: Re: [PATCH v5 20/23] KVM: arm64: GICv4.1: Plumb SGI implementation selection in the distributor To: Marc Zyngier , , , , CC: Lorenzo Pieralisi , Jason Cooper , Robert Richter , "Thomas Gleixner" , Eric Auger , "James Morse" , Julien Thierry , Suzuki K Poulose References: <20200304203330.4967-1-maz@kernel.org> <20200304203330.4967-21-maz@kernel.org> From: Zenghui Yu Message-ID: <72832f51-bbde-8502-3e03-189ac20a0143@huawei.com> Date: Wed, 18 Mar 2020 14:34:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <20200304203330.4967-21-maz@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.222.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marc, On 2020/3/5 4:33, Marc Zyngier wrote: > The GICv4.1 architecture gives the hypervisor the option to let > the guest choose whether it wants the good old SGIs with an > active state, or the new, HW-based ones that do not have one. > > For this, plumb the configuration of SGIs into the GICv3 MMIO > handling, present the GICD_TYPER2.nASSGIcap to the guest, > and handle the GICD_CTLR.nASSGIreq setting. > > In order to be able to deal with the restore of a guest, also > apply the GICD_CTLR.nASSGIreq setting at first run so that we > can move the restored SGIs to the HW if that's what the guest > had selected in a previous life. I'm okay with the restore path. But it seems that we still fail to save the pending state of vSGI - software pending_latch of HW-based vSGIs will not be updated (and always be false) because we directly inject them through ITS, so vgic_v3_uaccess_read_pending() can't tell the correct pending state to user-space (the correct one should be latched in HW). It would be good if we can sync the hardware state into pending_latch at an appropriate time (just before save), but not sure if we can... > > Signed-off-by: Marc Zyngier > --- > virt/kvm/arm/vgic/vgic-mmio-v3.c | 48 ++++++++++++++++++++++++++++++-- > virt/kvm/arm/vgic/vgic-v3.c | 2 ++ > 2 files changed, 48 insertions(+), 2 deletions(-) > > diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c > index de89da76a379..442f3b8c2559 100644 > --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c > +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c > @@ -3,6 +3,7 @@ > * VGICv3 MMIO handling functions > */ > > +#include > #include > #include > #include > @@ -70,6 +71,8 @@ static unsigned long vgic_mmio_read_v3_misc(struct kvm_vcpu *vcpu, > if (vgic->enabled) > value |= GICD_CTLR_ENABLE_SS_G1; > value |= GICD_CTLR_ARE_NS | GICD_CTLR_DS; > + if (kvm_vgic_global_state.has_gicv4_1 && vgic->nassgireq) Looking at how we handle the GICD_CTLR.nASSGIreq setting, I think "nassgireq==true" already indicates "has_gicv4_1==true". So this can be simplified. But I wonder that should we use nassgireq to *only* keep track what the guest had written into the GICD_CTLR.nASSGIreq. If not, we may lose the guest-request bit after migration among hosts with different has_gicv4_1 settings. The remaining patches all look good to me :-). I will wait for you to confirm these two concerns. Thanks, Zenghui > + value |= GICD_CTLR_nASSGIreq; > break; > case GICD_TYPER: > value = vgic->nr_spis + VGIC_NR_PRIVATE_IRQS; > @@ -81,6 +84,10 @@ static unsigned long vgic_mmio_read_v3_misc(struct kvm_vcpu *vcpu, > value |= (INTERRUPT_ID_BITS_SPIS - 1) << 19; > } > break; > + case GICD_TYPER2: > + if (kvm_vgic_global_state.has_gicv4_1) > + value = GICD_TYPER2_nASSGIcap; > + break; > case GICD_IIDR: > value = (PRODUCT_ID_KVM << GICD_IIDR_PRODUCT_ID_SHIFT) | > (vgic->implementation_rev << GICD_IIDR_REVISION_SHIFT) | > @@ -98,17 +105,43 @@ static void vgic_mmio_write_v3_misc(struct kvm_vcpu *vcpu, > unsigned long val) > { > struct vgic_dist *dist = &vcpu->kvm->arch.vgic; > - bool was_enabled = dist->enabled; > > switch (addr & 0x0c) { > - case GICD_CTLR: > + case GICD_CTLR: { > + bool was_enabled, is_hwsgi; > + > + mutex_lock(&vcpu->kvm->lock); > + > + was_enabled = dist->enabled; > + is_hwsgi = dist->nassgireq; > + > dist->enabled = val & GICD_CTLR_ENABLE_SS_G1; > > + /* Not a GICv4.1? No HW SGIs */ > + if (!kvm_vgic_global_state.has_gicv4_1) > + val &= ~GICD_CTLR_nASSGIreq; > + > + /* Dist stays enabled? nASSGIreq is RO */ > + if (was_enabled && dist->enabled) { > + val &= ~GICD_CTLR_nASSGIreq; > + val |= FIELD_PREP(GICD_CTLR_nASSGIreq, is_hwsgi); > + } > + > + /* Switching HW SGIs? */ > + dist->nassgireq = val & GICD_CTLR_nASSGIreq; > + if (is_hwsgi != dist->nassgireq) > + vgic_v4_configure_vsgis(vcpu->kvm); > + > if (!was_enabled && dist->enabled) > vgic_kick_vcpus(vcpu->kvm); > + > + mutex_unlock(&vcpu->kvm->lock); > break; > + } > case GICD_TYPER: > + case GICD_TYPER2: > case GICD_IIDR: > + /* This is at best for documentation purposes... */ > return; > } > } > @@ -117,10 +150,21 @@ static int vgic_mmio_uaccess_write_v3_misc(struct kvm_vcpu *vcpu, > gpa_t addr, unsigned int len, > unsigned long val) > { > + struct vgic_dist *dist = &vcpu->kvm->arch.vgic; > + > switch (addr & 0x0c) { > case GICD_IIDR: > if (val != vgic_mmio_read_v3_misc(vcpu, addr, len)) > return -EINVAL; > + return 0; > + case GICD_CTLR: > + /* Not a GICv4.1? No HW SGIs */ > + if (!kvm_vgic_global_state.has_gicv4_1) > + val &= ~GICD_CTLR_nASSGIreq; > + > + dist->enabled = val & GICD_CTLR_ENABLE_SS_G1; > + dist->nassgireq = val & GICD_CTLR_nASSGIreq; > + return 0; > } > > vgic_mmio_write_v3_misc(vcpu, addr, len, val); > diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c > index 1bc09b523486..2c9fc13e2c59 100644 > --- a/virt/kvm/arm/vgic/vgic-v3.c > +++ b/virt/kvm/arm/vgic/vgic-v3.c > @@ -540,6 +540,8 @@ int vgic_v3_map_resources(struct kvm *kvm) > goto out; > } > > + if (kvm_vgic_global_state.has_gicv4_1) > + vgic_v4_configure_vsgis(kvm); > dist->ready = true; > > out: >