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 35690606A31B for ; Tue, 27 Oct 2026 08:12:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=z//+WOYx; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=DO30WsaM 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=/dqcNV2rxcj+H+N6V1Q7pF0i14uOvWt3XmYVtpF0Vwo=; b=z//+WOYx1TwmIQ BwZ9Dsnt7dZzf3Irh8BzP0ZajvcBQvtl2WLM9sbP70CQ1UUBMsG9q7EU7om5bzF1rij4zy2gWw/QA FMgm46LJOJV5sU1yfm9OlmDJj4PuNls9HaULSoQPiu7/g1kV/YvlIZiBdxq72vgBWGdvxpmG4ZCQv U5uBL4T092hYwFIfSpxHTrI65WONvlpjYEcyPUJarxaGWnIRssVtdHY7tMRl4RLwM+zW1BhizSM/e tHGv1caqN1WOqJhnFZZubgePF6X+SEt20KBGsTy378hWcHyF/UC8beu+G2HE2AsSaLHdT36AyOOh+ NhQs3myLep2H3BoD0JnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLcHn-0000000402V-1fCH; Tue, 27 Oct 2026 08:11:59 +0000 Received: from out-47.mta1.migadu.com ([95.215.58.47] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLcHj-00000004011-2xNY for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2026 08:11:57 +0000 X-Envelope-To: linux-arm-kernel@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=hOfLyCvPxdoMK3iGT2snLIRtrBmcqixK3sf0MGFjqIg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793088713; v=1; x=1793693513; b=DO30WsaMONIhhJJccnNUyYpn4khrV8ieI51OrfrEkW/HFHx28z2V7fLZzG2F2d6r744ClNSn Mm7KG7Mev4TjbTFsh5dQRFd1uaLFAR6rVvWt6gIIMwK4Sc+ykyExsSKIjLm14EIxz+uuiP/GlFy 90ePGutgRkqRnnEsWKJGUY44= X-Envelope-To: linux-arm-kernel@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id da38054059dc04e0; Tue, 27 Oct 2026 08:11:53 +0000 X-Mizu-Trace-ID: da38054059dc04e0 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Vincent Donnefort , kernel-team@android.com, linux-kernel@vger.kernel.org, Oculytic , Fuad Tabba Subject: [PATCH 1/3] KVM: arm64: Synchronise kvm_host_data before host deprivileging Date: Tue, 27 Oct 2026 08:11:45 +0000 Message-ID: <20261027081147.498183-2-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261027081147.498183-1-fuad.tabba@linux.dev> References: <20261027081147.498183-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-20261027_011155_966634_3DA62C6C X-CRM114-Status: GOOD ( 12.14 ) 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 From: Vincent Donnefort When protected mode is enabled, the host is populating and reading the hypervisor copy of kvm_host_data until it is deprivileged. This is an issue for nr_event_counters which is only used by the host to populate mdcr_el2. After deprivileging, it is reading an uninitialised value and sets HPMN to 0, preventing programmable event counters from counting a non-protected guest. Before the host is entirely deprivileged, copy the entire kvm_host_data content from the hypervisor copy to the host-accessible one. Fixes: 2417218f2f23 ("KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts") Signed-off-by: Vincent Donnefort Signed-off-by: Fuad Tabba --- arch/arm64/kvm/pkvm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c index 380dfb1db0be4..58190ff6723d6 100644 --- a/arch/arm64/kvm/pkvm.c +++ b/arch/arm64/kvm/pkvm.c @@ -316,6 +316,12 @@ static void __init _kvm_host_prot_finalize(void *arg) { int *err = arg; + /* + * After __pkvm_prot_finalize, access to the hypervisor copy of + * kvm_host_data is lost. Save it into the host-accessible version. + */ + *this_cpu_ptr(&kvm_host_data) = *this_cpu_ptr_nvhe_sym(kvm_host_data); + if (WARN_ON(kvm_call_hyp_nvhe(__pkvm_prot_finalize))) WRITE_ONCE(*err, -EINVAL); } -- 2.47.3