From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Aaron Lewis <aaronlewis@google.com>,
Like Xu <like.xu.linux@gmail.com>
Subject: [PATCH 2/4] KVM: x86/pmu: Simplify intel_hw_event_available()
Date: Tue, 6 Jun 2023 18:02:04 -0700 [thread overview]
Message-ID: <20230607010206.1425277-3-seanjc@google.com> (raw)
In-Reply-To: <20230607010206.1425277-1-seanjc@google.com>
Walk only the "real", i.e. non-pseudo, architectural events when checking
if a hardware event is available, i.e. isn't disabled by guest CPUID.
Skipping pseudo-arch events in the loop body is unnecessarily convoluted,
especially now that KVM has enums that delineate between real and pseudo
events.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/vmx/pmu_intel.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
index 0050d71c9c01..f281e634af3c 100644
--- a/arch/x86/kvm/vmx/pmu_intel.c
+++ b/arch/x86/kvm/vmx/pmu_intel.c
@@ -122,17 +122,16 @@ static bool intel_hw_event_available(struct kvm_pmc *pmc)
BUILD_BUG_ON(ARRAY_SIZE(intel_arch_events) != NR_INTEL_ARCH_EVENTS);
- for (i = 0; i < NR_INTEL_ARCH_EVENTS; i++) {
+ /*
+ * Disallow events reported as unavailable in guest CPUID. Note, this
+ * doesn't apply to pseudo-architectural events.
+ */
+ for (i = 0; i < NR_REAL_INTEL_ARCH_EVENTS; i++) {
if (intel_arch_events[i].eventsel != event_select ||
intel_arch_events[i].unit_mask != unit_mask)
continue;
- /* disable event that reported as not present by cpuid */
- if ((i < PSEUDO_ARCH_REFERENCE_CYCLES) &&
- !(pmu->available_event_types & (1 << i)))
- return false;
-
- break;
+ return pmu->available_event_types & BIT(i);
}
return true;
--
2.41.0.162.gfafddb0af9-goog
next prev parent reply other threads:[~2023-06-07 1:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 1:02 [PATCH 0/4] KVM: x86/pmu: Clean up arch/hw event handling Sean Christopherson
2023-06-07 1:02 ` [PATCH 1/4] KVM: x86/pmu: Use enums instead of hardcoded magic for arch event indices Sean Christopherson
2023-07-10 10:50 ` Like Xu
2023-06-07 1:02 ` Sean Christopherson [this message]
2023-06-07 1:02 ` [PATCH 3/4] KVM: x86/pmu: Require nr fixed_pmc_events to match nr max fixed counters Sean Christopherson
2023-06-07 1:02 ` [PATCH 4/4] KVM: x86/pmu: Move .hw_event_available() check out of PMC filter helper Sean Christopherson
2023-07-11 16:32 ` Like Xu
2023-07-12 16:11 ` Sean Christopherson
2023-08-03 0:05 ` [PATCH 0/4] KVM: x86/pmu: Clean up arch/hw event handling 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=20230607010206.1425277-3-seanjc@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/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
Powered by JetHome