From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64F6A36B05C; Mon, 2 Feb 2026 15:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770044653; cv=none; b=hBTffv2Nb5AsDRW/JvYbLmfCPk900kFkQQyL0kM5qf32ZAUHnW3kjYT1I1pJMDksmn8HxAShFJ02Y7W1qZuLWID4qfj0J1QamsDFiYZB83L5mz9c0plC+E2InQaF4vCPJjSok1Y1CV/mBlkJofMFho3tMdJOwS6nNZcqUy9FuTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770044653; c=relaxed/simple; bh=eZckfXnFrLIaGFGKygaD5J/uv8VG0UUKhlpbe4BDf3E=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=hRt+y4JS+GuTP0O2jsxQyDzu3JBModlXN/BnWMSGm4UU+rgfv5Rt6lbFj8sopQDq7jKkt6K1cQFaFYOAr0M5QCwz/w6szO3CEtzvtMsOLvCv1BOZBmxMuyPjH2wxM57XxW+iw5VZDuhesjOe7GdR1c+ZwA4uwrxbK96A1KR0ri4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E1nCgQpr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E1nCgQpr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 365EAC116C6; Mon, 2 Feb 2026 15:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770044653; bh=eZckfXnFrLIaGFGKygaD5J/uv8VG0UUKhlpbe4BDf3E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=E1nCgQprrMLG2nBQUWDgwmFySozjaH4hgmvcRiBPi7jDWWdBY/7GgvyaCRzbbWXMr z9oH0r6Ij5JOJsMC9FAfEqCeQUVqna6d8dIZgWgBMHR+LpbpCHVuHf4ZfRW8JecyIW d2m0qExy0cYlklmAByd54m3L9/cGkn+R3f1ca7QCn6WFBFWXDL/GAiOSuay0WT4Ykr 3WGq48O1ZUr4pumHvGlSWulGRiz6MopJg0rFa3tXm4TYkYpQnWy4xUPdHUyOSiY6Ra Hw+UZjAFo9hTwmIymHRZ7oC/bOtzJa+5Z1r710j0bo7aqG/rgY2Lm0FxZzlR+SZSUD Tunu+K5HVbepQ== 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 1vmvTG-00000007oX3-3Dla; Mon, 02 Feb 2026 15:04:10 +0000 Date: Mon, 02 Feb 2026 15:04:10 +0000 Message-ID: <86sebj9ogl.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: References: <20260202130513.49436-1-tabba@google.com> <86tsvz9pbg.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) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 On Mon, 02 Feb 2026 14:54:55 +0000, Fuad Tabba wrote: > > Hi Marc, > > On Mon, 2 Feb 2026 at 14:45, Marc Zyngier wrote: > > > > 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? > > That would definitely work (just tested it). I just assumed that the > code is there in case in the future we want to support nv + pkvm.... > Although, I chuckled a bit as I was writing those words :) Don't laugh, I seriously considered what it would take to teach NV to the RMM, just as a way to get rid of the ridiculous notion of planes (which is exactly like NV, only done in a way that is even worse than the architected version, so even more costly for no good reason). > I was going to ask if you'd like me to respin, but this is a > completely different patch. Would you like me to write it up and > send it (my contribution would be the commit msg)? Yes please, it's a lot less effort for me! :p Thanks, M. -- Without deviation from the norm, progress is not possible.