From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 759A5C982C1 for ; Wed, 16 Sep 2026 16:43:32 +0000 (UTC) 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-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=G5fdoWcd4IbAkK7p7KKtFU9jGsN4lvSTG0kjXK87Z/s=; b=zz1v83MnKR73lYMVgxHRfUxuoI oVE7zzzm9PF8VO57oyTQ4szhkO+a4yooa1h/Op1EktU8hJXiukRFLdH8h7IO3y1gUqp8deXF27Z0M da2/DukjPmoW2tj4LgHc428hZO8e8NKG9I0wAoRWwASy1cekUFNlkTrwWrKP/UP5q982FS9UGB/c1 UiuNznIhI86Kv5X6EreT9C+Wek+PNCosmAw66gOGwUw6lHzqGTuChZD6bcou5MddnVF9I2Y4PWTwC l08BqDvU6+NKEnWhSGrdfU/2BjBRD8+49ehbOub2krkfSavy7h0WMOqVpyvzeTOcesbUWj1VN5JHw DH9W3NUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x6sjE-00000009m0W-3iAz; Wed, 16 Sep 2026 16:43:24 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x6sjD-00000009m0F-2p7H for linux-arm-kernel@lists.infradead.org; Wed, 16 Sep 2026 16:43:23 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 1CBC8433A4; Wed, 16 Sep 2026 16:43:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F22271F0089F; Wed, 16 Sep 2026 16:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789577003; bh=G5fdoWcd4IbAkK7p7KKtFU9jGsN4lvSTG0kjXK87Z/s=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=og3EaWrjP8c7fsXDATC1SKvtJnQZOm079+ugLkbY/nxtak8GydZhXjNiHQh4izk1S OEdZu0no6ojvJzKlYaCjTo+uODYvNXNicXce1FBem5USIcbi5UoL1Lq8q4BY26W4h+ vi9S6qWyIuqYH5o/KOaL5pakpQ9iDn1kPgjdKZg1OYGweIae7DIX9QPAMwZ+BJ4X2y i7jkvUXB2IthoHvpvGPvYC/JAFEszLThLjj7PJaTksZF+vCSJjM18q0j3PQJR+u3fn kt6lOrDXIwHQW/AjDHFCGjA2907tj+tnP+PdCd8c6GDsRDnkBKHUqfouoKfjAmdLGO sv8qB16AoZFSw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x6sjA-00000009igi-3lRZ; Wed, 16 Sep 2026 16:43:21 +0000 Date: Wed, 16 Sep 2026 17:43:20 +0100 Message-ID: <868q515eqf.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, mark.rutland@arm.com, steven.price@arm.com, vdonnefort@google.com, qperret@google.com, tabba@google.com Subject: Re: [PATCH v3 16/18] KVM: arm64: Reject host power-on of a vCPU that EL2 holds powered off In-Reply-To: <20260914113338.159227-17-fuad.tabba@linux.dev> References: <20260914113338.159227-1-fuad.tabba@linux.dev> <20260914113338.159227-17-fuad.tabba@linux.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: fuad.tabba@linux.dev, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, mark.rutland@arm.com, steven.price@arm.com, vdonnefort@google.com, qperret@google.com, tabba@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 14 Sep 2026 12:33:36 +0100, Fuad Tabba wrote: > > A protected vCPU's power state belongs to EL2, which changes it only > on the guest's own PSCI calls. KVM_SET_MP_STATE(RUNNABLE) on a vCPU > EL2 holds powered off changes the host's copy alone, and the guest's > next CPU_ON of that vCPU then fails: mp_state is no longer STOPPED, so > the host returns ALREADY_ON, and the guest's retry fails the same way > until the VMM stops the vCPU again. SUSPENDED has the same effect. > > Track at the host whether EL2 holds a protected vCPU powered off and > return -EPERM for both writes in that state. STOPPED stays permitted, > so a VMM can pause a vCPU, and RUNNABLE on a vCPU EL2 has powered on, > so it can resume one. > > The guest's CPU_ON is gated on the same record rather than on STOPPED. > A VMM that sets STOPPED between the target's CPU_OFF exit and the > host's power-off of it would otherwise let the CPU_ON through, and the > power-off would then record the target powered off while EL2 holds it > ON_PENDING, with no way back before VM teardown. Gated on the record, > that CPU_ON returns ALREADY_ON and the retry succeeds once the > power-off has run. > > Signed-off-by: Fuad Tabba > --- > arch/arm64/include/asm/kvm_host.h | 2 ++ > arch/arm64/kvm/arm.c | 19 +++++++++++++++++++ > arch/arm64/kvm/pkvm.c | 21 +++++++++++++++++---- > arch/arm64/kvm/psci.c | 10 +++++++++- > 4 files changed, 47 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 37d0721d39a45..2e2c051dd8e62 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -922,6 +922,8 @@ struct kvm_vcpu_arch { > /* vcpu power state */ > struct kvm_mp_state mp_state; > spinlock_t mp_state_lock; > + /* EL2 holds the protected vCPU powered off. Under mp_state_lock. */ > + bool pkvm_powered_off; I'm definitely not keen on yet another random boolean to describe some new state. We already have mp_state. Why can't we use one of the unused encodings and check that, since it very much looks like a case of "let userspace change the MP_STATE unless EL2 says otherwise". Can that be made to work? M. -- Without deviation from the norm, progress is not possible.