diff options
author | Aaron Lewis <aaronlewis@google.com> | 2022-05-17 05:12:36 +0000 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-05-20 07:06:29 -0400 |
commit | 4ac19ead0dfbabd8e0bfc731f507cfb0b95d6c99 (patch) | |
tree | 503f77d5e4605325356792e629b5544c4ab9c075 /arch/x86/kvm | |
parent | 6f5adb35045d1100b715aad864589b0c41040ff4 (diff) | |
download | linux-4ac19ead0dfbabd8e0bfc731f507cfb0b95d6c99.tar.bz2 |
kvm: x86/pmu: Fix the compare function used by the pmu event filter
When returning from the compare function the u64 is truncated to an
int. This results in a loss of the high nybble[1] in the event select
and its sign if that nybble is in use. Switch from using a result that
can end up being truncated to a result that can only be: 1, 0, -1.
[1] bits 35:32 in the event select register and bits 11:8 in the event
select.
Fixes: 7ff775aca48ad ("KVM: x86/pmu: Use binary search to check filtered events")
Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20220517051238.2566934-1-aaronlewis@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r-- | arch/x86/kvm/pmu.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index eca39f56c231..0604bc29f0b8 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -171,9 +171,12 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc) return true; } -static int cmp_u64(const void *a, const void *b) +static int cmp_u64(const void *pa, const void *pb) { - return *(__u64 *)a - *(__u64 *)b; + u64 a = *(u64 *)pa; + u64 b = *(u64 *)pb; + + return (a > b) - (a < b); } void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) |