mbox series

[v8,0/7] Introduce and test masked events

Message ID 20221220161236.555143-1-aaronlewis@google.com (mailing list archive)
Headers show
Series Introduce and test masked events | expand

Message

Aaron Lewis Dec. 20, 2022, 4:12 p.m. UTC
This series introduces the concept of masked events to the pmu event
filter. Masked events can help reduce the number of events needed in the
pmu event filter by allowing a more generalized matching method to be
used for the unit mask when filtering guest events in the pmu.  With
masked events, if an event select should be restricted from the guest,
instead of having to add an entry to the pmu event filter for each
event select + unit mask pair, a masked event can be added to generalize
the unit mask values.

Reviewed-by: Sean Christopherson <seanjc@google.com>

v7 -> v8
 - Rebased on top of the latest in kvm/queue.
 - s/num_gp_counters/X86_PROPERTY_PMU_NR_GP_COUNTERS/ in the masked
   events test.

v6 -> v7
 - Rebased on top of the latest in kvm/queue. [Like]
 - Patch #7, Added comment about how counters value are used. [Sean]

v5 -> v6
 - The following changes were based on Sean's feedback.
 - Patch #1, Use a const for EVENTSEL_EVENT rather than a callback.
 - Patch #2, s/invalid/impossible and removed helpers.
 - Patch #3, Ditched internal event struct.  Sticking with arch layout.
 - Patch #4,
     - Switched masked events to follow arch layout.
     - Created an internal struct for the pmu event filter.
     - Track separate lists for include events and exclude events.
     - General refactors as a result of these changes.

