From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDE2F606A31F for ; Sun, 6 Dec 2026 14:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Bmio2yD4; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ZSSTdeOd DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=8WSbhcnKbYRmj1ufS53m9yHIx/ryxM6w5MnXil91R0U=; b=Bmio2yD4twsHD9 1mu2HE79FDajFy6eWo3+QZz+/KPzNSxkzoN3Rd0lfVVm7GgzK5A82N/l6Culwzt+Y1c0z942CbDL7 QWbj5n7wMtfnTBqaqcKwhr6RK50AofDmfRB+5WGvrd1cj8YF43YQbhn5oV2VP4wCfo6+e9nE1kE8d N22r94g9e3qcH7zslJidd7pcTheBWzqvY2l+f/reigZscgdi8AeAW8HhFrC7IONsQrbSwhouCSGuI ZXHGwE5U+axijAFyAETitlKNYFFZBdDpE18058S50qV3ZYb4M6sFC2FdzBYvnlyNvfrAlUKp/2Oci H7CpQxCUAvuvC/VtYyfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaD4C-00000003ePs-2SMw; Sun, 06 Dec 2026 14:18:16 +0000 Received: from out-234.mta1.migadu.com ([2001:41d0:203:375::ea] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaD48-00000003ePQ-15sE for linux-arm-kernel@lists.infradead.org; Sun, 06 Dec 2026 14:18:15 +0000 X-Envelope-To: linux-arm-kernel@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=IOFx2xOrO5QC3gt/cI/MmCSdcDX0gn/kmX6ZpHvpn5M=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796566687; v=1; x=1797171487; b=ZSSTdeOdRWTQy/Tp8Ob6YF4ZRBmGOx8Gyc6PatOXpzudJyXhi+Elnp8bOcllNjBDDK5QOUF6 54HgQgcYpc4cSulCvABlHzVvbk4AcUwUEM5Kw3WNI/h8MRf4OovgoAWl9K2CzRBAqBHh22GzCUD PnKKe4CtDkXQNmZsGO+OCZZg= X-Envelope-To: linux-arm-kernel@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id 0221ef282658f637; Sun, 06 Dec 2026 14:18:06 +0000 X-Mizu-Trace-ID: 0221ef282658f637 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Xuheng Li Cc: Marc Zyngier , Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Fuad Tabba Subject: Re: [PATCH] KVM: arm64: pkvm: Roll back only the caller's own CPU_ON Date: Sun, 6 Dec 2026 14:18:01 +0000 Message-ID: <20261206141801.1947386-1-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261204-pkvm-cpu-on-rollback-v1-1-958da5cb7337@cs.columbia.edu> References: <20261204-pkvm-cpu-on-rollback-v1-1-958da5cb7337@cs.columbia.edu> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261206_061812_861846_C0336FC6 X-CRM114-Status: GOOD ( 18.92 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Xuheng, On Fri, 04 Dec 2026 20:08:27 +0000, Xuheng Li 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 Reviewed-by: Fuad Tabba 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 > 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