From patchwork Sat Aug 19 04:39:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13358506 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 59196EE499C for ; Sat, 19 Aug 2023 04:40:47 +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=TX9LwXTiBAcWqiuyqc90RjsuFbMj+xZJfnqtusn4ojA=; b=sPIfn84rb2HxO7wK66TGBmUsWz PrHP0Xl7W7RRI7esFFSdTvaLzVFJRxc/ah4aJ07YYsSB1KlEeyypxpZvOlw0whLg5541aDyMwrOx/ VmIsMnb/CHaPzGm4h12SXAfvD8wWvUB7sKtAi0QVBMOEuSLsQH93OS7NFQCCVAj4eauElibu+/5nU 6xK1mYNbm9wBBr0Z3iUPlImHgqY31X1JHVX/B0xcM/Lxl4P+dS2JvHUzxssbrXl1c2cKL4vBAfE+d iDJcfm5sUfbXkpAm+8opKxvDF7ecKIbSKgm7IYVLeHcQV1+vbp+08GTrEXG9g5Wc0BW5qghhx1kuT suOODlag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qXDkq-00AOUM-2Q; Sat, 19 Aug 2023 04:40:04 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qXDkn-00AOSC-1f for linux-arm-kernel@lists.infradead.org; Sat, 19 Aug 2023 04:40:02 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58cbf62bae8so21845287b3.3 for ; Fri, 18 Aug 2023 21:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692419999; x=1693024799; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Seh1pUJAoJeQMsb3DjbA2692WgZC2RtCPmgGThvub30=; b=DwkJD32BekuBCy2U4IGt+GsAXbEeNlO8nqmNBNRYSJRYAuGurqXGOPFa84zQOJUG6B LNX++XExakKbrpEEtpeXFwLrXMqQNp6nJ7PgVb9YR2MT1ig76IumJt0+ofKZIrV3yULh yRVADfXjNzU1NlxKdGULlj+buFsONnxtCUK14eD5NRvOz3hCTltJ/Hz89hHQ0QDm1LNu b5zLZjuAV72if7vS438j5l1gDhM7Eb+jUFyBy+xk/4v1QNP09pY6tL2zIdftUFzWFDqJ HGDtcaUnBhLuUXFvefYPtalWuV4aMkM8zuZRykC/3owI3r3scalOmigyXxpLegc0wNN8 H89Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692419999; x=1693024799; 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=Seh1pUJAoJeQMsb3DjbA2692WgZC2RtCPmgGThvub30=; b=EN87Obb+kjDxWRhOxbjTbyJlOKXVkcsi47HMrfCMPgrOwz4I8fmSCZLE8CiBio0/Ju o+oouYGfONqgzFfqKuCrkDrO5qcP8Idpe/rcIHVAY2GFw2aO4DftdDyo6T3qT0n/0wxs xnbyo5FJHPKPZVDwYQC5S1TsETqJq2q2WwZ6XACss8/AF5W2/ndmXcgevqniboaGETJj uxB9xFE52ydkj6wioB+JVj6AgTf4tUCvMHmn7kneLQg+Ixrtak5K1F0NyUA3NZGg+mcV nZ4kxzndH9dKz4AbSJQMiLUszOQAz1WBir7h+z2n7QEnzPIoTGv0ak9ELEW65zENSJPT MaxA== X-Gm-Message-State: AOJu0Yxf+GbFqXbT7oioJ9IIPCl209x6Z9MgArEAIltcLx7FIm46+arV B3CfCvOGmTC+bd/sSH2/uo7WpkGAIE8= X-Google-Smtp-Source: AGHT+IHb42+dcZ0kfTh6jwPD34e2/SSiy6aoKrRAB1WAoCDxylqcANHFl34q+BzSpUcEkGGuqaQWd6kWUhU= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a81:764e:0:b0:584:3d8f:a425 with SMTP id j14-20020a81764e000000b005843d8fa425mr10578ywk.10.1692419998770; Fri, 18 Aug 2023 21:39:58 -0700 (PDT) Date: Fri, 18 Aug 2023 21:39:44 -0700 In-Reply-To: <20230819043947.4100985-1-reijiw@google.com> Mime-Version: 1.0 References: <20230819043947.4100985-1-reijiw@google.com> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230819043947.4100985-2-reijiw@google.com> Subject: [PATCH v3 1/4] KVM: arm64: PMU: Disallow vPMU on non-uniform PMUVer 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-20230818_214001_558920_67227C3B X-CRM114-Status: GOOD ( 13.68 ) 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/pmu-emul.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 560650972478..689bbd88fd69 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -14,6 +14,7 @@ #include #include #include +#include #define PERF_ATTR_CFG1_COUNTER_64BIT BIT(0) @@ -672,8 +673,11 @@ 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) + /* + * Check the sanitised PMU version for the system, as KVM does not + * support implementations where PMUv3 exists on a subset of CPUs. + */ + if (!pmuv3_implemented(kvm_arm_pmu_get_pmuver_limit())) return; mutex_lock(&arm_pmus_lock);