public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Anselm Busse <abusse@amazon.com>
To: unlisted-recipients:; (no To-header on input)
Cc: <dwmw@amazon.co.uk>, <hborghor@amazon.de>, <sironi@amazon.de>,
	"Anselm Busse" <abusse@amazon.com>,
	Sean Christopherson <seanjc@google.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>, <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] KVM: vmx/pmu: Add support for selected fixed vPMU enablement for PMU v5
Date: Thu, 27 Apr 2023 09:53:33 +0000	[thread overview]
Message-ID: <20230427095333.35038-3-abusse@amazon.com> (raw)
In-Reply-To: <20230427095333.35038-1-abusse@amazon.com>

This commits adds virtualization support to enable slected fixed
function PMCs for Intel PMU v5 based on CPUID.0AH.ECX.

Starting with v5, the Intel PMU allows to indicate the available fixed
function PMCs not only through CPUID.0AH.EDX[4:0] but also through a
bit mask in CPUID.0AH.ECX. According to the SDM the OS can consider a
fix function PMC i supported for:

CPUID.0AH.ECX[i] || (CPUID.0AH.EDX[4:0] > i)

This behavior is already supported by the Intel PMU driver. However, KVM
support is missing. Therefore, this commit extends the KVM
implementation by also taking the values in CPUID.0AH.ECX into account
when setting the bitmap of enabled fixed function PMCs.

Signed-off-by: Anselm Busse <abusse@amazon.com>
---
 arch/x86/kvm/vmx/pmu_intel.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
index 55ff06a9df47..d1fd3472bfd4 100644
--- a/arch/x86/kvm/vmx/pmu_intel.c
+++ b/arch/x86/kvm/vmx/pmu_intel.c
@@ -562,6 +562,13 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
 						  kvm_pmu_cap.bit_width_fixed);
 		pmu->counter_bitmask[KVM_PMC_FIXED] =
 			((u64)1 << edx.split.bit_width_fixed) - 1;
+
+		if (pmu->version >= 5)
+			bitmap_or(pmu->mask_arch_fixed_counters,
+				  pmu->mask_arch_fixed_counters,
+				  (unsigned long *)&entry->ecx,
+				  INTEL_PMC_MAX_FIXED);
+
 		setup_fixed_pmc_eventsel(pmu);
 	}
 
-- 
2.39.2




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




  parent reply	other threads:[~2023-04-27  9:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27  9:53 [PATCH 0/2] KVM support for Intel PMU v5 fixed function PMC bitmap Anselm Busse
2023-04-27  9:53 ` [PATCH 1/2] KVM: vmx/pmu: Indicate available fixed function PMCs through a bitmap Anselm Busse
2023-05-25 22:35   ` Sean Christopherson
2023-04-27  9:53 ` Anselm Busse [this message]
2023-05-16 13:29 ` [PATCH 0/2] KVM support for Intel PMU v5 fixed function PMC bitmap Like Xu
2023-05-25 22:30   ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230427095333.35038-3-abusse@amazon.com \
    --to=abusse@amazon.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=hborghor@amazon.de \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=sironi@amazon.de \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox