From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793088717; b=ABY9eINjH/Ix8jBv1qXacKqwrU47nczZELOHUwdAMTKtQHBF92nUvhYNh9rywVWjk6yo lw9YDzT3mVVQc3XfHiYUu1S2/ujnqWGLglXNIOJbR59lSEPzh2K9Fi9DCyfjfD5WGLDgT jQw6EFvDGe+cz4VQ4z3N7dhuwYK1TP1PRn7FsAfpnPWaSVTWEE+iYp4wuTXw7/ybqA8uz eKThCUenQgLckIhVHxL94+yIVhI4BRrOqWxFXr7s308BRtHF6Dgsf6/Wx1rDMxnWytPaw ko/V9/wKARtS134lUU7PhzT+4RAIs2H4e5sZOyICQbvi3zhXkH7ji+vR+JEM8JdO3fA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793088717; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=/dqcNV2rxcj+H+N6V1Q7pF0i14uOvWt3XmYVtpF0Vwo=; b=S/9xtORDP38eWRcsi28vFGNSPXfX7Zs6v1QKpVpDm7xZ4HeLlegDTk0LydG2wJ93CCJB ruOQEyYs/yhSzm2IXpxiVym3dVznUhuWdjnULsnvCrwtHUaq8vSlyQGyLQ0nc1Nw41G0I owOYgg5bDWwpoeM+5nzMTlJoDkJ5RUXeOm+YNepmbL8xBToXhSmQ0GanjSg5laSwUYiUW L2KGNmmtBHgBXL9jVN2Py5W96I1OGr3Bb/rf9t5SVABRyEZCZFnD6ydfNzO9l9qLUxiTg ji4EL7ogewRr4wyyeQxwH2qNjMncBS2ftgnAdTuF6mt1GcE6FoWexJfB50AbtNyLB4Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=DO30WsaM; arc=none smtp.remote-ip=95.215.58.49 Received: from mta1.migadu.com (out-49.mta1.migadu.com [95.215.58.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F22C4606A320 for ; Tue, 27 Oct 2026 08:11:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F22C4606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=DO30WsaM X-Envelope-To: linux-kernel@vger.kernel.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-kernel@vger.kernel.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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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