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 8101C606A325 for ; Mon, 30 Nov 2026 14:45:32 +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=lIrDmmR0; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=bHrYnq+p 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=AQB9wvgms8LvyTN8VI7p6uv2E6uY901LwtAWj6AZD/s=; b=lIrDmmR0GZlKg/ TDmFAyLQPf5kyXXYB95bgzcwnfK1MtgU+e4wRql2Ht2FFLjg+gNvDhJ45iwmFJ8PJx42OuyDjxP2s auqVN9N8dQu1KeqdugaitUW8g3AjWdfEKAPruqZT/Hkj95GP718Zr6XD6cg1/tv3t6wrOlJMLBPgg IcewWFZt2S+Qmabu8zDgs2tvdiiqekCoWwrUjOr6aZkSv1XMNEXi+RcqR6N8071QoRAHbRSiIrs/r w3N9RxnanLZcr6ulEZeR7P3mf7h75m/2CbMxaWC8EVeRNKydkVC1qNIbE2dtImMik6QLH2ew8JQjx 8/jKU2ameyJk2y5tZW9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY2cn-00000004wBa-2Xil; Mon, 30 Nov 2026 14:45:01 +0000 Received: from out-170.mta1.migadu.com ([2001:41d0:203:375::aa] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY2ch-00000004w8r-2yFk for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 14:44:58 +0000 X-Envelope-To: linux-arm-kernel@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=oeIgjs+yyViHvM0NutvhCsjXCGtyx4iAL/JM+mjzYq4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796049893; v=1; x=1796654693; b=bHrYnq+plWTqzC28kjQ9C+LyMrmQfprZS0ZcgxP7YKAc5s0hW25uDvd9jdyQnE7UUXy7BKoI AuzDhCkzPRmH1jVrJYPLx68A4uTzdIDV99Dnbovt0cdyB4uBxLb4+m4xEZhXUyLC4sxxzfwNsrG XNtMwPQL+OWYM5nAANRHjLiI= X-Envelope-To: linux-arm-kernel@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id f9c6d3c09d104fca; Mon, 30 Nov 2026 14:44:53 +0000 X-Mizu-Trace-ID: f9c6d3c09d104fca X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Marc Zyngier , Oliver Upton Cc: 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: [PATCH 3/3] KVM: arm64: Don't run a protected vCPU that was caught in AArch32 Date: Mon, 30 Nov 2026 14:44:38 +0000 Message-ID: <20261130144438.3176276-4-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130144438.3176276-1-fuad.tabba@linux.dev> References: <20261130144438.3176276-1-fuad.tabba@linux.dev> 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-20261130_064457_121307_3CC271C1 X-CRM114-Status: GOOD ( 13.84 ) X-Spam-Score: -2.8 (--) 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=-18.9 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 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); -- 2.47.3