KVM: x86/pmu: Check eventsel first when emulating (branch) insns retired
authorSean Christopherson <seanjc@google.com>
Fri, 10 Nov 2023 02:28:56 +0000 (18:28 -0800)
committerSean Christopherson <seanjc@google.com>
Thu, 1 Feb 2024 17:35:48 +0000 (09:35 -0800)
commite35529fb4ac930a4a39e0c15bafcb28a30d26611
tree27ef009c0846b25be27ccc2fcd14a9b7272cf475
parentafda2d7666f894d1d7b8406cf54801e6c11f63c2
KVM: x86/pmu: Check eventsel first when emulating (branch) insns retired

When triggering events, i.e. emulating PMC events in software, check for
a matching event selector before checking the event is allowed.  The "is
allowed" check *might* be cheap, but it could also be very costly, e.g. if
userspace has defined a large PMU event filter.  The event selector check
on the other hand is all but guaranteed to be <10 uops, e.g. looks
something like:

   0xffffffff8105e615 <+5>: movabs $0xf0000ffff,%rax
   0xffffffff8105e61f <+15>: xor    %rdi,%rsi
   0xffffffff8105e622 <+18>: test   %rax,%rsi
   0xffffffff8105e625 <+21>: sete   %al

Link: https://lore.kernel.org/r/20231110022857.1273836-10-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/pmu.c