Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3689268lfo; Mon, 23 May 2022 11:31:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzDNRg9xNfyR7iyd0bGfIGed0BOgff9A3L6q/nxcb5bgeTt9u5ltoqsbPjvbuED5jhPSRQ X-Received: by 2002:a17:90b:1955:b0:1df:a48e:4597 with SMTP id nk21-20020a17090b195500b001dfa48e4597mr293789pjb.187.1653330665007; Mon, 23 May 2022 11:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330665; cv=none; d=google.com; s=arc-20160816; b=wER7fprRiP1fxjIWtdOv4UwvRAaIJ24ptc289XNmUouZL3OYZdU2nfFPK5keqsq9HP uz+UpJXbDJZBUheLhz8lMnJ15CEc/HdF0mMSp1F5zedbtpOmRTZRP1hnqLrgnoMJnlrd fe7RPXPc4ig2XRyKELTkC+V3kar7/oZRR/K5YLxvEps5a1Ql70esIaPL0ojdOu3KEcto J9LAPwM39DCcuCtQIPl5xHiOYLhjOjKdaRIBJMmK5ZhJxpqsEes9WQ55KEDMqNY8Hd+c tv53PGOYS5Yub5dXkCSEEZI3zcng+c6JEv+bPGj6Ybd47lZVDi97criTudi+taFRmNGb cmgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fFgSKO3sZWYvRwcIZ55kVIytirzSMT/txlIyCcYePGQ=; b=vptpyAEy8zze3cVnzgAlQ4I8YqL+Rqz6wZL3owK6Q0AzTrl/OliyuitFLlWH4+VS94 Ai72s8/uuLyuqUqOFn5dezdS9ffWrdB5TlbkDjjGT6fwENoyM+/W9DgTpy5uSqIc572a pCmNEzV8LbGfvlkveU1F29lzwoMi8O0cf8vWh1Qi+w4BKZYR/K8++tNU5G3Ai11/7ZPB 0CDgESspcmPZ5VG9Zlh+9fUyiqHBKHyqK9y9dXD0WE7dBwHVuFIVoVym2as+1vApu6PZ bMVZlQjkwIQK1qfQJW0eUqCYkGsy95pHzTi6SPiC3ehez/AhsRdOeOsOTY8M88Ty+9gr VVsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h61YY2SM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z16-20020aa78890000000b00518c539ce57si39986pfe.303.2022.05.23.11.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:31:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h61YY2SM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E1DF140402; Mon, 23 May 2022 11:30:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244190AbiEWSGV (ORCPT + 99 others); Mon, 23 May 2022 14:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243146AbiEWRhy (ORCPT ); Mon, 23 May 2022 13:37:54 -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 4311A7A47E; Mon, 23 May 2022 10:32:10 -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 C3AFCB81201; Mon, 23 May 2022 17:30:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 240C6C34115; Mon, 23 May 2022 17:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653327001; bh=EpJkC7kTnHmaFTqFlnkMeVZeMzfMC+I02j0S0pN1mms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h61YY2SMxxabvj++fqHFAQD08YONpvAnYidq0LfHiHzVxv7Gbc1dk4CmEt6CPFzoN N6yvswW0YxYEA7Sjjjb/R2pbweXrxVqyB9/ydTrvJCrUGNmWRTYB2M8tyEi8g/tDvo z3myaVj88QkQrfGZd4W/bcaJwbJ/auWRUKmPBqoo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaron Lewis , Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.17 124/158] kvm: x86/pmu: Fix the compare function used by the pmu event filter Date: Mon, 23 May 2022 19:04:41 +0200 Message-Id: <20220523165851.232347554@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165830.581652127@linuxfoundation.org> References: <20220523165830.581652127@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aaron Lewis [ 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 Reviewed-by: Sean Christopherson Message-Id: <20220517051238.2566934-1-aaronlewis@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/pmu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index eca39f56c231..0604bc29f0b8 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -171,9 +171,12 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc) return true; } -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 = *(u64 *)pa; + u64 b = *(u64 *)pb; + + return (a > b) - (a < b); } void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) -- 2.35.1