From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377126; b=szOu4bvRMnzwvotIkAJUUZ5e0Zx+Wswrqoj6cl2YjGc5In453qApjuip6h1qPLNcQawe jG/LkcMziEmy+CLVMfdhrnhGc1cpcIUqQEs8sr+MZJ/G+KBh2HZ4afbmfKcy3gEDAwFFH 5XLUcRFhd3eKLOgX7d3frDQ4deTtzYLM/RnxA5sPHvYRvY1SN77rzDsGqdeGrW5TN72Od pQvCr6MBLzSFIIzBxA4478QV6BNMLE/GevBcCT35bB1LmFf+/fNgB/Jc/hiZI6nIpV57O tzSDCSR0pMnZR1qPHV5yRl1ZOdYnCeyPmi4Kw6QS0+F0PT/TSqPZVvth6wZja7t0j1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377126; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Fmb3k8+l6HU5/lrYpGJsi0qKU5bXAuhBv6xNjGiKyUw=; b=dx8BFkeoS8kWqi4hv5S+sUUrJ8+U3jsiAGYFhAomzeYbhD57M1pLunSMy/H5X1UX72Le dDspjQJTQDqXQ5eSfYx/uvtfD45w+cJ4hfDO3QQ5dMBX1HWRXf5053gW1KEvXm2je/Zd0 7xo1u8MOgt+FKf6Ic2SVjbPpePCPtsobbX9fF4FtR/vELQv7JFS2w07wS/fi42xAH4Pjj BPgyjLu2FlQocAguMWqQp7764EyDoZ4Ob4pHvvaqn4E5iM45dNVuYXiSyen1+gXBCcBad nbSb7BHNKdTzTrTPJ/SYEmzWfkP744001ddMBfGOuyjDTPpAtL1iXrYLcrHJhgvlwEg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Eunja/Ak"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0648B606A322; Fri, 4 Dec 2026 09:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Eunja/Ak Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4DA71F000C2; Fri, 4 Dec 2026 09:38:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796377125; bh=Fmb3k8+l6HU5/lrYpGJsi0qKU5bXAuhBv6xNjGiKyUw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Eunja/Ak5V3ZQIhfTkXjYgwVXpiyorRqDaMglNplePhzIt1asfTJoM9Z4XpJ97Kwi VNMtwg5XXN3VYCzEDFA4+P5+5FFTHrt80Xm2ZpJqsJZl4pAH7qiAZfk599jn471503 mSYfypJi36daxmay5Yizyd1lmx+gKcx+jOfTGfGfVkqxzZT/ey2IW/P9yJz3m8mBOa QjlpvwXVuKnN2EBASK2G1InUS+EzlWyy6OgbQWOTuXc8DMBRfI1FtJ+Xwn2gdd7nBH syQNNg24ENaQqTUo5DAdU5RueAVnGglpXKNzokI0PB/nQovLC1Vxz+65Db1d2FmNXx DtIv5GHQhBBTw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 1/2] KVM: arm64: Don't load hardware vCPU state before first run Reply-To: sashiko-reviews@lists.linux.dev To: "Jia He" Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, "Oliver Upton" , "Marc Zyngier" In-Reply-To: <20261204090914.459990-2-justin.he@arm.com> References: <20261204090914.459990-1-justin.he@arm.com> <20261204090914.459990-2-justin.he@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 09:38:45 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] KVM: arm64: kvm_inject_nested() leaks VHE PMU state before first KVM_RUN -- commit f447e42779fe8bcecaa4f6aa6298f73ee8e89cf9 Author: Jia He KVM: arm64: Don't load hardware vCPU state before first run This commit skips the arch vcpu_load() and vcpu_put() callbacks until vcpu_has_run_once() is true, and updates VHE's enter_vmid_context() to check host_ctxt->__hyp_running_vcpu instead of kvm_get_running_vcpu(). > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 157bf4b812020..720367868f6c8 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c [ ... ] > @@ -862,8 +872,11 @@ static void pkvm_vcpu_put(struct kvm_vcpu *vcpu) > =20 > void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) > { > - vcpu->arch.vcpu_ops->vcpu_put(vcpu); > - vcpu_clear_on_unsupported_cpu(vcpu); > + if (likely(vcpu_has_run_once(vcpu))) { > + vcpu->arch.vcpu_ops->vcpu_put(vcpu); > + vcpu_clear_on_unsupported_cpu(vcpu); > + } > + > vcpu->cpu =3D -1; > } [Severity: High] Can skipping vcpu_ops->vcpu_put() here leak VHE PMU EL0 counter filtering on the host CPU when KVM_SET_VCPU_EVENTS injects a nested exception before the first KVM_RUN? When KVM_SET_VCPU_EVENTS injects a nested SError (e.g. from L2 EL1h with HCR_EL2.AMO and the cycle counter enabled in PMCNTENSET_EL0), kvm_inject_nested() still calls kvm_pmu_nested_transition() unconditionally whenever kvm_vcpu_has_pmu(vcpu) is true. kvm_pmu_nested_transition() calls kvm_pmu_create_perf_event() and kvm_vcpu_pmu_restore_guest(), modifying the physical VHE PMU EL0 filter registers. Because kvm_arch_vcpu_put() now skips vcpu_ops->vcpu_put() and kvm_vcpu_pmu_restore_host(), host EL0 PMU filtering is never restored. In addition, kvm_pmu_create_perf_event() runs before kvm_arm_pmu_v3_init() initializes vcpu->arch.pmu.overflow_work, so an NMI overflow on the leaked event makes kvm_pmu_perf_overflow() queue an uninitialized irq_work and trigger a NULL pointer dereference in irq_work_single(). Guarding kvm_pmu_nested_transition() on vcpu_has_run_once(vcpu) would avoid touching PMU hardware or creating perf events before the first KVM_RUN. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204090914.4599= 90-1-justin.he@arm.com?part=3D1