Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp185863ybt; Tue, 23 Jun 2020 19:02:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRSKGKuHfL2kqmscTKPYJ/nTeRPVfxjI/0NRJQV/FqhDwvMAvnhCxzrZ0Bl4XAbVL3AJbu X-Received: by 2002:a17:906:284d:: with SMTP id s13mr3568936ejc.247.1592964142566; Tue, 23 Jun 2020 19:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592964142; cv=none; d=google.com; s=arc-20160816; b=jjuPZxtrkNvqvvFLQaF3j6Ot1g1eTswFqmxnQwEHaOj1OIKyIkrYCMLHBNv7WW44af INGd53jWGN9NOzvcLA5iiyzeWICF9HycA+vOiRNjCIyWcqbgL/4zQ5H3QqyV9iVf+lYW KBGQlvcUpXd18QcgNzRWL1KsGbX6M3Od4NL7XmjbdXftWpGhnz7dPJPOP/dYkUhfxx0t /+KXKtPpRQ3QssLjOySBCj5p2rWjg6idePrJTuxKTZVyQ4DEk3XqkGzxcZTp/4hlqCga VIvNxBf9Z/jhY25mLa0YHkWeCcaAJrPbZWRc2fqDi+UPdc53ooxjGDxyAE6+iSmgAf7c wmjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=RDuL7Fcxk+vAwBpDlIenVpfpgPHwHZy4+30gqWY2kI4=; b=x1sflKem+tEtzzt4QRPTIa7go3Vo7DEcclPR00P3/oXzsOSsFc/WeIADlm7e+Oba6k f+OIyVVsN8Aff0eS0FxYtqw0PNKOy6sXWPI9o2KjOx6MdskbxIe5hNe1QKtPACM6KzEY +U2LaIBmq6vqz5bEgvP26PYXmwcG/4slUIiDgfTnIRHhtCeIkGVtPZcO4PX0mBb4E70W Psrg0T2gea/NVNwx/3Hn2p8cV7ekH+w+mCb+Rp8yHOnCQlypOvj4O6GrOo1ihqWhQztM agFgSWyxZN8AzfhpR0mJph1zQVg2EFXIMaQCfN08OFx4OKa17biMzhzgV/tJgsIG66rB NBaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o20si11266041eju.673.2020.06.23.19.01.57; Tue, 23 Jun 2020 19:02:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387719AbgFXCAp (ORCPT + 99 others); Tue, 23 Jun 2020 22:00:45 -0400 Received: from mga05.intel.com ([192.55.52.43]:12261 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730898AbgFXCAp (ORCPT ); Tue, 23 Jun 2020 22:00:45 -0400 IronPort-SDR: rrS8TqHZfrqc5u3S9NZdlxRhkrtJTqaUj06dnpYqPzPtd2UAStEZksx6uJXTlKkJx/Qblr+o7D Bg6ZEWLSoX3Q== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="228978274" X-IronPort-AV: E=Sophos;i="5.75,273,1589266800"; d="scan'208";a="228978274" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 19:00:44 -0700 IronPort-SDR: nyusmRsoLpw4RhjXmgQ2g5Ff9IPLjc3Aqcjzxi8zdrmzruuMYtvvxZvnEX1FQas3QtGUjJl3yS ns3x6FbD8c/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,273,1589266800"; d="scan'208";a="310649991" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by orsmga008.jf.intel.com with ESMTP; 23 Jun 2020 19:00:41 -0700 From: Like Xu To: Paolo Bonzini , kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH] kvm: x86: limit the maximum number of vPMU fixed counters to 3 Date: Wed, 24 Jun 2020 09:59:28 +0800 Message-Id: <20200624015928.118614-1-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some new Intel platforms (such as TGL) already have the fourth fixed counter TOPDOWN.SLOTS, but it has not been fully enabled on KVM and the host. Therefore, we limit edx.split.num_counters_fixed to 3, so that it does not break the kvm-unit-tests PMU test case and bad-handled userspace. Signed-off-by: Like Xu --- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/pmu.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 8a294f9747aa..0a2c6d2b4650 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -604,7 +604,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) eax.split.bit_width = cap.bit_width_gp; eax.split.mask_length = cap.events_mask_len; - edx.split.num_counters_fixed = cap.num_counters_fixed; + edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS); edx.split.bit_width_fixed = cap.bit_width_fixed; edx.split.reserved = 0; diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h index ab85eed8a6cc..067fef51760c 100644 --- a/arch/x86/kvm/pmu.h +++ b/arch/x86/kvm/pmu.h @@ -15,6 +15,8 @@ #define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001 #define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002 +#define MAX_FIXED_COUNTERS 3 + struct kvm_event_hw_type_mapping { u8 eventsel; u8 unit_mask; -- 2.21.3