Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6449430ybl; Mon, 23 Dec 2019 06:08:43 -0800 (PST) X-Google-Smtp-Source: APXvYqz9Rhqcg/HmYWIpHtgH4yEJ9mCNOp4GI3zOtfqsC5dbubzQ+xKOp31zB+bQTu1Kym5Dfopj X-Received: by 2002:a05:6830:110a:: with SMTP id w10mr33746763otq.300.1577110122760; Mon, 23 Dec 2019 06:08:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577110122; cv=none; d=google.com; s=arc-20160816; b=NFPgEm/s6coRtBzrswLUAD71Bt9Wbku2ZUUSC9EfGyC64ge7TWp3gGNtK9Kk+9f+gB e9mALmlLe8wRsDVV/YeffjnL7pgyQCag23M/VkMo1Sehft70Xi/SUxh4uHKdMYS0jAeS nJ4eLJ0eVKRabc1K0bh3RSSfZ/wibSclUGnJqoFXv2tTqLc9cWYbvo/csF+I+QowhJgU ZyfDHujD8PSENX8Z4LbXc+lWzBbxTZxAP9be1VuEeKIxdgKuVMRJt2Wjv3LPmnW1oaaL 4s6GO4Hdo9Qp9seKC1+dACfaSLUicd/x7nFin4BW+3bfk74IxFPeZ7bQtir5j9qTiPmv qtUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:cc:from:date:content-transfer-encoding:mime-version :subject:to; bh=8JsaW3x4mBWoCDqOkrK2oPp0tIC/CJuCGO/BX/H8O0c=; b=ociMBFWcoQEV0HW49WZW4NJyii0QKR5fXqfsbLb9OpmR6HGc+Br0SHzqM/LhTE+HWl JTBeHawli/pOBDIZrWYL2Y+fqO32CRmh6+lXA172VGAnDQAlb1mPcafUMLdKbd4WNLPH YzSPjWjesC4k/3lGD9+uvHulupicpj3MtACdNJHBPr4wRNTyWa0Mcja4m3QS3J4phKz+ Ohg5VejaZKyyGFVKMOE250Hlh5i1xNj+vS7VY8R7VAuOpqTpucJalT8bIV35LViGpOcu TNyDIByil6U9qiconNdIMRNN4XOz9rdEDm5PC/Evp3kFAzAROkg0sBtLWHPGdcw0R+vO ZzHg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p184si8167537oib.144.2019.12.23.06.08.30; Mon, 23 Dec 2019 06:08:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726907AbfLWOH1 (ORCPT + 99 others); Mon, 23 Dec 2019 09:07:27 -0500 Received: from inca-roads.misterjones.org ([213.251.177.50]:50280 "EHLO inca-roads.misterjones.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726682AbfLWOH0 (ORCPT ); Mon, 23 Dec 2019 09:07:26 -0500 Received: from www-data by cheepnis.misterjones.org with local (Exim 4.80) (envelope-from ) id 1ijOMh-0006s5-8h; Mon, 23 Dec 2019 15:07:19 +0100 To: Zenghui Yu Subject: Re: [PATCH] KVM: arm/arm64: vgic: Handle =?UTF-8?Q?GICR=5FPENDBAS?= =?UTF-8?Q?ER=2EPTZ=20filed=20as=20RAZ?= X-PHP-Originating-Script: 0:main.inc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 23 Dec 2019 14:07:19 +0000 From: Marc Zyngier Cc: , , , , , In-Reply-To: <3a729559-d0eb-e042-d6bd-b69bacb0dd23@huawei.com> References: <20191220111833.1422-1-yuzenghui@huawei.com> <3a729559-d0eb-e042-d6bd-b69bacb0dd23@huawei.com> Message-ID: X-Sender: maz@kernel.org User-Agent: Roundcube Webmail/0.7.2 X-SA-Exim-Connect-IP: X-SA-Exim-Rcpt-To: yuzenghui@huawei.com, andre.przywara@arm.com, eric.auger@redhat.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, wanghaibin.wang@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on cheepnis.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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()). This patch on its own fixes more than one bug! Thanks, M. -- Jazz is not dead. It just smells funny...