From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796220125; b=hUEAtRd9ggAhbyCXSzr4eKyFTy+6AE4L4HRwCWXlHQiA52UJEr919C1PEre5cVTsAcVI NH0eNMATaFx7P3Lm7u4BeXXXMJyLKlPKJh0pSN65BiMfDYS3BENOM1DqBcm+h7swIyP/3 oXitt0i/iS7o6iZJ/JTOZ8Fvj95LtqEPHBMyKgkDMbPigXDufW5qorvW2Miz41cOWHS+5 Fw3GulXf/VSBUUxin1UnWTHMAB4gZaUJ/v7vlRlDDkBQIOYyBS8VaF01sabuZDmaekmQx SLJj8ah+PuK/1XT4eZVEPVuO24/JFs7d1vP/dAaso+7MnvaPsLcRQFL8UO7EbwFo3SQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796220125; h=Received:DKIM-Signature:Received:Date:Message-ID:From:To:Cc:Subject: In-Reply-To:References:User-Agent:MIME-Version:Content-Type: X-SA-Exim-Connect-IP:X-SA-Exim-Rcpt-To:X-SA-Exim-Mail-From: X-SA-Exim-Scanned; bh=7B5Umb/t/Piaq1jlfE9Tt+OPkkQEYbdNfxjaQZzC55k=; b=EVopgJ0L7duuJOfRj89lFGdfJMImXzhWwwtPsiape6b3CpOVqoQ9p6QYyOINubrBLS75 F+zYIfKHNaXQqGNJNgaFExDbAWZEBhxyQ+1t0yfLKM1+cZsP+CL7gtHFIfTQFicG1bQX9 H0cAy7pydGHEzeJsPE74VxxL0QIC335Np0xi9xQAZOLs2rzDy6dwyKA9HnqXJaoUhxWh4 uTtlE8B8SNeTrd8qQZDF7EL8Q/l5OBZdMgpuj9T7pulkxqFx92/suJT+DS0z6eJCenihr B8rVsyyJQpxDKDnEOKvcoYWzwm1WQ48idsRqV9BWDITS7+igKmyzD6zBSgWf644/QKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Nniy/gH2"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B684606A329; Wed, 2 Dec 2026 14:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Nniy/gH2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C18E81F000C1; Wed, 2 Dec 2026 14:02:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796220124; bh=7B5Umb/t/Piaq1jlfE9Tt+OPkkQEYbdNfxjaQZzC55k=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=Nniy/gH2UIYU9BIbGAnRcodGZtCvdJUFRVA2/dqYvZlkNkzhWHBNhHD7h03EzKa83 zemqAedG4ZWMtyTCRbxvsyvzzGX+z65wfByIvE+8TNcgD5IbTuZyk5kgtmpT2wGU1r T3lvZ+rx1Wxa//gC6IkhMfBYZ72Of70QPBRENo23jSrWaE0A3l0wcQL/j1ZAHQd6/+ 3xXR+bDGHVm4Z2Okd2ZqH2lwBdQb5hCZgizP6HY4+ZIrsSE7wQ2+AnhMgbjbDumBG1 Tpr0Xdvd2sZ/I1qzWnvg18iq3Ny8L7AwFSW3mpJR2LWseuXF7jaysz9q+R0NdTkCg9 mU7bmjBcnTbIw== 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 1xYkuI-000000068bZ-2wFf; Wed, 02 Dec 2026 14:02:02 +0000 Date: Wed, 02 Dec 2026 14:02:02 +0000 Message-ID: <86bj73ye5h.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Vincent Donnefort , Fuad Tabba , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] KVM: arm64: Don't run a protected vCPU that was caught in AArch32 In-Reply-To: <20261130144438.3176276-4-fuad.tabba@linux.dev> References: <20261130144438.3176276-1-fuad.tabba@linux.dev> <20261130144438.3176276-4-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) X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, vdonnefort@google.com, tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 30 Nov 2026 14:44:38 +0000, Fuad Tabba wrote: > > When a protected vCPU exits to EL2 in AArch32, EL2 fails the run and > clears VCPU_INITIALIZED on its copy of the vCPU to make the vCPU > invalid, but EL2 never reads that flag. The host's copy of the flag > remains set, so the next KVM_RUN runs the vCPU again. > > Don't run a vCPU whose flag EL2 has cleared. pkvm_filter_vcpu_ioctl() > rejects KVM_ARM_VCPU_INIT for a protected vCPU that has run, so reword > the comment in fixup_guest_exit(). > > Fixes: be66e67f17509 ("KVM: arm64: Use the pKVM hyp vCPU structure in handle___kvm_vcpu_run()") > Signed-off-by: Fuad Tabba > --- > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 4 ++++ > arch/arm64/kvm/hyp/nvhe/switch.c | 7 +++---- > 2 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > index 179d7c8277b88..19509d460e06e 100644 > --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > @@ -924,6 +924,10 @@ DEFINE_KVM_HOST_HCALL(int, __kvm_vcpu_run, struct kvm_vcpu __kern *, vcpu) > if (unlikely(system_supports_sme() && read_sysreg_s(SYS_SVCR))) > return ret; > > + /* Cleared by fixup_guest_exit() for a protected vCPU caught in AArch32. */ > + if (unlikely(!kvm_vcpu_initialized(&hyp_vcpu->vcpu))) > + return ret; > + > /* > * ON has a single writer, pkvm_reset_vcpu() on this CPU, so > * READ_ONCE suffices. ON_PENDING takes the reset; -ECANCELED > diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c > index 89fb9dd351ad5..b69295f8c122d 100644 > --- a/arch/arm64/kvm/hyp/nvhe/switch.c > +++ b/arch/arm64/kvm/hyp/nvhe/switch.c > @@ -262,10 +262,9 @@ static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) > if (unlikely(vcpu_is_protected(vcpu) && vcpu_mode_is_32bit(vcpu))) { > /* > * As we have caught the guest red-handed, decide that it isn't > - * fit for purpose anymore by making the vcpu invalid. The VMM > - * can try and fix it by re-initializing the vcpu with > - * KVM_ARM_VCPU_INIT, however, this is likely not possible for > - * protected VMs. > + * fit for purpose anymore by making the vcpu invalid. EL2 > + * can't run it again, and a protected vcpu that has run > + * can't be re-initialized with KVM_ARM_VCPU_INIT. > */ > vcpu_clear_flag(vcpu, VCPU_INITIALIZED); > *exit_code &= BIT(ARM_EXIT_WITH_SERROR_BIT); This is yet another weird difference in behaviour that is visible from userspace. Also, once a vcpu is "unrunnable", the whole guest is pretty much dead (I can't see how it is going to recover from a vcpu being gone). I wonder if we should promote the "red-handed" behaviour to being a case of kvm_vm_dead(). This would solve all our problems once and for all. The other solution is of course to wipe AArch32 support altogether. M. (tempted...) -- Without deviation from the norm, progress is not possible.