Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7124220ybl; Mon, 23 Dec 2019 18:53:27 -0800 (PST) X-Google-Smtp-Source: APXvYqwwfepDdbST4uRDf5+8buH1s+7I3YIHAxOv9g/Z9rSm9snBluG3jafYkg9qQiXJhbYBwrXZ X-Received: by 2002:a9d:6d10:: with SMTP id o16mr37013152otp.28.1577156007529; Mon, 23 Dec 2019 18:53:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577156007; cv=none; d=google.com; s=arc-20160816; b=FFCGFsxk40+j4QJcOrHRJD0eKgIlEvLAJ9qzAsgOSC23g/0QH3sLJAbW9+efvY5Vp3 SzKYrk2KLIpWrNym7nTgVNdeUr/43dWl6D++Y3klZPbVvjGzIL2fYCg1klI8ZgL/ZhrV Q8Ao1eLm9wWazh1IJp48e3uOqQyYud3rVU95rC0SzBdy9rJeoD+8HcxG5rkiIujXmF3f iarLdA++9kXLXQ0StHnQiXrrGt+KzLPheCP7/5RJ6x0/pYXqli4E/hr8Kx3V7X4TgMGM 7ovIt3pNLvEodIqRg2udJ1St1nIroPNVRdx67P9H6tU/2Dg+ajqLieWxP2wvXlmL1QT1 9SXg== 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=3mEh/gnEzRLoelzir6L6iGa/X+wcKoQLUNU9A4ybHg0=; b=E1qIbzXXwmOqaRuQCz9CRj7Mn0GOMqbABWzAARFTb/KOlOf4qK7pV0FM593toX5NPV FlphzzJdgRUF5T1ai8ObBKmpw5vEQcx6yA2meavMoXLZdAMqHzFde9GA4ywOsJb58XZY rQeb+4h6U9uWhLCzIuih5lTuJ0ujKfew9mJa9SWf4vRAsxdSMIgq/1p5Dugg895K2kjE Ut2ECIh86oFGWYzttijcme+ojqCQaiWkinXNWkqUla6bQRv0ZGgZeoEwJu+wyGQiAWEl pVQaT41kB5M81Ls1QO3lX4o9nHFvrDuTFVdwpKM3sxFzUt+erv0OA+VuhPWRa1KPURcR czpg== 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 i15si10838453otk.120.2019.12.23.18.53.15; Mon, 23 Dec 2019 18:53:27 -0800 (PST) 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 S1726878AbfLXCwi (ORCPT + 99 others); Mon, 23 Dec 2019 21:52:38 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:8166 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726832AbfLXCwh (ORCPT ); Mon, 23 Dec 2019 21:52:37 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 1582691D5E6EDCC03903; Tue, 24 Dec 2019 10:52:35 +0800 (CST) Received: from [127.0.0.1] (10.173.222.27) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Tue, 24 Dec 2019 10:52:27 +0800 Subject: Re: [PATCH] KVM: arm/arm64: vgic: Handle GICR_PENDBASER.PTZ filed as RAZ To: Marc Zyngier CC: , , , , , References: <20191220111833.1422-1-yuzenghui@huawei.com> <3a729559-d0eb-e042-d6bd-b69bacb0dd23@huawei.com> From: Zenghui Yu Message-ID: <1225d839-3cf7-d513-778e-698e12e94875@huawei.com> Date: Tue, 24 Dec 2019 10:52:26 +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: 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, Eric, On 2019/12/23 22:07, Marc Zyngier wrote: > Hi Zenghui, > > On 2019-12-23 13:43, Zenghui Yu wrote: >> On 2019/12/20 19:18, Zenghui Yu wrote: >>> Although guest will hardly read and use the PTZ (Pending Table Zero) >>> bit in GICR_PENDBASER, let us emulate the architecture strictly. >>> As per IHI 0069E 9.11.30, PTZ field is WO, and reads as 0. >>> Signed-off-by: Zenghui Yu >>> --- >>> Noticed when checking all fields of GICR_PENDBASER register. >>> But _not_ sure whether it's worth a fix, as Linux never sets >>> the PTZ bit before enabling LPI (set GICR_CTLR_ENABLE_LPIS). >>> And I wonder under which scenarios can this bit be written as 1. >>> It seems difficult for software to determine whether the pending >>> table contains all zeros when writing this bit. >>> virt/kvm/arm/vgic/vgic-mmio-v3.c | 5 ++++- >>>   1 file changed, 4 insertions(+), 1 deletion(-) >>> diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c >>> b/virt/kvm/arm/vgic/vgic-mmio-v3.c >>> index 7dfd15dbb308..ebc218840fc2 100644 >>> --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c >>> +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c >>> @@ -414,8 +414,11 @@ static unsigned long >>> vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu, >>>                            gpa_t addr, unsigned int len) >>>   { >>>       struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; >>> +    u64 value = vgic_cpu->pendbaser; >>>   -    return extract_bytes(vgic_cpu->pendbaser, addr & 7, len); >>> +    value &= ~GICR_PENDBASER_PTZ; >>> + >>> +    return extract_bytes(value, addr & 7, len); >>>   } >>>   static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, >>> >> >> I noticed there is no userspace access callbacks for GICR_PENDBASER, >> so this patch will make the PTZ field also 'Read As Zero' by userspace. >> Should we consider adding a uaccess_read callback for GICR_PENDBASER >> which just returns the unchanged vgic_cpu->pendbaser to userspace? >> (Though this is really not a big deal. We now always emulate the PTZ >> field to guest as RAZ. And 'vgic_cpu->pendbaser & GICR_PENDBASER_PTZ' >> only indicates whether KVM will optimize the LPI enabling process, >> where Read As Zero indicates never optimize..) > > I don't think adding a userspace accessor would help much. All this > bit tells userspace is that the guest has programmed a zero filled > table. On restore, we'd avoid a rescan of the table if there was > no LPI mapped. Yes, I agree. > And thinking of it, this fixes a bug for non-Linux guests: If you write > PTZ=1, we never clear it. Which means that if userspace saves and restores > PENDBASER with PTZ set, we'll never restore the pending bits, which is > pretty bad (see vgic_enable_lpis()). But I'm afraid I can't follow this point. After reading the code (with Qemu) a bit further, the Redistributors are restored before the ITS. So there should be _no_ LPI has been mapped when we're restoring GICR_CTLR and enabling LPI, which says we will not scan the whole pending table and restore pending by vgic_enable_lpis()/its_sync_lpi_pending_table(), regardless of what the PTZ is. Instead, vgic_its_restore_ite()/vgic_v3_lpi_sync_pending_status() is where we actually read the guest RAM and restore the LPI pending state. Which means we will still do the right thing even for non-Linux guests. Not sure if I've got things correctly here. In the end, let's keep the patch as it is. > > This patch on its own fixes more than one bug! > If so, just by luck ;-) Thanks, Zenghui