From: Fuad Tabba <fuad.tabba@linux.dev>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Vincent Donnefort <vdonnefort@google.com>,
Fuad Tabba <tabba@google.com>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 1/3] KVM: arm64: Don't call kvm_setup_vcpu() again once a vCPU has run
Date: Mon, 30 Nov 2026 14:44:36 +0000 [thread overview]
Message-ID: <20261130144438.3176276-2-fuad.tabba@linux.dev> (raw)
In-Reply-To: <20261130144438.3176276-1-fuad.tabba@linux.dev>
KVM clears VCPU_INITIALIZED on a vCPU whose guest enters a disallowed
AArch32 mode, and the VMM can initialize it again. However, with the
flag clear, KVM_ARM_VCPU_INIT sets the vCPU up a second time with
kvm_setup_vcpu(), as if it never ran.
For a nested vCPU, if growing the nested MMU array fails in the second
setup, the error path frees the VNCR page. The virtual timer's offset,
CNTVOFF_EL2, is in that page, and the timer reads it from the freed
page the next time the vCPU is loaded:
BUG: KASAN: use-after-free in timer_restore_state (arch/arm64/kvm/arch_timer.c:642)
[...]
Call trace:
timer_restore_state (arch/arm64/kvm/arch_timer.c:642)
kvm_timer_vcpu_load (arch/arm64/kvm/arch_timer.c:910)
vhe_vcpu_load (arch/arm64/kvm/arm.c:764)
kvm_arch_vcpu_load (arch/arm64/kvm/arm.c:814)
vcpu_load (arch/arm64/kvm/../../../virt/kvm/kvm_main.c:179)
kvm_arch_vcpu_ioctl_run (arch/arm64/kvm/arm.c:1426)
kvm_vcpu_ioctl (arch/arm64/kvm/../../../virt/kvm/kvm_main.c:4575)
When the second setup succeeds, the vCPU is reset with the flag still
clear, and that reset overwrites what the VMM wrote to MPIDR_EL1 and
CLIDR_EL1, which KVM must reset only once.
Only set up an uninitialized vCPU that hasn't run. Reset one that has,
as for an initialized vCPU, and set VCPU_INITIALIZED before the reset
so that the two registers are kept.
Fixes: 469c4713d4802 ("KVM: arm64: nv: Allocate VNCR page when required")
Fixes: e016333745c70 ("KVM: arm64: Only reset vCPU-scoped feature ID regs once")
Cc: stable@vger.kernel.org
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/kvm/arm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 157bf4b812020..cfaaadd97233f 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1883,12 +1883,15 @@ static int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
if (ret)
return ret;
- if (!kvm_vcpu_initialized(vcpu))
+ /* A vCPU that has run is only reset even if it is no longer initialized. */
+ if (!kvm_vcpu_initialized(vcpu) && !vcpu_has_run_once(vcpu))
return __kvm_vcpu_set_target(vcpu, init);
if (kvm_vcpu_init_changed(vcpu, init))
return -EINVAL;
+ /* The reset keeps the vCPU-scoped ID registers only with the flag set. */
+ vcpu_set_flag(vcpu, VCPU_INITIALIZED);
kvm_reset_vcpu(vcpu);
return 0;
}
--
2.47.3
next prev parent reply other threads:[~2026-11-30 14:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 14:44 [PATCH 0/3] KVM: arm64: Fixes for a vCPU caught in a disallowed AArch32 mode Fuad Tabba
2026-11-30 14:44 ` Fuad Tabba [this message]
2026-11-30 14:44 ` [PATCH 2/3] KVM: arm64: Reject KVM_RUN on a vCPU that's no longer initialized Fuad Tabba
2026-11-30 14:55 ` sashiko-bot
2026-11-30 15:11 ` Fuad Tabba
2026-11-30 14:44 ` [PATCH 3/3] KVM: arm64: Don't run a protected vCPU that was caught in AArch32 Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130144438.3176276-2-fuad.tabba@linux.dev \
--to=fuad.tabba@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=vdonnefort@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.