From: Fuad Tabba <fuad.tabba@linux.dev>
To: Xuheng Li <xuheng@cs.columbia.edu>
Cc: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
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>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
Fuad Tabba <tabba@google.com>
Subject: Re: [PATCH] KVM: arm64: pkvm: Roll back only the caller's own CPU_ON
Date: Sun, 6 Dec 2026 14:18:01 +0000 [thread overview]
Message-ID: <20261206141801.1947386-1-fuad.tabba@linux.dev> (raw)
In-Reply-To: <20261204-pkvm-cpu-on-rollback-v1-1-958da5cb7337@cs.columbia.edu>
Hi Xuheng,
On Fri, 04 Dec 2026 20:08:27 +0000, Xuheng Li <xuheng@cs.columbia.edu> wrote:
> When the host answers a protected vCPU's forwarded PSCI CPU_ON with a
> failure, handle_pvm_entry_hvc64() rolls the target back by moving its
> power_state from ON_PENDING to OFF. ON_PENDING does not say whose CPU_ON
> made it so. Between the forward and the caller's next entry the target
> can run, power itself off, and be targeted by another vCPU's CPU_ON. The
> rollback then cancels that other CPU_ON:
>
> vCPU i vCPU j target t
> CPU_ON(t): OFF ->
> ON_PENDING, publish;
> the host fails it but
> runs t anyway
> reset, ON, ..., CPU_OFF
> CPU_ON(t): OFF ->
> ON_PENDING
> re-entry: rollback
> ON_PENDING -> OFF
> publish pc/r0; SUCCESS
>
> i's caller is told INTERNAL_FAILURE although t ran its CPU_ON, and j's
> caller is told SUCCESS, but t stays OFF and never runs j's entry point.
> As the rollback leaves reset_state.reset set, the next CPU_ON of t can
> also boot it from j's pc/r0, or from a mix of j's and its own values if
> t's reset runs before that CPU_ON has written them.
>
> Only a host that fails a forwarded CPU_ON yet runs its target can set
> this up, but that is exactly the case to defend against: pKVM does not
> trust the host, and a protected guest must be able to rely on the PSCI
> results and power-on semantics that EL2 gives it, whatever the host
> does with its scheduling or its return values.
>
> Keep the protocol in power_state. An ON_PENDING value now also carries
> its caller (vcpu_idx + 1, or 0 for the first run) and a PUBLISHED bit:
> pvm_psci_vcpu_on() moves OFF to its own pending value, writes
> reset_state, and publishes with a release of the published value; the
> rollback moves only its own published value back to OFF; and
> pkvm_reset_vcpu() resets only a published ON_PENDING, with an acquire
> cmpxchg from the value it read, so the reset_state it reads is the one
> that value published. reset_state.reset is no longer used at EL2.
>
> The caller tag only fits for vcpu_idx below 2^23, so __pkvm_init_vm()
> now also rejects a VM with more than KVM_MAX_VCPUS vCPUs, which the host
> never creates. Without that bound, a host could create a VM in which two
> vCPUs share a tag.
>
> Fixes: 872383bd12e1 ("KVM: arm64: Add per-EC entry/exit state marshalling for protected guests")
> Signed-off-by: Xuheng Li <xuheng@cs.columbia.edu>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Tested on QEMU with a protected guest, with CPU hotplug and with a
test-only host change that fails CPU_ON before or after it wakes the
target:
Tested-by: Fuad Tabba <fuad.tabba@linux.dev>
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
[...]
> @@ -479,8 +478,9 @@ static int pkvm_vcpu_init_psci(struct pkvm_hyp_vcpu *hyp_vcpu, u32 mp_state)
> host_vcpu = hyp_vcpu->host_vcpu;
> reset_state->pc = READ_ONCE(*vcpu_pc(host_vcpu));
> reset_state->r0 = READ_ONCE(vcpu_gp_regs(host_vcpu)[0]);
> - reset_state->reset = true;
> - hyp_vcpu->power_state = PSCI_0_2_AFFINITY_LEVEL_ON_PENDING;
> + /* The first run: published, with no caller to roll it back. */
> + hyp_vcpu->power_state = PSCI_0_2_AFFINITY_LEVEL_ON_PENDING |
> + PKVM_POWER_PUBLISHED;
nit: this assignment fits on one line.
Cheers,
/fuad
prev parent reply other threads:[~2026-12-06 14:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 20:08 [PATCH] KVM: arm64: pkvm: Roll back only the caller's own CPU_ON Xuheng Li via B4 Relay
2026-12-06 14:18 ` Fuad Tabba [this message]
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=20261206141801.1947386-1-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=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=will@kernel.org \
--cc=xuheng@cs.columbia.edu \
--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