From: Sean Christopherson <seanjc@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com
Subject: Re: [PATCH 1/3] kvm: x86/pmu: Fix the compare function used by the pmu event filter
Date: Wed, 18 May 2022 00:57:14 +0000 [thread overview]
Message-ID: <YoREatFTrxJVcfHg@google.com> (raw)
In-Reply-To: <20220517051238.2566934-1-aaronlewis@google.com>
On Tue, May 17, 2022, Aaron Lewis wrote:
> 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);
On one hand, this is downright evil. On the other, it does generate branch-free
code, whereas gcc does not for explicit returns...
It's a little easier to read if the values are captured in local variables?
u64 l = *(u64 *)a;
u64 r = *(u64 *)b;
return (l > r) - (l < r);
Either way,
Reviewed-by: Sean Christopherson <seanjc@google.com>
prev parent reply other threads:[~2022-05-18 0:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Sean Christopherson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YoREatFTrxJVcfHg@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.