Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3458084ybb; Mon, 23 Mar 2020 01:11:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs3eCcJIfg2wKsjpqqH5uQtN4tIA417U/mANl84NejnwKQaESi8PquAmfVlMRd68Austg4K X-Received: by 2002:a05:6830:1581:: with SMTP id i1mr16246781otr.349.1584951111030; Mon, 23 Mar 2020 01:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584951111; cv=none; d=google.com; s=arc-20160816; b=R2Co5JafQ0GaqjLXb+C42/XRbeifTAO04/edtsxTambT253RupekDeHiGz1ozIFquw QKT7ElQzewJnt2WWogldMU52CmUhhQ3LAngz77o/QIbh9fkPanKHIxmMqFscSpTIsGO5 UOiyIdu+n+AzdchWpn19fX8g4NT7fR03z2uQ4KSMvVYJdf9lHbjf6wSbt5cb9BSnXcCX Rf7Fs3C/5eX1jWBnRMruoRDisLxP1krP7i0FKvGV8rbPsDiM/2ymTATANEXJZvN+vUPq z5dayarStJaRJTIx0u8uoa8zNbnmH6umNmUfID6uIZupsJvvZQFDz3wXwvcxqezPFrgH nnJw== 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=XAB4u4r3pPIzcdsM0ILgoGDk9RmzSqcH0eRiO4XYGo8=; b=tuJqTfCg/0OCgp22JB5fomqQsH/pVbldmB99v2WYRF1hvLjsh9ocUMmU6FDft7jaVc MwBzGIxpKiGSK/pJWcAdxrGPwdHqAQI33yNOD0+XmxYYwKBFb2c/tzlnqoiXtJx8Zkdy X9C+LDTyz6OTzGnwvkmKP9TyI3zih253fE5nEdiLKUkvSm7jCP5P2HnqNbY63w/gfO7B iIB80SLimMNCrUA5m57k1GY0WwSdAWECS6zKgTMesirOxFgHCREnRRhV+jaM59+LIkmd oRT8gdKpwspr4ZJH2YHa1myu4ami2pG0m2DKdOYVsuEaDcH3ltwF8QSIEA3jARKa2k6t pXEA== 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 x7si7317089oto.262.2020.03.23.01.11.37; Mon, 23 Mar 2020 01:11:51 -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 S1727531AbgCWILT (ORCPT + 99 others); Mon, 23 Mar 2020 04:11:19 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:35004 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727422AbgCWILT (ORCPT ); Mon, 23 Mar 2020 04:11:19 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id CDDB242FB3B17C38F76B; Mon, 23 Mar 2020 16:11:09 +0800 (CST) Received: from [127.0.0.1] (10.173.222.27) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Mon, 23 Mar 2020 16:11:02 +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> <72832f51-bbde-8502-3e03-189ac20a0143@huawei.com> <4a06fae9c93e10351276d173747d17f4@kernel.org> <1c9fdfc8-bdb2-88b6-4bdc-2b9254dfa55c@huawei.com> <256b58a9679412c96600217f316f424f@kernel.org> From: Zenghui Yu Message-ID: Date: Mon, 23 Mar 2020 16:11:00 +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: <256b58a9679412c96600217f316f424f@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit 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/20 17:01, Marc Zyngier wrote: > Hi Zenghui, > > On 2020-03-20 03:53, Zenghui Yu wrote: >> Hi Marc, >> >> On 2020/3/19 20:10, Marc Zyngier wrote: >>>> 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. >>> >>> I'm unsure of what you're suggesting here. If userspace tries to set >>> GICD_CTLR.nASSGIreq on a non-4.1 host, this bit will not latch. >> >> This is exactly what I *was* concerning about. >> >>> Userspace can check that at restore time. Or we could fail the >>> userspace write, which is a bit odd (the bit is otherwise RES0). >>> >>> Could you clarify your proposal? >> >> Let's assume two hosts below. 'has_gicv4_1' is true on host-A while >> it is false on host-B because of lack of HW support or the kernel >> parameter "kvm-arm.vgic_v4_enable=0". >> >> If we migrate guest through A->B->A, we may end-up lose the initial >> guest-request "nASSGIreq=1" and don't use direct vSGI delivery for >> this guest when it's migrated back to host-A. > > My point above is that we shouldn't allow the A->B migration the first > place, and fail it as quickly as possible. We don't know what the guest > has observed in terms of GIC capability, and it may not have enabled the > new flavour of SGIs just yet. Indeed. I didn't realize it. > >> This can be "fixed" by keep track of what guest had written into >> nASSGIreq. And we need to evaluate the need for using direct vSGI >> for a specified guest by 'has_gicv4_1 && nassgireq'. > > It feels odd. It means we have more state than the HW normally has. > I have an alternative proposal, see below. > >> But if it's expected that "if userspace tries to set nASSGIreq on >> a non-4.1 host, this bit will not latch", then this shouldn't be >> a problem at all. > > Well, that is the semantics of the RES0 bit. It applies from both > guest and userspace. > > And actually, maybe we can handle that pretty cheaply. If userspace > tries to restore GICD_TYPER2 to a value that isn't what KVM can > offer, we just return an error. Exactly like we do for GICD_IIDR. > Hence the following patch: > > diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c > b/virt/kvm/arm/vgic/vgic-mmio-v3.c > index 28b639fd1abc..e72dcc454247 100644 > --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c > +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c > @@ -156,6 +156,7 @@ static int vgic_mmio_uaccess_write_v3_misc(struct > kvm_vcpu *vcpu, >      struct vgic_dist *dist = &vcpu->kvm->arch.vgic; > >      switch (addr & 0x0c) { > +    case GICD_TYPER2: >      case GICD_IIDR: >          if (val != vgic_mmio_read_v3_misc(vcpu, addr, len)) >              return -EINVAL; > > Being a RO register, writing something that isn't compatible with the > possible behaviour of the hypervisor will just return an error. This is really a nice point to address my concern! I'm happy to see this in v6 now. > > What do you think? I agreed with you, with a bit nervous though. Some old guests (which have no knowledge about GICv4.1 vSGIs and don't care about nASSGIcap at all) will also fail to migrate from A to B, just because now we present two different (unused) GICD_TYPER2 registers to them. Is it a little unfair to them :-) ? Thanks, Zenghui