From nobody Tue Dec 16 11:44:02 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BA05C28B2B for ; Fri, 19 Aug 2022 16:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354429AbiHSQxi (ORCPT ); Fri, 19 Aug 2022 12:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354645AbiHSQv3 (ORCPT ); Fri, 19 Aug 2022 12:51:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E02741156FD; Fri, 19 Aug 2022 09:14:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DF8B9B8280D; Fri, 19 Aug 2022 16:13:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BA9BC433D6; Fri, 19 Aug 2022 16:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925615; bh=WbEMAlrawh08q0dXgHD22Zl1G6evzjYEaZ+pVq1Yp3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vWHu1/ExxdPFOoelkl8QV1P5BV+AToHosGjfL455es+BifeaUpb+VAoXnRty6/Rvq KAtvl8kKvNMcw8s3sQw/PbATtjqaBbEmAd3Lr347js/k4qGVWcaWa8NSNeWRLnNSpn nLNjfSCmbRtogx3ra9YFeLUXDYQ0QWSViApbYKV4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaron Lewis , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.10 539/545] kvm: x86/pmu: Fix the compare function used by the pmu event filter Date: Fri, 19 Aug 2022 17:45:09 +0200 Message-Id: <20220819153853.713095678@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Aaron Lewis commit 4ac19ead0dfbabd8e0bfc731f507cfb0b95d6c99 upstream. 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 ev= ents") Signed-off-by: Aaron Lewis Reviewed-by: Sean Christopherson Message-Id: <20220517051238.2566934-1-aaronlewis@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/pmu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -170,9 +170,12 @@ static bool pmc_resume_counter(struct kv return true; } =20 -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 =3D *(u64 *)pa; + u64 b =3D *(u64 *)pb; + + return (a > b) - (a < b); } =20 void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)