From: Sean Christopherson <seanjc@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com
Subject: Re: [PATCH v5 4/7] kvm: x86/pmu: Introduce masked events to the pmu event filter
Date: Sat, 8 Oct 2022 00:37:08 +0000 [thread overview]
Message-ID: <Y0DGNEvbmT3kWR56@google.com> (raw)
In-Reply-To: <20220920174603.302510-5-aaronlewis@google.com>
On Tue, Sep 20, 2022, Aaron Lewis wrote:
> +To access individual components in a masked entry use:
> +::
> + struct kvm_pmu_event_masked_entry {
> + union {
> + __u64 raw;
> + struct {
> + /* event_select bits 11:8 are only valid on AMD. */
> + __u64 event_select:12;
> + __u64 mask:8;
> + __u64 match:8;
> + __u64 exclude:1;
As suggested in patch 3, keep the architectural bits where they are and fill in
the gaps. IIUC, all of bits 63:36 are available, i.e. there's lots of room for
expansion. Go top down (start at 63) and cross our fingers that neither Intel
nor AMD puts stuff there. If that does happen, then we can start mucking with
the layout, but until then, let's not make it too hard for ourselves.
> + __u64 rsvd:35;
> #define KVM_VCPU_TSC_CTRL 0 /* control group for the timestamp counter (TSC) */
> #define KVM_VCPU_TSC_OFFSET 0 /* attribute for the TSC offset */
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index 7ce8bfafea91..b188ddb23f75 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -252,34 +252,61 @@ static inline u8 get_unit_mask(u64 eventsel)
> return (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
> }
...
> +/*
> + * Sort will order the list by exclude, then event select. This function will
> + * then index the sublists of event selects such that when a search is done on
> + * the list, the head of the event select sublist is returned. This simplifies
> + * the logic in filter_contains_match() when walking the list.
Unless I'm missing something, this is a complex way to solve a relatively simple
problem. You want a list of "includes" and a list of "excludes". Just have two
separate lists.
Actually, if we're effectively changing the ABI, why not make everyone's lives
simpler and expose that to userspace. E.g. use one of the "pad" words to specify
the number of "include" events and effectively do this:
struct kvm_pmu_event_filter {
__u32 action;
__u32 nevents;
__u32 fixed_counter_bitmap;
__u32 flags;
__u32 nr_include_events;
__u64 include[nr_include_events];
__u64 exclude[nevents - nr_allowed_events];
};
Then we don't need to steal a bit for "exclude" in the uABI. The kernel code
gets a wee bit simpler.
> @@ -693,6 +796,10 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp)
> /* Ensure nevents can't be changed between the user copies. */
> *filter = tmp;
>
> + r = -EINVAL;
> + if (!is_filter_valid(filter))
Do this in prepare_filter_events() to avoid walking the filter multiple times.
I've gotten fairly twisted around and my local copy of the code is a mess, but
something like this:
static int prepare_filter_events(struct kvm_pmu_event_filter *filter)
{
int i;
for (i = 0, j = 0; i < filter->nevents; i++) {
if (filter->events[i] & ~kvm_pmu_ops.EVENTSEL_MASK) {
if (!filter->mask)
continue;
if (<reserved bits set>)
return -EINVAL;
}
filter->events[j++] = filter->events[i];
}
<more magic here>
}
> + goto cleanup;
> +
> prepare_filter_events(filter);
>
> mutex_lock(&kvm->lock);
next prev parent reply other threads:[~2022-10-08 0:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 17:45 [PATCH v5 0/7] Introduce and test masked events Aaron Lewis
2022-09-20 17:45 ` [PATCH v5 1/7] kvm: x86/pmu: Correct the mask used in a pmu event filter lookup Aaron Lewis
2022-10-07 23:25 ` Sean Christopherson
2022-10-15 15:43 ` Aaron Lewis
2022-10-17 18:20 ` Sean Christopherson
2022-10-21 1:33 ` Aaron Lewis
2022-09-20 17:45 ` [PATCH v5 2/7] kvm: x86/pmu: Remove invalid raw events from the pmu event filter Aaron Lewis
2022-10-07 23:48 ` Sean Christopherson
2022-09-20 17:45 ` [PATCH v5 3/7] kvm: x86/pmu: prepare the pmu event filter for masked events Aaron Lewis
2022-10-08 0:08 ` Sean Christopherson
2022-09-20 17:46 ` [PATCH v5 4/7] kvm: x86/pmu: Introduce masked events to the pmu event filter Aaron Lewis
2022-10-08 0:37 ` Sean Christopherson [this message]
2022-10-10 15:42 ` Sean Christopherson
2022-10-15 15:43 ` Aaron Lewis
2022-10-17 17:47 ` Sean Christopherson
2022-10-19 1:06 ` Aaron Lewis
2022-10-21 1:33 ` Aaron Lewis
2022-10-21 17:50 ` Sean Christopherson
2022-09-20 17:46 ` [PATCH v5 5/7] selftests: kvm/x86: Add flags when creating a " Aaron Lewis
2022-09-20 17:46 ` [PATCH v5 6/7] selftests: kvm/x86: Add testing for KVM_SET_PMU_EVENT_FILTER Aaron Lewis
2022-09-20 17:56 ` Jim Mattson
2022-09-20 17:46 ` [PATCH v5 7/7] selftests: kvm/x86: Test masked events Aaron Lewis
2022-09-20 17:59 ` Jim Mattson
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=Y0DGNEvbmT3kWR56@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@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 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.