v4 -> v5
 - Patch #3, Simplified the return logic in filter_contains_match(). [Jim]
 - Patch #4, Corrected documentation for errors and returns. [Jim]
 - Patch #6, Added TEST_REQUIRE for KVM_CAP_PMU_EVENT_MASKED_EVENTS. [Jim]
 - Patch #7,
     - Removed TEST_REQUIRE for KVM_CAP_PMU_EVENT_MASKED_EVENTS (moved it
       to patch #6).
     - Changed the assert to a branch in supports_event_mem_inst_retired().
       [Jim]
     - Added a check to make sure 3 GP counters are available. [Jim]

v3 -> v4
 - Patch #1, Fix the mask for the guest event select used in bsearch.
 - Patch #2, Remove invalid events from the pmu event filter.
 - Patch #3, Create an internal/common representation for filter events.
 - Patch #4,
     - Use a common filter event to simplify kernel code. [Jim]
     - s/invalid/exclude for masked events. More descriptive. [Sean]
     - Simplified masked event layout. There was no need to complicate it.
     - Add KVM_CAP_PMU_EVENT_MASKED_EVENTS.
 - Patch #7, Rewrote the masked events tests using MEM_INST_RETIRED (0xd0)
   on Intel and LS Dispatch (0x29) on AMD. They have multiple unit masks
   each which were leveraged for improved masked events testing.

v2 -> v3
 - Reworked and documented the invert flag usage.  It was possible to
   get ambiguous results when using it.  That should not be possible
   now.
 - Added testing for inverted masked events to validate the updated
   implementation.
 - Removed testing for inverted masked events from the masked events test.
   They were meaningless with the updated implementation.  More meaning
   tests were added separately.

v1 -> v2
 - Made has_invalid_event() static to fix warning.
 - Fixed checkpatch.pl errors and warnings.
 - Updated to account for KVM_X86_PMU_OP().

Aaron Lewis (7):
  kvm: x86/pmu: Correct the mask used in a pmu event filter lookup
  kvm: x86/pmu: Remove impossible events from the pmu event filter
  kvm: x86/pmu: prepare the pmu event filter for masked events
  kvm: x86/pmu: Introduce masked events to the pmu event filter
  selftests: kvm/x86: Add flags when creating a pmu event filter
  selftests: kvm/x86: Add testing for KVM_SET_PMU_EVENT_FILTER
  selftests: kvm/x86: Test masked events

 Documentation/virt/kvm/api.rst                |  77 +++-
 arch/x86/include/asm/kvm_host.h               |  14 +-
 arch/x86/include/uapi/asm/kvm.h               |  29 ++
 arch/x86/kvm/pmu.c                            | 241 +++++++++--
 arch/x86/kvm/pmu.h                            |   2 +
 arch/x86/kvm/svm/pmu.c                        |   1 +
 arch/x86/kvm/vmx/pmu_intel.c                  |   1 +
 arch/x86/kvm/x86.c                            |   1 +
 include/uapi/linux/kvm.h                      |   1 +
 .../kvm/x86_64/pmu_event_filter_test.c        | 381 +++++++++++++++++-
 10 files changed, 697 insertions(+), 51 deletions(-)

Comments

Sean Christopherson Jan. 19, 2023, 8:57 p.m. UTC | #1
On Tue, 20 Dec 2022 16:12:29 +0000, Aaron Lewis wrote:
> This series introduces the concept of masked events to the pmu event
> filter. Masked events can help reduce the number of events needed in the
> pmu event filter by allowing a more generalized matching method to be
> used for the unit mask when filtering guest events in the pmu.  With
> masked events, if an event select should be restricted from the guest,
> instead of having to add an entry to the pmu event filter for each
> event select + unit mask pair, a masked event can be added to generalize
> the unit mask values.
> 
> [...]

Applied to kvm-x86 pmu, thanks!

[1/7] kvm: x86/pmu: Correct the mask used in a pmu event filter lookup
      https://github.com/kvm-x86/linux/commit/aa570a7481c3
[2/7] kvm: x86/pmu: Remove impossible events from the pmu event filter
      https://github.com/kvm-x86/linux/commit/778e86e3a2fd
[3/7] kvm: x86/pmu: prepare the pmu event filter for masked events
      https://github.com/kvm-x86/linux/commit/11794a3da07f
[4/7] kvm: x86/pmu: Introduce masked events to the pmu event filter
      https://github.com/kvm-x86/linux/commit/651daa44b11c
[5/7] selftests: kvm/x86: Add flags when creating a pmu event filter
      https://github.com/kvm-x86/linux/commit/6a6b17a7c594
[6/7] selftests: kvm/x86: Add testing for KVM_SET_PMU_EVENT_FILTER
      https://github.com/kvm-x86/linux/commit/b1a865796643
[7/7] selftests: kvm/x86: Test masked events
      https://github.com/kvm-x86/linux/commit/5ed12ae83c4c

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes
Sean Christopherson Jan. 20, 2023, 6:11 p.m. UTC | #2
On Thu, Jan 19, 2023, Sean Christopherson wrote:
> On Tue, 20 Dec 2022 16:12:29 +0000, Aaron Lewis wrote:
> > This series introduces the concept of masked events to the pmu event
> > filter. Masked events can help reduce the number of events needed in the
> > pmu event filter by allowing a more generalized matching method to be
> > used for the unit mask when filtering guest events in the pmu.  With
> > masked events, if an event select should be restricted from the guest,
> > instead of having to add an entry to the pmu event filter for each
> > event select + unit mask pair, a masked event can be added to generalize
> > the unit mask values.
> > 
> > [...]
> 
> Applied to kvm-x86 pmu, thanks!
> 
> [1/7] kvm: x86/pmu: Correct the mask used in a pmu event filter lookup
>       https://github.com/kvm-x86/linux/commit/aa570a7481c3
> [2/7] kvm: x86/pmu: Remove impossible events from the pmu event filter
>       https://github.com/kvm-x86/linux/commit/778e86e3a2fd
> [3/7] kvm: x86/pmu: prepare the pmu event filter for masked events
>       https://github.com/kvm-x86/linux/commit/11794a3da07f
> [4/7] kvm: x86/pmu: Introduce masked events to the pmu event filter
>       https://github.com/kvm-x86/linux/commit/651daa44b11c
> [5/7] selftests: kvm/x86: Add flags when creating a pmu event filter
>       https://github.com/kvm-x86/linux/commit/6a6b17a7c594
> [6/7] selftests: kvm/x86: Add testing for KVM_SET_PMU_EVENT_FILTER
>       https://github.com/kvm-x86/linux/commit/b1a865796643
> [7/7] selftests: kvm/x86: Test masked events
>       https://github.com/kvm-x86/linux/commit/5ed12ae83c4c

FYI, I forced pushed to pmu to fix a minor warning in the docs and decided to
opportunistically update all of the shortlogs to fix (again minor) issues with
the scope since this series is currently the only thing sitting in pmu.

[1/7] KVM: x86/pmu: Correct the mask used in a pmu event filter lookup
      https://github.com/kvm-x86/linux/commit/1d2489485e28
[2/7] KVM: x86/pmu: Remove impossible events from the pmu event filter
      https://github.com/kvm-x86/linux/commit/1110a9128858
[3/7] KVM: x86/pmu: prepare the pmu event filter for masked events
      https://github.com/kvm-x86/linux/commit/3b049af387c4
[4/7] KVM: x86/pmu: Introduce masked events to the pmu event filter
      https://github.com/kvm-x86/linux/commit/22f39725f0f6
[5/7] KVM: selftests: Add flags when creating a pmu event filter
      https://github.com/kvm-x86/linux/commit/963fd783390f
[6/7] KVM: selftests: Add testing for KVM_SET_PMU_EVENT_FILTER
      https://github.com/kvm-x86/linux/commit/1c1045925ed4
[7/7] KVM: selftests: Test masked events in PMU filter
      https://github.com/kvm-x86/linux/commit/526d9f600225