From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D37E3C021AA for ; Wed, 19 Feb 2025 17:47:46 +0000 (UTC) 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-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cL21fulpfITu0hDXuuY6KqorVnA0OzHYgjj1ZGgGQt8=; b=4QulcYXhFUOoB0rHwuob0rdhT2 mUbC4YNhFKqJpKnGcQ44zmimpaf6Dtpq+pTd0Y/UVcMvL6mQIWrrYTMXDzppNsFJq59Cwo+BZMbgq PvQpqTx7RKv3fclYAUqQipapH/XGvNDnOxdt1xIrpJni+tPSb2mYM8ptJPCvs5XsDBPWCpPq4OnVA I1dPa8CAahlRqjTU3LyYRuLefR3jjZNAeOwmXnzhYQc6Cg1OZuT+OjJKw0Uhtw4u05+fv3YWggBjM nnD0BPuNVx3sESFjSdHDzqPdmuqHusPw/9nJXc6jXpvVMbAaKD+OZYpXL5NKqVa9YBXPMOxONnfcz pOu1WkCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tkoAY-0000000EAkI-3vX4; Wed, 19 Feb 2025 17:47:34 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tko86-0000000EA2l-3v0j for linux-arm-kernel@lists.infradead.org; Wed, 19 Feb 2025 17:45:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1C7705C5B45; Wed, 19 Feb 2025 17:44:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E56B1C4CED1; Wed, 19 Feb 2025 17:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739987102; bh=9DDQSRBXojYKs3E7l0ZcCaT7BmSFwinEFa+8YID+AY0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GzI76u01W+GuItG8twFKvac3xBV8lqEt2O70ZlQ9ECAM7mn4PvY6B6m3dFVNeoSJF bAZxgh30RdMRUzQZLDVLSZOCrIsIbWzdIvS33u09PTY07HDgLbMXmj9W6psLwIPzV0 RRdB7by9dMs04GOCMFsJFA3aNWTLPeTIY3MtUfRUk7iI1rZlLhg6o8YHzQk6Y1myQG +vh8xwegNiTBcoB2O13Kb55jz5H6cBYN5tTbvKe6Xv5pKDYLJPngZcOJg79IpF7r1H 9Fe0p6n8xuhg2RWvpbnx4SRy/p+ijK15Cn73A1hkbadJEXNaZqwemj4H/B/dHrvYY/ i6Rd5VZq9xLKg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tko83-005ud8-MR; Wed, 19 Feb 2025 17:44:59 +0000 Date: Wed, 19 Feb 2025 17:44:59 +0000 Message-ID: <864j0psuas.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, Joey Gouly , Suzuki K Poulose , Zenghui Yu , Mingwei Zhang , Colton Lewis , Raghavendra Rao Ananta , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Janne Grunau Subject: Re: [PATCH v2 07/14] KVM: arm64: Use a cpucap to determine if system supports FEAT_PMUv3 In-Reply-To: <20250203183111.191519-8-oliver.upton@linux.dev> References: <20250203183111.191519-1-oliver.upton@linux.dev> <20250203183111.191519-8-oliver.upton@linux.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kvmarm@lists.linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, mizhang@google.com, coltonlewis@google.com, rananta@google.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, j@jannau.net X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250219_094503_060390_40892E28 X-CRM114-Status: GOOD ( 27.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 03 Feb 2025 18:31:04 +0000, Oliver Upton wrote: > > KVM is about to learn some new tricks to virtualize PMUv3 on IMPDEF > hardware. As part of that, we now need to differentiate host support > from guest support for PMUv3. > > Add a cpucap to determine if an architectural PMUv3 is present to guard > host usage of PMUv3 controls. > > Tested-by: Janne Grunau > Signed-off-by: Oliver Upton > --- > arch/arm64/include/asm/cpufeature.h | 5 +++++ > arch/arm64/kernel/cpufeature.c | 19 +++++++++++++++++++ > arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++-- > arch/arm64/kvm/pmu.c | 10 +++++----- > arch/arm64/tools/cpucaps | 1 + > include/kvm/arm_pmu.h | 2 +- > 6 files changed, 33 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index e0e4478f5fb5..0eff048848b8 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -866,6 +866,11 @@ static __always_inline bool system_supports_mpam_hcr(void) > return alternative_has_cap_unlikely(ARM64_MPAM_HCR); > } > > +static inline bool system_supports_pmuv3(void) > +{ > + return cpus_have_final_cap(ARM64_HAS_PMUV3); > +} > + > int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt); > bool try_emulate_mrs(struct pt_regs *regs, u32 isn); > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 4eb7c6698ae4..6886d2875fac 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -1898,6 +1898,19 @@ static bool has_lpa2(const struct arm64_cpu_capabilities *entry, int scope) > } > #endif > > +static bool has_pmuv3(const struct arm64_cpu_capabilities *entry, int scope) > +{ > + u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); > + unsigned int pmuver; > + > + pmuver = cpuid_feature_extract_unsigned_field(dfr0, > + ID_AA64DFR0_EL1_PMUVer_SHIFT); > + if (pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF) > + return false; > + > + return pmuver >= ID_AA64DFR0_EL1_PMUVer_IMP; Given that PMUVer is a signed field, how about using cpuid_feature_extract_signed_field() and do a signed comparison instead? > +} > + > #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 > #define KPTI_NG_TEMP_VA (-(1UL << PMD_SHIFT)) > > @@ -2999,6 +3012,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = { > ARM64_CPUID_FIELDS(ID_AA64PFR1_EL1, GCS, IMP) > }, > #endif > + { > + .desc = "PMUv3", > + .capability = ARM64_HAS_PMUV3, > + .type = ARM64_CPUCAP_SYSTEM_FEATURE, > + .matches = has_pmuv3, > + }, This cap is probed unconditionally (without any configuration dependency)... > {}, > }; > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index f838a45665f2..0edc7882bedb 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -244,7 +244,7 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu) > * counter, which could make a PMXEVCNTR_EL0 access UNDEF at > * EL1 instead of being trapped to EL2. > */ > - if (kvm_arm_support_pmu_v3()) { > + if (system_supports_pmuv3()) { ... but kvm_arm_support_pmu_v3() is conditional on CONFIG_HW_PERF_EVENTS. Doesn't this create some sort of new code path that we didn't expect? Thanks, M. -- Without deviation from the norm, progress is not possible.