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 2544226D4C1; Mon, 1 Sep 2025 12:24:10 +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=1756729451; cv=none; b=AiANzeNXqpWPuauRWygbACp01BZX6bKI/lG7oVsX731Ka9ytlg8AX7YiPOu2WQcxosYuOt/CelNCDsFIx1ns35+tUl//vsnF7NeLgpp91985j5C1cHcGsuHIdsU5fp9DpkcZoiaIUY4k1iicKHBe6I3xUBIWfcaVYozs7qHb5jE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756729451; c=relaxed/simple; bh=1y1C3r+YYCBCldCQKr3GO6JKvPpDZX9+NRK0YMyqE/c=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=YzzTIj9c2uwwP0HOGiDRP2kUYidQlgxNGFw2x21Zx9GXgbPS+BldFKJhhoUsFpEfyJXiIxUiWZXoAsDsrU4mLpxS0TM2L+Okq5xApVBfezQ6R3vBCs/3SMXaU73ogbH+PvkBKLK8FtBytgH+/Jx4Vxz2fEszea+MJgQ3eLwW/nU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bMqtVR+p; 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="bMqtVR+p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94EFEC4CEF0; Mon, 1 Sep 2025 12:24:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756729450; bh=1y1C3r+YYCBCldCQKr3GO6JKvPpDZX9+NRK0YMyqE/c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bMqtVR+pnPwQGrofgqUly/HRw5+is5i33ASvrU3eqrSUaY6VndIg6J/zUi2HTccUP Cs8Bp01Iobubz67QuN8CXqUXAs8ycsuVmHHl3FnGnT1c4ugIsE4YW7BFI2A2DXMHJZ r7LRwHFY9vG53RqA6aSDJ0HlafWV1ydatN5yQdY1edikeBePJa8qLwvK4Z8nTa0/Q5 ntTTnaDB1gS9b6YpI8Nc5zg+KXI5ltrn3VKvNMFLvn4EtE2LHsKjWPD7HTX8lHZSPW CBcMn/nbXMnBhQuswnFHP7NAjbLe+hnU3AgPOxLUQVH2bjyah0xXSHUepJg75VxuNi REe1eNB40fadA== 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 1ut3Zw-00000002F4D-0jUI; Mon, 01 Sep 2025 12:24:08 +0000 Date: Mon, 01 Sep 2025 13:24:07 +0100 Message-ID: <863496e4yg.wl-maz@kernel.org> From: Marc Zyngier To: James Clark Cc: Yingchao Deng , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, quic_yingdeng@quicinc.com, jinlong.mao@oss.qualcomm.com, tingwei.zhang@oss.qualcomm.com, Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon Subject: Re: [PATCH] KVM: arm64: Fix NULL pointer access issue In-Reply-To: <450f11c2-6c11-4ffa-ae20-db4ea419a3ca@linaro.org> References: <20250901-etm_crash-v1-1-ce65e44c137c@oss.qualcomm.com> <450f11c2-6c11-4ffa-ae20-db4ea419a3ca@linaro.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: linux-kernel@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: james.clark@linaro.org, yingchao.deng@oss.qualcomm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, quic_yingdeng@quicinc.com, jinlong.mao@oss.qualcomm.com, tingwei.zhang@oss.qualcomm.com, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 01 Sep 2025 11:36:11 +0100, James Clark wrote: > > > > On 01/09/2025 11:01 am, Yingchao Deng wrote: > > When linux is booted in EL1, macro "host_data_ptr()" is a wrapper that > > resolves to "&per_cpu_ptr_nvhe_sym(kvm_host_data, cpu)", > > is_hyp_mode_available() return false during kvm_arm_init, the per-CPU base > > pointer __kvm_nvhe_kvm_arm_hyp_percpu_base[cpu] remains uninitialized. > > Consequently, any access via per_cpu_ptr_nvhe_sym(kvm_host_data, cpu) > > will result in a NULL pointer. > > > > Add is_kvm_arm_initialised() condition check to ensure that kvm_arm_init > > completes all necessary initialization steps, including init_hyp_mode. > > > > Fixes: 054b88391bbe2 ("KVM: arm64: Support trace filtering for guests") > > Signed-off-by: Yingchao Deng > > --- > > Add a check to prevent accessing uninitialized per-CPU data. > > --- > > arch/arm64/kvm/debug.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c > > index 381382c19fe4741980c79b08bbdab6a1bcd825ad..add58056297293b4eb337028773b1b018ecc9d35 100644 > > --- a/arch/arm64/kvm/debug.c > > +++ b/arch/arm64/kvm/debug.c > > @@ -233,7 +233,7 @@ void kvm_debug_handle_oslar(struct kvm_vcpu *vcpu, u64 val) > > void kvm_enable_trbe(void) > > { > > if (has_vhe() || is_protected_kvm_enabled() || > > - WARN_ON_ONCE(preemptible())) > > + WARN_ON_ONCE(preemptible()) || !is_kvm_arm_initialised()) > > Hi Yingchao, > > There shouldn't be a warning for this, at least for the case where > it's not initialized and never will be. If you're never going to run a > guest these functions can all skip, the same way for !has_vhe() etc. It's not a warning. It's a bona-fide crash: void kvm_enable_trbe(void) { if (has_vhe() || is_protected_kvm_enabled() || WARN_ON_ONCE(preemptible())) return; host_data_set_flag(TRBE_ENABLED); <--- Explodes here } So the write of the flag has to be skipped if KVM is available, even if KVM is compiled in. M. -- Without deviation from the norm, progress is not possible.