All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] kvm: x86/pmu: Fix the compare function used by the pmu event filter
@ 2022-05-17  5:12 Aaron Lewis
  2022-05-17  5:12 ` [PATCH 2/3] selftests: kvm/x86: Add the helper function create_pmu_event_filter Aaron Lewis
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aaron Lewis @ 2022-05-17  5:12 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, jmattson, seanjc, Aaron Lewis

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>
---
 arch/x86/kvm/pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index eca39f56c231..1666e9d3e545 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -173,7 +173,7 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)
 
 static int cmp_u64(const void *a, const void *b)
 {
-	return *(__u64 *)a - *(__u64 *)b;
+	return (*(u64 *)a > *(u64 *)b) - (*(u64 *)a < *(u64 *)b);
 }
 
 void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
-- 
2.36.1.124.g0e6072fb45-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-18  0:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-17  5:12 [PATCH 1/3] kvm: x86/pmu: Fix the compare function used by the pmu event filter Aaron Lewis
2022-05-17  5:12 ` [PATCH 2/3] selftests: kvm/x86: Add the helper function create_pmu_event_filter Aaron Lewis
2022-05-17  5:12 ` [PATCH 3/3] selftests: kvm/x86: Verify the pmu event filter matches the correct event Aaron Lewis
2022-05-18  0:57 ` [PATCH 1/3] kvm: x86/pmu: Fix the compare function used by the pmu event filter Sean Christopherson

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.