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 CB3DC606A330 for ; Fri, 4 Dec 2026 10:49:29 +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=EUi73dxv; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Cy3BPXE6 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=Ko8lvx9iBpSZmP0j38SKozzd9w2AQptPse2OS8afBgI=; b=EUi73dxvXDNFU0 nUVLdEp+PTKLIxYhnqVpHyoEhTMAlrAkM8rqFoSgnMwLoP9B1GecmY801kAYrIqm210OPIdjcLwi7 ZnkYHKd9ihUMgiWTwurIybciBYkaKnmjQ6Qbq3m3MqWJwFFcYkln+GmyvaliqNadutf3Wbj328JsS RmvLVtzYVm5XQgEsWmN7NWddgdsRgTG9oG8CBMaIEO1J0gXuMybGr55EvLAdUUGHeb/m/3Jz7Vj42 5VStG4ZpPcxochgT3hfruOBTjDVcAGXfuewjq7Rum02oUMk30TnqEIOB5lVqCEA0FBQJz4kjJB5gz SSItYW+1+oaFihU6rGBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZQqx-000000002Ld-3QS5; Fri, 04 Dec 2026 10:49:23 +0000 Received: from out-167.mta1.migadu.com ([2001:41d0:203:375::a7] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZQqv-000000002KV-29dJ for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 10:49:22 +0000 X-Envelope-To: linux-arm-kernel@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=0r71yIMFELZ+bjucGw5kCmqL/DV7rnqeuA+oN1g9JRg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796381359; v=1; x=1796986159; b=Cy3BPXE6tDboAmvlTCjZOSiqwaDrbZ94M+B5fo8DRV8oxjXWLaxb5tmdUfNIF1wj30oXv7sP O9teuvYCDFlQzWH2OFM+q05gr/7T29ggOH3VIjhswkZebSHwacZJVe012Wdp8n3NKIc1LoJYXIf 7qb9wtSnSR78eZKcmGR6ne44= X-Envelope-To: linux-arm-kernel@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id e5479770fc74a4a5; Fri, 04 Dec 2026 10:49:19 +0000 X-Mizu-Trace-ID: e5479770fc74a4a5 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Marc Zyngier , Oliver Upton Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Vincent Donnefort , Paolo Bonzini , Sean Christopherson , Shuah Khan , James Clark , Fuad Tabba Subject: [PATCH 1/2] KVM: arm64: Don't copy the PMU registers between the host and hyp vCPU Date: Fri, 4 Dec 2026 10:49:10 +0000 Message-ID: <20261204104911.2797512-2-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261204104911.2797512-1-fuad.tabba@linux.dev> References: <20261204104911.2797512-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-20261204_024921_692317_747EFFFE X-CRM114-Status: GOOD ( 12.18 ) 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.3 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 The host emulates the PMU of a non-protected guest in pKVM, and EL2 doesn't access the guest's PMU registers in the hyp vCPU. Lazy state sync copies them anyway. Since commit 8ee90ca40b10c ("KVM: arm64: Pass the PMU events to the hyp vCPU of non-protected guests") the guest's counters count, and the perf overflow handler sets an overflowing counter's bit in the host's copy of PMOVSSET_EL0 before the host has synced the guest's state. The next sync overwrites it with the hyp vCPU's stale copy, so the guest takes no overflow interrupt, or takes it with the overflow bit clear. Leave the PMU registers out of the copy, like we do for the timer registers. Fixes: 734dc8c01c838 ("KVM: arm64: Implement lazy vCPU state sync for non-protected guests") Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 0c023ee0cf42a..2d0401a94246b 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -627,7 +627,7 @@ static void __copy_vcpu_state(const struct kvm_vcpu *from_vcpu, to_vcpu->arch.ctxt.fp_regs = from_vcpu->arch.ctxt.fp_regs; /* - * Copy the sysregs, but don't mess with the timer state which + * Copy the sysregs, but don't mess with the timer and PMU state which * is directly handled by EL1 and is expected to be preserved. * enum vcpu_sysreg is sparse: VNCR-mapped registers take values * derived from their VNCR page offset, so the timer registers do @@ -640,6 +640,16 @@ static void __copy_vcpu_state(const struct kvm_vcpu *from_vcpu, case CNTV_CTL_EL0: case CNTP_CVAL_EL0: case CNTP_CTL_EL0: + case PMCR_EL0: + case PMSELR_EL0: + case PMEVCNTR0_EL0 ... PMEVCNTR30_EL0: + case PMCCNTR_EL0: + case PMEVTYPER0_EL0 ... PMEVTYPER30_EL0: + case PMCCFILTR_EL0: + case PMCNTENSET_EL0: + case PMINTENSET_EL1: + case PMOVSSET_EL0: + case PMUSERENR_EL0: continue; } to_vcpu->arch.ctxt.sys_regs[i] = from_vcpu->arch.ctxt.sys_regs[i]; -- 2.47.3