From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381362; b=gJ/TxdvTONflGpEMaMIwWJH0Zj9+4OHzqm65nh/3IeWrAcJfOxCy6m8AJeZv0UqL1dyy NOd5SLhdBDcjYPnATam5vXSnUnNI+tWCxJwaTHtLcIVwtfVAv6RLFuBrTq8mjPAHCsz7x ti7OsiUBWUpIWJRXB/Bo1b6BQlmUTOdlkiEuFpeNyt867iM1t0KH4TTAY/qj/xypJ4TUz LvsGD3213STkneCoehZKo9iNT0APqMeV+aqE486OAVq33VPgjoXaiMtoDyxx791/6L3z1 IOf/9GaOiZZxaA/esWejF+iirr/CnOByVEoSIW64OhYAuDJKbUnjKB781MQ1PoIPYFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381362; 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=Ko8lvx9iBpSZmP0j38SKozzd9w2AQptPse2OS8afBgI=; b=GpuyojuKa7SagwhTY9JTxiAMPt1YP16v3v79YB26brgTQ6PSQZRQXoUu5o2NKjhrhpCl NTrKycAs/b3RCWcg6SN0sx6BMrGwinzYls3kwTo9GR7z/5ogiMxfscXNXZ8BhoUEwMr+U 2thrqRjAi7t293qhJV9iuLm973OVpqeYmYIwDzFtZCOd0xIbomUS39HSqExx2c0wCGBsd BTxPJofxyq26WyMaXsRoljE7/mVRP4Bv3+KFM3g7allxHUrGUbtiXqLrmNFZfv7VkhoTf YndhWcu/p/x5IglPoFYzzx0Fcd2c9wY+grdo73LnGtMtOv8WfIiIoOlVG0CmQ7IUbkA== 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=Cy3BPXE6; arc=none smtp.remote-ip=91.218.175.171 Received: from mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 7BC64606A330 for ; Fri, 4 Dec 2026 10:49:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7BC64606A330 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=Cy3BPXE6 X-Envelope-To: kvm@vger.kernel.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: kvm@vger.kernel.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-Mailing-List: kvm@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 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