From: Aaron Lewis <aaronlewis@google.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
Aaron Lewis <aaronlewis@google.com>
Subject: [PATCH v6 3/7] kvm: x86/pmu: prepare the pmu event filter for masked events
Date: Fri, 21 Oct 2022 20:51:01 +0000 [thread overview]
Message-ID: <20221021205105.1621014-4-aaronlewis@google.com> (raw)
In-Reply-To: <20221021205105.1621014-1-aaronlewis@google.com>
Refactor check_pmu_event_filter() in preparation for masked events.
No functional changes intended
Signed-off-by: Aaron Lewis <aaronlewis@google.com>
---
arch/x86/kvm/pmu.c | 56 +++++++++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 23 deletions(-)
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index a79f0d5ecaf0..64172e082404 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -257,41 +257,51 @@ static int cmp_u64(const void *pa, const void *pb)
return (a > b) - (a < b);
}
+static u64 *find_filter_entry(struct kvm_pmu_event_filter *filter, u64 key)
+{
+ return bsearch(&key, filter->events, filter->nevents,
+ sizeof(filter->events[0]), cmp_u64);
+}
+
+static bool is_gp_event_allowed(struct kvm_pmu_event_filter *filter, u64 eventsel)
+{
+ if (find_filter_entry(filter, eventsel & (kvm_pmu_ops.EVENTSEL_EVENT |
+ ARCH_PERFMON_EVENTSEL_UMASK)))
+ return filter->action == KVM_PMU_EVENT_ALLOW;
+
+ return filter->action == KVM_PMU_EVENT_DENY;
+}
+
+static bool is_fixed_event_allowed(struct kvm_pmu_event_filter *filter, int idx)
+{
+ int fixed_idx = idx - INTEL_PMC_IDX_FIXED;
+
+ if (filter->action == KVM_PMU_EVENT_DENY &&
+ test_bit(fixed_idx, (ulong *)&filter->fixed_counter_bitmap))
+ return false;
+ if (filter->action == KVM_PMU_EVENT_ALLOW &&
+ !test_bit(fixed_idx, (ulong *)&filter->fixed_counter_bitmap))
+ return false;
+
+ return true;
+}
+
static bool check_pmu_event_filter(struct kvm_pmc *pmc)
{
struct kvm_pmu_event_filter *filter;
struct kvm *kvm = pmc->vcpu->kvm;
- bool allow_event = true;
- __u64 key;
- int idx;
if (!static_call(kvm_x86_pmu_hw_event_available)(pmc))
return false;
filter = srcu_dereference(kvm->arch.pmu_event_filter, &kvm->srcu);
if (!filter)
- goto out;
+ return true;
- if (pmc_is_gp(pmc)) {
- key = pmc->eventsel & (kvm_pmu_ops.EVENTSEL_EVENT |
- ARCH_PERFMON_EVENTSEL_UMASK);
- if (bsearch(&key, filter->events, filter->nevents,
- sizeof(__u64), cmp_u64))
- allow_event = filter->action == KVM_PMU_EVENT_ALLOW;
- else
- allow_event = filter->action == KVM_PMU_EVENT_DENY;
- } else {
- idx = pmc->idx - INTEL_PMC_IDX_FIXED;
- if (filter->action == KVM_PMU_EVENT_DENY &&
- test_bit(idx, (ulong *)&filter->fixed_counter_bitmap))
- allow_event = false;
- if (filter->action == KVM_PMU_EVENT_ALLOW &&
- !test_bit(idx, (ulong *)&filter->fixed_counter_bitmap))
- allow_event = false;
- }
+ if (pmc_is_gp(pmc))
+ return is_gp_event_allowed(filter, pmc->eventsel);
-out:
- return allow_event;
+ return is_fixed_event_allowed(filter, pmc->idx);
}
void reprogram_counter(struct kvm_pmc *pmc)
--
2.38.0.135.g90850a2211-goog
next prev parent reply other threads:[~2022-10-21 20:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-21 20:50 [PATCH v6 0/7] Introduce and test masked events Aaron Lewis
2022-10-21 20:50 ` [PATCH v6 1/7] kvm: x86/pmu: Correct the mask used in a pmu event filter lookup Aaron Lewis
2022-10-21 20:51 ` [PATCH v6 2/7] kvm: x86/pmu: Remove impossible events from the pmu event filter Aaron Lewis
2022-10-21 20:51 ` Aaron Lewis [this message]
2022-10-21 20:51 ` [PATCH v6 4/7] kvm: x86/pmu: Introduce masked events to " Aaron Lewis
2022-12-15 9:43 ` Like Xu
2022-12-16 17:55 ` Sean Christopherson
2022-12-16 18:31 ` Aaron Lewis
2022-12-19 10:02 ` Like Xu
2022-10-21 20:51 ` [PATCH v6 5/7] selftests: kvm/x86: Add flags when creating a " Aaron Lewis
2022-10-21 20:51 ` [PATCH v6 6/7] selftests: kvm/x86: Add testing for KVM_SET_PMU_EVENT_FILTER Aaron Lewis
2022-10-21 20:51 ` [PATCH v6 7/7] selftests: kvm/x86: Test masked events Aaron Lewis
2022-10-27 22:00 ` Sean Christopherson
2022-10-27 22:02 ` [PATCH v6 0/7] Introduce and test " Sean Christopherson
2022-11-09 11:28 ` Like Xu
2022-11-09 17:41 ` Aaron Lewis
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=20221021205105.1621014-4-aaronlewis@google.com \
--to=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.