Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7195898ybl; Mon, 23 Dec 2019 20:48:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwttvdy9WpFV94oh4EdHvyeREWbJVZSiEeW9ul+6VP9986/11rW5eH43xybTs6/qXDMFRTS X-Received: by 2002:a9d:664a:: with SMTP id q10mr27498950otm.99.1577162892254; Mon, 23 Dec 2019 20:48:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577162892; cv=none; d=google.com; s=arc-20160816; b=B79Nc9+HLUKMj3vEKp8K8NoC3CMfZ2W0RP+cWmRuhvErA79EdUB+MQSTc/MaBn2LK2 DGzlWL4u6NNwZcM8+H6NMWauSMZb5vhbbXL2IKATgxTgqDh289da9uDA6pR3dp9dR9z5 c4J2GkY6XAQObnx7PEDB6SyejB4sHmYyWglJgyrz2ey79La9jQMXTdfRfwVXrjts0aTb ecPVNSWXxDCemVDWtJWsOLDyuJFNBx4cDJZXMdWUbNUFAlZiq3TeKMrdIc0ZALqtPYy0 o1RXPtvXY+dqfi1fJSM98d2pz+qfjVNpHGflwN3fufv3nWggoNN8jVvwYOv8cfPqDbEH cTwQ== 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:dkim-signature; bh=0QvQOGSsD6BCQ/KZZeRtn8Sn6aNp+vhwPhxNJ2ctz9g=; b=sIGqbaQQa83iM7v3ValS+wVkqbV3DyDo7ktVs14LccYs0GCjWS21oVbkbW/ULAGA9D +LW0Mb7A74GoUdy4/WreunctZcUD2XaHeFl6jcBl+rk9Gv5FVKbGQLTVWMLkss2cfMeh rdF84bwfJ+fvh/rU5wxP+vNUbVQhAcf5hCZheWL4JM/fr6TykLYUHoYq5I04N1LHSAYa a5pskCGFAG0TMmRlsMEy+X0RzitUlfdJJSY7uwX6JIcH5qJI6lmj35SLzzojflOcg7ja UjqT0XDuBpvvjGs/jClxFDI7OXh96U0GM4qI9se5IQ3OENYqjTNI6H6tbCo29Zb+8D7V 2NdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iZ1FOaWV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p83si10226542oih.198.2019.12.23.20.47.59; Mon, 23 Dec 2019 20:48:12 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iZ1FOaWV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726995AbfLXEph (ORCPT + 99 others); Mon, 23 Dec 2019 23:45:37 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:39016 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726853AbfLXEph (ORCPT ); Mon, 23 Dec 2019 23:45:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577162735; 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=0QvQOGSsD6BCQ/KZZeRtn8Sn6aNp+vhwPhxNJ2ctz9g=; b=iZ1FOaWV5uZvITwjE6ncOt0nums8TdMg4KvEuAaorFANAeDgxfpICHxKqK5fwYVANQI4fT f0utBJyGhthLX4ebyvFNlCVAgZ1j1dOQqNFFqcFWpxcAGUcSRWp8NwALxDLGJTUMk3KIg3 IY3t/WmnDUjBd8Exv+HrFeI3p+G6qAY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-65-Hoek3P4zOCSlBGu07fty_A-1; Mon, 23 Dec 2019 23:45:32 -0500 X-MC-Unique: Hoek3P4zOCSlBGu07fty_A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAEBB184B461; Tue, 24 Dec 2019 04:45:30 +0000 (UTC) Received: from [10.36.116.117] (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 141505DA60; Tue, 24 Dec 2019 04:45:20 +0000 (UTC) Subject: Re: [PATCH] KVM: arm/arm64: vgic: Handle GICR_PENDBASER.PTZ filed as RAZ To: Zenghui Yu , Marc Zyngier Cc: andre.przywara@arm.com, linux-kernel@vger.kernel.org, wanghaibin.wang@huawei.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org References: <20191220111833.1422-1-yuzenghui@huawei.com> <3a729559-d0eb-e042-d6bd-b69bacb0dd23@huawei.com> <1225d839-3cf7-d513-778e-698e12e94875@huawei.com> From: Auger Eric Message-ID: <12a1e25b-617d-6b04-6a5a-4c67a39565a5@redhat.com> Date: Tue, 24 Dec 2019 05:45:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1225d839-3cf7-d513-778e-698e12e94875@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zenghui, On 12/24/19 3:52 AM, Zenghui Yu wrote: > Hi Marc, Eric, >=20 > 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 ++++- >>>> =C2=A0 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, >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 gpa_t addr, unsigned int len) >>>> =C2=A0 { >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct vgic_cpu *vgic_cpu =3D &vcpu->= arch.vgic_cpu; >>>> +=C2=A0=C2=A0=C2=A0 u64 value =3D vgic_cpu->pendbaser; >>>> =C2=A0 -=C2=A0=C2=A0=C2=A0 return extract_bytes(vgic_cpu->pendbaser,= addr & 7, len); >>>> +=C2=A0=C2=A0=C2=A0 value &=3D ~GICR_PENDBASER_PTZ; >>>> + >>>> +=C2=A0=C2=A0=C2=A0 return extract_bytes(value, addr & 7, len); >>>> =C2=A0 } >>>> =C2=A0 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 userspac= e. >>> 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. >=20 > Yes, I agree. >=20 >> And thinking of it, this fixes a bug for non-Linux guests: If you writ= e >> PTZ=3D1, 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()). >=20 > 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. This is also part of the kernel documentation: Documentation/virt/kvm/devices/arm-vgic-its.txt (ITS restore sequence) 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. >=20 > 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. yes the pending state is restored from vgic_its_restore_ite/vgic_add_lpi/vgic_v3_lpi_sync_pending_status and this path ignores the PTZ. Thanks Eric > Which means we will still do the right thing even for non-Linux guests. > Not sure if I've got things correctly here. >=20 > In the end, let's keep the patch as it is. >=20 >> >> This patch on its own fixes more than one bug! >> >=20 > If so, just by luck ;-) >=20 >=20 > Thanks, > Zenghui >=20 >=20 > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel