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 AB7EBCD8C8C for ; Sun, 7 Jun 2026 17:57:06 +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=BjwXzAqn09XGqwiofLmSdzwFEecQWhSyb73CLPOpiE0=; b=3LXRGeJlT3gd2efh7Ut9cIXlog ZP0Xwq1wqSvfLNNGa6w1eRWyP35l2g4sfUAgZl9JaiUCa49rvUtrqRgAxxi+eIQNP7prTAR/LAdc2 1OopktnFZC9IUZcGhHemibumbLmDpBnQ2kMDcLwSGZfiVzFvekHkfroW8DrM64+VXPeJh+utfVkfQ mGmyT1uK95njSTb9VFOkF9MbTJEd7i6yOdlpTEbs5TF7jOupj6PN6/iElaigw6RwwdOeRCjjR3FNX p5JCTLOWps/xsMaSV2jQLQltokomkmy9NPfZF9JLuP5L68RIbjX4Clwo2lK9fy7Vqw/1IxK8Faqoa Y/yKVOjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wWHk3-00000002Nsq-3Ahu; Sun, 07 Jun 2026 17:56:59 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wWHk3-00000002Nsk-0uAf for linux-arm-kernel@lists.infradead.org; Sun, 07 Jun 2026 17:56:59 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 40AFF60018; Sun, 7 Jun 2026 17:56:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E864D1F00893; Sun, 7 Jun 2026 17:56:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780855018; bh=BjwXzAqn09XGqwiofLmSdzwFEecQWhSyb73CLPOpiE0=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=md+5SvzoVgkMo++0FXqv/QtZ587IK43WpQwvAceByUuP0zfJHConm4uV9SdHR3bO6 N56R7SE3gbHVbzVkph+kPwNPyKujt74YqmmihtqT0WDqZaSPp01NeXJ0uVgoXLZLMF TqlJdsboENkonutk15z9r/dg2gUtoWDp0t2ur4M0/qENZgECkJNKoH77df2v8N+b7u 3Kr2Au/Wxi73fxVKgJpftMj2/RVYYZ3WNR/jDCNSDKFT7qOqZYAYx7+Y8CZNLiyOHV DF/V8C524sp4I1Z3BcenuskDK+u0j6aaiEDRvF4tmH6wcHge/OSZccujVxy0Qqb5lu Ul2M+sIb2Og2g== Received: from sofa.misterjones.org ([185.219.108.64] helo=lobster-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 1wWHk0-0000000AEPF-079p; Sun, 07 Jun 2026 17:56:56 +0000 Date: Sun, 07 Jun 2026 19:00:16 +0100 Message-ID: <87wlwa8c3z.wl-maz@kernel.org> From: Marc Zyngier To: Hyunwoo Kim Cc: 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] KVM: arm64: nv: Skip vCPUs without a pseudo-TLB in invalidate_vncr_va() In-Reply-To: References: <8733yya4ch.wl-maz@kernel.org> 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, 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 Sun, 07 Jun 2026 14:36:44 +0100, Hyunwoo Kim wrote: > > On Sun, Jun 07, 2026 at 02:05:02PM +0100, Marc Zyngier wrote: > > On Sun, 07 Jun 2026 09:43:53 +0100, > > Hyunwoo Kim wrote: > > > > > > vncr_tlb is not allocated before a vCPU runs for the first time, so > > > vcpu->arch.vncr_tlb is NULL for a vCPU that has been created but not yet > > > run. Code that iterates over every vCPU's pseudo-TLB must skip those. > > > > > > invalidate_vncr_va() iterates over the vCPUs with kvm_for_each_vcpu() and > > > dereferences vt->valid without checking whether vncr_tlb is NULL. > > > > > > While iterating, skip vCPUs whose pseudo-TLB has not been allocated. > > > > > > Fixes: 4ffa72ad8f37 ("KVM: arm64: nv: Add S1 TLB invalidation primitive for VNCR_EL2") > > > Signed-off-by: Hyunwoo Kim > > > --- > > > arch/arm64/kvm/nested.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c > > > index 6f7bc9a9992e..063e079d1d1a 100644 > > > --- a/arch/arm64/kvm/nested.c > > > +++ b/arch/arm64/kvm/nested.c > > > @@ -969,6 +969,10 @@ static void invalidate_vncr_va(struct kvm *kvm, > > > struct vncr_tlb *vt = vcpu->arch.vncr_tlb; > > > u64 va_start, va_end, va_size; > > > > > > + /* Skip vCPUs whose pseudo-TLB hasn't been allocated yet */ > > > + if (!vt) > > > + continue; > > > + > > > if (!vt->valid) > > > continue; > > > > > > > This looks correct and matches what we already have for > > invalidate_vncr_ipa(). > > > > But I think this misses the opportunity to squash a whole class of > > similar bugs, should we ever have the need for another function that > > iterates over all *valid* VNCR pseudo-TLBs. > > > > Since I'm on a train and have nothing better to do, I've written the > > following hack. > > > > Thoughts? > > Looks like a good direction to me. I confirmed it fixes the issue (as > expected). > > How about you submit this patch yourself? Sure, can do. I'll sent that in a minute. > > +#define kvm_for_each_vncr_tlb(idx, vcpup, tlbp, kvm) \ > > + kvm_for_each_vcpu(idx, vcpu, kvm) \ > > Maybe vcpu -> vcpup? Duh. Yes. Thanks. M. -- Jazz isn't dead. It just smells funny.