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 D6A4AE7DEF0 for ; Mon, 2 Feb 2026 14:45:49 +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=Ahk8+k1CVfEqwjSqRoqbhdzC47aQQ+I1gf1jEvUvkaw=; b=ZUI3LvixdiCwP33BXbFEjNsncR 0mNUEmywR7rmJO+IMUzPmxahq1QXHgI2uhikW+ubrbRBSxTJihFCHUiIsDtQkx72mYb0eoHZhE+e6 UymlrlkVYjoIIbu8X+ddb2X5CjiallmvUnoYqU5EROQmSBQp/QpUW5g0dZ78tCThyWNPrdtMwTuGy 84yv3w+5jVG/alWSK7kaBXN/CktZDS6hzRciZlfv9f2R9T2mjkxX8xAq0AbyBqBYJV1Z1/anUbBE0 Vkw+ejRHJHO/ijBGg5w67Z4uwoKsHRVBUdnG+aZKq27M4dz6UMf83IagSZ9UZlKHjYWF8uBFh29kV IXPTlkjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vmvBQ-000000057f5-0ULS; Mon, 02 Feb 2026 14:45:44 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vmvBO-000000057ew-3jYL for linux-arm-kernel@lists.infradead.org; Mon, 02 Feb 2026 14:45:43 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 554D260121; Mon, 2 Feb 2026 14:45:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05028C116C6; Mon, 2 Feb 2026 14:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770043542; bh=BnvZh8Om2JZS78ajUbACUahIMrCteVQ3uDiQsuhUGCk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gO9AG1QJV3HugxXNmlwIY4zaUTOs3eWBivy6nbecOhB3pu1lYt+5yDV6Rz6aCmk1k lh6xHjYyE4uymtgDY0GAbyoNgMcg79eBUobb5AdTny4k7ghxujDr2scA7F7QExKgG8 jC4UpBd44kg0jYteqv+/+pLvsq5qKTIzdI7N3LOlb1ikUgQpIQKY7awS4bSeLIV7/p jCyMhg6jxdh8jdkDQH+nO9T9z5ZwNZaikuM2BSuqb+MfqCEPngJTFlZU8PP8v3UoQ8 RADcPu+xzp+676oaOUJM5Ac8KT4S3Ppy/nHuqUiyz7QxzDtlVA//mqpaHPt8lkwnvH t2wfTdfYtlGtw== 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 1vmvBL-00000007o8W-2xGJ; Mon, 02 Feb 2026 14:45:39 +0000 Date: Mon, 02 Feb 2026 14:45:39 +0000 Message-ID: <86tsvz9pbg.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, qperret@google.com Subject: Re: [PATCH v1] KVM: arm64: nv: Use kvm_phys_size() for VNCR invalidation range In-Reply-To: <20260202130513.49436-1-tabba@google.com> References: <20260202130513.49436-1-tabba@google.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: tabba@google.com, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, qperret@google.com 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 Mon, 02 Feb 2026 13:04:24 +0000, Fuad Tabba wrote: > > KVM: arm64: nv: Use kvm_phys_size() for VNCR invalidation range > > Protected mode uses `pkvm_mappings` of the union inside `struct kvm_pgtable`. > This aliases `ia_bits`, which is used in non-protected mode. > > Attempting to use `pgt->ia_bits` in kvm_nested_s2_unmap() and > kvm_nested_s2_wp() results in reading mapping pointers or state as a > shift amount. This triggers a UBSAN shift-out-of-bounds error: > > UBSAN: shift-out-of-bounds in arch/arm64/kvm/nested.c:1127:34 > shift exponent 174565952 is too large for 64-bit type 'unsigned long' > Call trace: > __ubsan_handle_shift_out_of_bounds+0x28c/0x2c0 > kvm_nested_s2_unmap+0x228/0x248 > kvm_arch_flush_shadow_memslot+0x98/0xc0 > kvm_set_memslot+0x248/0xce0 > > Fix this by using kvm_phys_size() to determine the IPA size. This helper > is independent of the software page table representation and works > correctly for both protected and non-protected modes, as it derives the > size directly from VTCR_EL2. I'm a bit confused by the explanation. We have plenty of code that uses pgt->ia_bits outside of the NV code. And yet that code is not affected by this? I'm asking because NV is clearly a case where the pkvm_mappings aliasing is unambiguously *not* happening. Isn't the real issue that we are entering the NV handling code for any S2 manipulation irrespective of NV support? Would something like below help instead? Thanks, M. diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index cdeeb8f09e722..d03e9b71bf6cd 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -1101,6 +1101,9 @@ void kvm_nested_s2_wp(struct kvm *kvm) lockdep_assert_held_write(&kvm->mmu_lock); + if (!kvm->arch.nested_mmus_size) + return; + for (i = 0; i < kvm->arch.nested_mmus_size; i++) { struct kvm_s2_mmu *mmu = &kvm->arch.nested_mmus[i]; @@ -1117,6 +1120,9 @@ void kvm_nested_s2_unmap(struct kvm *kvm, bool may_block) lockdep_assert_held_write(&kvm->mmu_lock); + if (!kvm->arch.nested_mmus_size) + return; + for (i = 0; i < kvm->arch.nested_mmus_size; i++) { struct kvm_s2_mmu *mmu = &kvm->arch.nested_mmus[i]; @@ -1133,6 +1139,9 @@ void kvm_nested_s2_flush(struct kvm *kvm) lockdep_assert_held_write(&kvm->mmu_lock); + if (!kvm->arch.nested_mmus_size) + return; + for (i = 0; i < kvm->arch.nested_mmus_size; i++) { struct kvm_s2_mmu *mmu = &kvm->arch.nested_mmus[i]; @@ -1145,6 +1154,9 @@ void kvm_arch_flush_shadow_all(struct kvm *kvm) { int i; + if (!kvm->arch.nested_mmus_size) + return; + for (i = 0; i < kvm->arch.nested_mmus_size; i++) { struct kvm_s2_mmu *mmu = &kvm->arch.nested_mmus[i]; -- Without deviation from the norm, progress is not possible.