From: Joey Gouly <joey.gouly@arm.com>
To: Marc Zyngier <maz@kernel.org>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oupton@kernel.org>,
Zenghui Yu <yuzenghui@huawei.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] KVM: arm64: Discard PC update state on vcpu reset
Date: Fri, 13 Mar 2026 14:30:19 +0000 [thread overview]
Message-ID: <20260313143019.GA3369094@e124191.cambridge.arm.com> (raw)
In-Reply-To: <20260312140850.822968-1-maz@kernel.org>
On Thu, Mar 12, 2026 at 02:08:50PM +0000, Marc Zyngier wrote:
> Our vcpu reset suffers from a particularly interesting flaw, as it
> does not correctly deal with state that will have an effect on the
> execution flow out of reset.
>
> Take the following completely random example, never seen in the wild
> and that never resulted in a couple of sleepless nights: /s
>
> - vcpu-A issues a PSCI_CPU_OFF using the SMC conduit
>
> - SMC being a trapped instruction (as opposed to HVC which is always
> normally executed), we annotate the vcpu as needing to skip the
> next instruction, which is the SMC itself
>
> - vcpu-A is now safely off
>
> - vcpu-B issues a PSCI_CPU_ON for vcpu-A, providing a starting PC
>
> - vcpu-A gets reset, get the new PC, and is sent on its merry way
>
> - right at the point of entering the guest, we notice that a PC
> increment is pending (remember the earlier SMC?)
>
> - vcpu-A skips its first instruction...
>
> What could possibly go wrong?
>
> Well, I'm glad you asked. For pKVM as a NV guest, that first instruction
> is extremely significant, as it indicates whether the CPU is booting
> or resuming. Having skipped that instruction, nothing makes any sense
> anymore, and CPU hotplugging fails.
Would the normal method of offlining/onlining via sysfs also be affected?
>
> This is all caused by the decoupling of PC update from the handling
> of an exception that triggers such update, making it non-obvious
> what affects what when.
>
> Fix this train wreck by discarding all the PC-affecting state on
> vcpu reset.
Good job on tracking it down.. makes you wonder why the DSB "fixed" things!
>
> Fixes: f5e30680616ab ("KVM: arm64: Move __adjust_pc out of line")
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Cc: stable@vger.kernel.org
> ---
> arch/arm64/kvm/reset.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
> index 959532422d3a3..b963fd975aaca 100644
> --- a/arch/arm64/kvm/reset.c
> +++ b/arch/arm64/kvm/reset.c
> @@ -247,6 +247,20 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
> kvm_vcpu_set_be(vcpu);
>
> *vcpu_pc(vcpu) = target_pc;
> +
> + /*
> + * We may come from a state where either a PC update was
> + * pending (SMC call resulting in PC being increpented to
incremented
> + * skip the SMC) or a pending exception. Make sure we get
> + * rid of all that, as this cannot be valid out of reset.
> + *
> + * Note that clearing the exception mask also clears PC
> + * updates, but that's an implementation detail, and we
> + * really want to make it explicit.
> + */
> + vcpu_clear_flag(vcpu, PENDING_EXCEPTION);
> + vcpu_clear_flag(vcpu, EXCEPT_MASK);
> + vcpu_clear_flag(vcpu, INCREMENT_PC);
> vcpu_set_reg(vcpu, 0, reset_state.r0);
> }
>
Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Thanks,
Joey
next prev parent reply other threads:[~2026-03-13 14:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 14:08 [PATCH] KVM: arm64: Discard PC update state on vcpu reset Marc Zyngier
2026-03-13 14:30 ` Joey Gouly [this message]
2026-03-15 15:08 ` Marc Zyngier
2026-03-13 16:16 ` Suzuki K Poulose
2026-03-15 15:11 ` Marc Zyngier
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=20260313143019.GA3369094@e124191.cambridge.arm.com \
--to=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox