From patchwork Sat Jun 10 06:15:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13274728 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 C58BBC77B7A for ; Sat, 10 Jun 2023 06:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=qFNFacDefFuHEmwGbpyaoqFqap14hw51Y29gXt1eMaM=; b=ws1W8Ft/RLB/uLXLcOoGdWESTA NFqlkKRuw34SLuHXEp76uiRV2MG8EzmcYYlAvV5uFShxQN0Woi/9ND2SPWFWe4df0B56JQHjkSzg3 +RPVirjdT2Fejj2la6y3TP3OuL9BTjoaiuJSCEu16SZVcqlrKOq/GtbshuaS2XPJANyknhOa4KwGg biofU2hGz195v/BHnRPqM60mOqCaujYrBSZBgct/2FIYmCSj8tzjM7wp7yQssdBH7IHKmAEnrhFcm 7KCss/YATqWUXh3SzH5N8yNJmRgL5cBBTxSO0IQBMXlE1qPkLQtcwl5aMx3rDd5ezVBc/O6e1koK6 46p/TZow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7rtB-00FM3O-34; Sat, 10 Jun 2023 06:15:53 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7rt9-00FM2o-2U for linux-arm-kernel@lists.infradead.org; Sat, 10 Jun 2023 06:15:53 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bad475920a8so7915428276.1 for ; Fri, 09 Jun 2023 23:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686377750; x=1688969750; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XLDsl1lE9fKzoXIg8MPnOFwUsmvQwygsh/INqaD/ueI=; b=UXc1xrBzdBOHgPQCOKCE2wNtYRgmzI+RQz6iY7jqlTfPceGe8tt2VMepKsGukaoYIa rzVoXP04E5vTRIA+ikBFVrDAcy7bloizNSUaTJhzYOECZl3wkLSMZq+XATfYdTlkZRKM FD1ZE/J4yrcDhasx1GF+l/LHPaCm2AN+dnhJG0Y+CWXKaGkMgKzct2jnOokOTkUn2wYd Bc4yjOcQO7urvkPY3uxi+wn8za7LZjpnUgvGGDwBsvWSuXzmN219boKVn62J2AXwM2bc miAMFWnxzMl1GsD5Bj4PXBdMFNm3ql+fyIDyrVUWZzlI65MuXPXJpmFCdaAg8OBc7I8h C0Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686377750; x=1688969750; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XLDsl1lE9fKzoXIg8MPnOFwUsmvQwygsh/INqaD/ueI=; b=Tdc07tEy+MGZYL0f9KAnTb2bq5/FRtw6KV+9EZoh8SrU7FCpVORf8zXc/+ifCyl96/ 2hw0hAKHGSuH8yrI1ooUTJrc67hHkAQ2rup4/uMtK8gga0LiO06iefBEyUW3COBs1oPm xXQJS65ZZCyo4TnwdKoWfO9+tcHB40oeP0oG9cFvEsax90XjkH09KipUGcGgNa9OpYRU T3UOcfnB2jal9Q0jSAnP0c9BsW5Scf3lDoAFW14VlQirYM5eHRIqEbn0jtJ91CSXN9dp omxedfuFtj1++ArQwaQdq4OkCSwWnQ3r865f2NQ1TcdOef8kcElqOTHDweoVtaejn+co CqIA== X-Gm-Message-State: AC+VfDzRKtkJ5pRwBFXAYyJHwFVmbN2ZGg0vHHXwxpetpDO4/hlVq/co 9wgLnEVB2hXoe99bOruCAaHtNthOsp8= X-Google-Smtp-Source: ACHHUZ6XJDpHi/HdxtmR8FpIa1JbQfGhF/z0iFxliMSkJFXID9aX9+1u8XSDF829uN+7AjpPFpq3nAnn06c= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:8c07:0:b0:bad:2b06:da3 with SMTP id k7-20020a258c07000000b00bad2b060da3mr2303926ybl.3.1686377750578; Fri, 09 Jun 2023 23:15:50 -0700 (PDT) Date: Fri, 9 Jun 2023 23:15:19 -0700 In-Reply-To: <20230610061520.3026530-1-reijiw@google.com> Mime-Version: 1.0 References: <20230610061520.3026530-1-reijiw@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230610061520.3026530-2-reijiw@google.com> Subject: [PATCH 1/2] KVM: arm64: PMU: Introduce pmu_v3_is_supported() helper From: Reiji Watanabe To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230609_231551_833766_D249FC87 X-CRM114-Status: GOOD ( 14.14 ) 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 Introduce pmu_v3_is_supported() helper to check if the given PMUVer supports PMUv3, and use it instead of open coding it. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/pmu-emul.c | 3 +-- arch/arm64/kvm/sys_regs.c | 2 +- include/kvm/arm_pmu.h | 8 ++++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 491ca7eb2a4c..5d2903f52a5f 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -672,8 +672,7 @@ void kvm_host_pmu_init(struct arm_pmu *pmu) { struct arm_pmu_entry *entry; - if (pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_NI || - pmu->pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF) + if (!pmu_v3_is_supported(pmu->pmuver)) return; mutex_lock(&arm_pmus_lock); diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 753aa7418149..9200b18127f6 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1408,7 +1408,7 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, if ((pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF && pmuver > host_pmuver)) return -EINVAL; - valid_pmu = (pmuver != 0 && pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF); + valid_pmu = pmu_v3_is_supported(pmuver); /* Make sure view register and PMU support do match */ if (kvm_vcpu_has_pmu(vcpu) != valid_pmu) diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 1a6a695ca67a..eef17de966da 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -12,6 +12,14 @@ #define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1) +static inline bool pmu_v3_is_supported(int pmuver) +{ + WARN_ON_ONCE(pmuver & ~GENMASK_ULL(ARM64_FEATURE_FIELD_BITS - 1, 0)); + + return (pmuver != ID_AA64DFR0_EL1_PMUVer_NI) && + (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF); +} + #ifdef CONFIG_HW_PERF_EVENTS struct kvm_pmc { From patchwork Sat Jun 10 06:15:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13274729 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 CA9D6C77B7A for ; Sat, 10 Jun 2023 06:16:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=IEx6nbqt2Rnf5TzYe870X4gn5G6Q/eRPEAvai6ACOjc=; b=V5zDOqcnK6D9eL3iPzE6atMSqx IbdChKWaw1svpNMe7ZTcAn54OtSCl38VwWSyUAkF3KV4qE/Pc/tV+zFj1JABuShELn5sXtl2TjXFd mwHDxrAaCFk2Z9RCXyiw2HHyHOpbOEuOvjHpDIvZ+9HsybhlnZC82tmA7LFz8WGd6y7qmXgXAMkV2 KLTAmEYhC7WrwzRB+J0zBF6/MXqneP5wSBuZ2FpR3aOZKGMbm4TnfIo/3hHWENaOJXVmEddlAeN85 wRcyfEJy1LsLdLvSGdLg3FjmxeT5WQvIOHmq8sWkDH5YXhPpJBTXVHKWWE8E0ZT+PJPbtPHXDU8mo 8c4L1+8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7rtj-00FM82-1E; Sat, 10 Jun 2023 06:16:27 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7rtg-00FM7L-2Y for linux-arm-kernel@lists.infradead.org; Sat, 10 Jun 2023 06:16:26 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bc5e2021f00so24327276.3 for ; Fri, 09 Jun 2023 23:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686377783; x=1688969783; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yRFpiF9EW1xpDdddok4DKuKkCXcjFgH6nNPKa16z1Tg=; b=v85qEb5h7erEV0vhQyB+Gi9zMu8mK1PwATuaa4UYvMQlHpiTl5aYYGPTGKVLzxNyJ1 s0aXRiu7I6K8vz9Vcw2KIiG+VcvSfR3imgnH8gfmeqbt8d9Ubg9ut0tgfN4dct+DafI4 FzY6T7hYX0d1i0q7DDMWnJsnTy9731J3qEexOmihzJVCvHq36GuKp8r8ai15VkdJRq1t VS0DwYsrPqtOqTaSAqdz1sl0fdHzpzFEEdMoy8sIXgcGeqim8rf5WEC5aMWTAepcp8dn wZQeFF4CG0zk7363WR2hAEhSrpXL8o0j5xLhPfmBsygnY0C9VjVNFpmS7djf9kuJVvBS +GAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686377783; x=1688969783; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yRFpiF9EW1xpDdddok4DKuKkCXcjFgH6nNPKa16z1Tg=; b=eNUVvmgNciSRCjntONN0+TuaeGNO72/aRXAa1u+JeTNmZsOs2yjG/gn3JMleY7FADF DBqNQnaw35pFgoe8PhjWh+siObCp3whEmpOkY6UEKxIbLUE7L4PEcwEjMtoJJUMS5vRH P4PKnrt2aK2F/dyZShT5wPfgUui9NPXN6Yrx7r+wC1uk8U7LxosXehJ/miyonmEj5hfs A/p3MRxgn744vTO/xbbvN/YI5cmNHqJ5B4PPgqCtGClJ8sIo98NAs2lxad7pDDlTCSHL y2yrKYpauCpjOYxTlrc5g1kEHSVXtSEZuNca3xzUywSKKoRTIIVmZRT3TDqzpC2iKT8o 9QIw== X-Gm-Message-State: AC+VfDwOEULZUhEpb2tN9hbxr0F32ez6TsB+WoNFXZePE7lGo71+IMpn naqC0d+6EFDbPVBKl/RAvs7UCi5h9L0= X-Google-Smtp-Source: ACHHUZ5PHGV4oelgCpab9bxHiQhiMBK4E/MkgJr0Ll1vuL3QAsfBaqeaprxSa0xFu5L+88zqObG0H4XDUv4= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a05:6902:1085:b0:bac:f582:ef18 with SMTP id v5-20020a056902108500b00bacf582ef18mr1834265ybu.5.1686377783371; Fri, 09 Jun 2023 23:16:23 -0700 (PDT) Date: Fri, 9 Jun 2023 23:15:20 -0700 In-Reply-To: <20230610061520.3026530-1-reijiw@google.com> Mime-Version: 1.0 References: <20230610061520.3026530-1-reijiw@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230610061520.3026530-3-reijiw@google.com> Subject: [PATCH 2/2] KVM: arm64: PMU: Disallow vPMU on non-uniform PMUVer systems From: Reiji Watanabe To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230609_231624_831320_15C3FA54 X-CRM114-Status: GOOD ( 12.67 ) 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 Disallow userspace from configuring vPMU for guests on systems where the PMUVer is not uniform across all PEs. KVM has not been advertising PMUv3 to the guests with vPMU on such systems anyway, and such systems would be extremely uncommon and unlikely to even use KVM. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/pmu-emul.c | 3 --- include/kvm/arm_pmu.h | 10 ++++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 14391826241c..21901fbd6e4d 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1960,6 +1960,7 @@ static int __init init_subsystems(void) goto out; kvm_register_perf_callbacks(NULL); + kvm_arm_set_support_pmu_v3(); out: if (err) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 5d2903f52a5f..45b84cf22026 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -684,9 +684,6 @@ void kvm_host_pmu_init(struct arm_pmu *pmu) entry->arm_pmu = pmu; list_add_tail(&entry->entry, &arm_pmus); - if (list_is_singular(&arm_pmus)) - static_branch_enable(&kvm_arm_pmu_available); - out_unlock: mutex_unlock(&arm_pmus_lock); } diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index eef17de966da..af1fe2b53fbb 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -105,6 +105,14 @@ void kvm_vcpu_pmu_restore_host(struct kvm_vcpu *vcpu); u8 kvm_arm_pmu_get_pmuver_limit(void); +static inline void kvm_arm_set_support_pmu_v3(void) +{ + u8 pmuver = kvm_arm_pmu_get_pmuver_limit(); + + if (pmu_v3_is_supported(pmuver)) + static_branch_enable(&kvm_arm_pmu_available); +} + #else struct kvm_pmu { }; @@ -114,6 +122,8 @@ static inline bool kvm_arm_support_pmu_v3(void) return false; } +static inline void kvm_arm_set_support_pmu_v3(void) {}; + #define kvm_arm_pmu_irq_initialized(v) (false) static inline u64 kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, u64 select_idx)