From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52A46CD6E6B for ; Fri, 5 Jun 2026 08:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Yu8TX8xnp5Yu5oGt44kALrElMZ8ip5Sl8d0Xx/+e4mQ=; b=mYvIKNX16ZJFdig/LpT72Kj359 tXTDYG7vFi94rKx4btQja85dRoAdiIFVplb4pGDUXLZWwcLx/yDqoSvTDZEu407J79gjWP5P6lA3l 2mJTQErlQcOySqWWrXBEIrfGh9RSYBvASLozobJxGq+DjxPSDf3WjX1sC/dfxi/oiUjdYdZrvf2fK tbwhyd6qNVDP3e+oMDjXlpr0JjDFqnCN9ljm9sYlRbORaNNELXX+3LrYWsahndWK3qA3jukeq3YP4 vMdUeMV0lFJFt64+0wOWEnNTemoRyRSfl9kOf0Ku9m7SQfsIX4hTPf0YjSKlqT7qah0ikxQb0tGFL Tlex4dzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wVQNa-00000000Lx8-3WWP; Fri, 05 Jun 2026 08:58:14 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wVQNZ-00000000LwJ-2wRX for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2026 08:58:13 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B62A840853; Fri, 5 Jun 2026 08:58:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 968F81F00893; Fri, 5 Jun 2026 08:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780649891; bh=Yu8TX8xnp5Yu5oGt44kALrElMZ8ip5Sl8d0Xx/+e4mQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=XbzKnU3Q5/W6SSRjC052uv19rILHL1AvqzDpiBYsjU0MNYDjMY1eiAMOAxxiWe6yc 4UTppxRlyw0Z81lKsboH//6XmsJGE1ySaDyeHDucomASARC7LTaRj5WxTWoEfAE4/Q w9/uFETcL/OZP7eIyorHoF/VBBPlfZQWv3FHir4eyU6ioQ/NloCL9CNJkuuaDm1GcQ ImAjUrN0lt0/kQXaTFob6OMBiLnikLPOc6f+oIjW1l4ziUzHw5FmIQFOg78KHvs8Xf y4lPH6HKZ5YSUxOr+7QWA53wQXo83oIYy7r0DR2FzGAttuksAuwi8ZuV+r68eAjRo0 eFa2Il4vsI3gg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wVQNV-00000009hhZ-1uVe; Fri, 05 Jun 2026 08:58:09 +0000 Date: Fri, 05 Jun 2026 09:58:09 +0100 Message-ID: <86zf19tlcu.wl-maz@kernel.org> From: Marc Zyngier To: Hyunwoo Kim Cc: tabba@google.com, oupton@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v2 2/2] KVM: arm64: Bound used_lrs when flushing the pKVM hyp vCPU In-Reply-To: <20260604151210.1304051-3-imv4bel@gmail.com> References: <20260604151210.1304051-1-imv4bel@gmail.com> <20260604151210.1304051-3-imv4bel@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: imv4bel@gmail.com, tabba@google.com, oupton@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 04 Jun 2026 16:12:03 +0100, Hyunwoo Kim wrote: > > flush_hyp_vcpu() copies the host vGIC state into the hyp's private vCPU > on every run. The vGIC list register save and restore use used_lrs as > their loop bound and expect it to stay within the number of implemented > list registers. While this is generally the case, flush_hyp_vcpu() > copies vgic_v3 verbatim and does not enforce this, so a value provided > by the host is used at EL2 to index vgic_lr[] and access ICH_LR_EL2 > (host -> EL2). > > Fix by clamping used_lrs to the number of implemented list registers > after the copy, as the trusted path already does in > vgic_flush_lr_state(). > > Fixes: be66e67f1750 ("KVM: arm64: Use the pKVM hyp vCPU structure in handle___kvm_vcpu_run()") > Signed-off-by: Hyunwoo Kim > --- > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > index 02c5d6e5abcbf..cd807fdb11ba8 100644 > --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > @@ -7,6 +7,7 @@ > #include > #include > > +#include > #include > #include > #include > @@ -142,6 +143,13 @@ static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu) > > hyp_vcpu->vcpu.arch.vgic_cpu.vgic_v3 = host_vcpu->arch.vgic_cpu.vgic_v3; > > + /* Bound used_lrs by the number of implemented list registers. */ > + if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) There is no pKVM support without a GICv3 CPU interface, and absolutely everything already assumes it. Why do we need this extra check? > + hyp_vcpu->vcpu.arch.vgic_cpu.vgic_v3.used_lrs = > + min_t(unsigned int, > + hyp_vcpu->vcpu.arch.vgic_cpu.vgic_v3.used_lrs, > + (read_gicreg(ICH_VTR_EL2) & 0xf) + 1); > + Reading ICH_VTR_EL2 on each entry is going to cause some really heavy trapping under NV, and we should avoid this. kvm_vgic_global_state.nr_lr contains this information, and it should only be a matter of replicating it (or compute it once) at init time. Thanks, M. -- Without deviation from the norm, progress is not possible.