kvm: x86/pmu: Fix the compare function used by the pmu event filter
authorAaron Lewis <aaronlewis@google.com>
Tue, 17 May 2022 05:12:36 +0000 (05:12 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 May 2022 07:59:11 +0000 (09:59 +0200)
commit3b419600856ddd61b2bae67fb8c75a03d5200b00
tree5afbd24b84ef9a3978f831677e17b1ade483eafe
parent7f9c8edddd5d1dc77933ae4c51fd22c04944484c
kvm: x86/pmu: Fix the compare function used by the pmu event filter

[ Upstream commit 4ac19ead0dfbabd8e0bfc731f507cfb0b95d6c99 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/kvm/pmu.c