Skip to content

Commit 4ac19ea

Browse files
suomilewisbonzini
authored andcommitted
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: 7ff775a ("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>
1 parent 6f5adb3 commit 4ac19ea

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

arch/x86/kvm/pmu.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,12 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)
171171
return true;
172172
}
173173

174-
static int cmp_u64(const void *a, const void *b)
174+
static int cmp_u64(const void *pa, const void *pb)
175175
{
176-
return *(__u64 *)a - *(__u64 *)b;
176+
u64 a = *(u64 *)pa;
177+
u64 b = *(u64 *)pb;
178+
179+
return (a > b) - (a < b);
177180
}
178181

179182
void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)

0 commit comments

Comments
 (0)