Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3869183pxb; Mon, 21 Feb 2022 07:18:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2CdPt2ROl6eI898tbTTnKyGnFbankIBECG6B6TLiAyhd0LvySaGOPqRAhggVepcT3ozPQ X-Received: by 2002:a17:902:ea08:b0:14b:e74:d7bd with SMTP id s8-20020a170902ea0800b0014b0e74d7bdmr19545540plg.126.1645456732095; Mon, 21 Feb 2022 07:18:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645456732; cv=none; d=google.com; s=arc-20160816; b=ra+TX8S0IM697MZ1FTWDiQqXj1G+WQy0n9q6UhmR/1PQ0hCFv9C+/Pd7j9hDV7a2RE oRsrKEu+4rNSyhVRoeG/8aBGMJagJ4XCapyRvYvoJjpu3PfnMt8WsQ6+We3Kb6u70nEn pvBgdsHrVTVaVSPgOdBfiKLTh+Y6Oc6z0kzeDkO7EK/7gHFGm4u4gcwY2PFpTtlH4Awx EAW9hPj1LgUAvT6JwRw/OKHe5Zv2jcG0NmckJ5TiFcY256V5DACWH/03FRRscLQIaD5A JWQORcTy5fGYNzK9r4NXQI6/S1r9s5fdnxPqQ9EesiGJG4/b3htBVXr2JiV5AyzVncJN +zSw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mhtKDiOsLT1DFVkDtSR/HqZI5hm/yp+9fh0AF9ZzPSE=; b=KNFMh7viG2Ytk/MeSSCFbXIxfN69nEv6XEwU7yLlm3WKeRA88VfORTU/mo9/ZVX2PG oRZXPhQUi8Rdg1YUFZ2befscUuGJoU4vJmmljdJdfIN6IbNygjeT5sofIP0GmKkGJ/// +Ir5mzZ06n0qGGgdqlZ2L7dICl7HVTD9UYH1z7aGO62y1aVlIMrkXm1/eScToBAUWT+w wOGBCJgwUkryWXoIVlCG+ERv8RJUyRAN8N1MGcd47bCz1Phg6QG3v6iK1Iet60/ofsxV ZDQ/TH7NfBiOfYf9kqijXMnzsKHA/63GEEZLnSB5593fLcu32dD3sRs54MJVFIp1btWx 29Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HzvfHmXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p23si18001536pgn.300.2022.02.21.07.18.35; Mon, 21 Feb 2022 07:18:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HzvfHmXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357053AbiBULxa (ORCPT + 99 others); Mon, 21 Feb 2022 06:53:30 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356967AbiBULxX (ORCPT ); Mon, 21 Feb 2022 06:53:23 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D1620197; Mon, 21 Feb 2022 03:52:40 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id m1-20020a17090a668100b001bc023c6f34so4807230pjj.3; Mon, 21 Feb 2022 03:52:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mhtKDiOsLT1DFVkDtSR/HqZI5hm/yp+9fh0AF9ZzPSE=; b=HzvfHmXZ10Z3fPpJMxzWMvs/cq9Ow90nVAhjDzhlQFBpuENLsPNcjq7kGEw3uJPFNM 6RJ1hJCBw0EiCAwEfZh5ok8pAh84dRvDh95OKDfBUOWEGoHErxWWwBe5t0dEZ1dtw0km Z7gb4pslxFor4OCr6T7Ceam1vAYLsuiBY5F8GYdtyCSInlaoGt6KN1+0Zp+S9rZ06FDc xjBGaf8PPdj8txfrko6KQEOBBDlw3Mvy7maZjZAhmI7RtMqlVRRYEt9Aep/f8nbXBMIw cK5ISMBDvMF/+wz4SBxqYAj/KLwyqO2vRZKturvYm68W8cmvuulsmu1QiwRnRQgbynu0 YmVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mhtKDiOsLT1DFVkDtSR/HqZI5hm/yp+9fh0AF9ZzPSE=; b=ma/iGNPu22D7zDlzgzaAjYtDNr4lwNsr6IxoT+j1wWdq48mai6w83kOomrz08eMZ3G eZk2yMgd5E10NJm6WuWDyyeFXTXi99ZKCLYZWYzxRWCIh12TAAPuXZSyGjXQ1c53Yaif r6W0U/HEV7G2uk3VnyoBix3ovrZ5Hb6lbPknb55vfWARsbF0TQOi9aQmrqkevqlTRhqr +EiCVbsSZne3myqFLGWEil3yaf+gb7Rq2/yu/O+/Wx1EjM+yWsnB0FSvktwgBdI27km9 Af5Kt2gHuecvtaF/xPArx9ga3ug7O6ffX1L5rb1u/jzjfnWsGYEnUDtO4Ov/otyYl+6n GA2Q== X-Gm-Message-State: AOAM532RucQfRBNRH8KoHhGCe32NBsU0JDNE25qMycrmyiCpisTMpxNX vBSuT9ss34YtiFs0U5aqVJ4= X-Received: by 2002:a17:902:8d84:b0:14f:83f2:8c0d with SMTP id v4-20020a1709028d8400b0014f83f28c0dmr11898579plo.110.1645444359800; Mon, 21 Feb 2022 03:52:39 -0800 (PST) Received: from localhost.localdomain ([103.7.29.32]) by smtp.gmail.com with ESMTPSA id z14sm13055011pfe.30.2022.02.21.03.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:52:39 -0800 (PST) From: Like Xu X-Google-Original-From: Like Xu To: Paolo Bonzini , Jim Mattson Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH 09/11] KVM: x86/pmu: Replace pmc_perf_hw_id() with perf_get_hw_event_config() Date: Mon, 21 Feb 2022 19:51:59 +0800 Message-Id: <20220221115201.22208-10-likexu@tencent.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220221115201.22208-1-likexu@tencent.com> References: <20220221115201.22208-1-likexu@tencent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Like Xu With the help of perf_get_hw_event_config(), KVM could query the correct EVENTSEL_{EVENT, UMASK} pair of a kernel-generic hw event directly from the different *_perfmon_event_map[] by the kernel's pre-defined perf_hw_id. Also extend the bit range of the comparison field to AMD64_RAW_EVENT_MASK_NB to prevent AMD from defining EventSelect[11:8] into perfmon_event_map[] one day. Signed-off-by: Like Xu --- arch/x86/kvm/pmu.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index edd51ec7711d..a6bfcbd3412d 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -468,13 +468,8 @@ static void kvm_pmu_incr_counter(struct kvm_pmc *pmc) static inline bool eventsel_match_perf_hw_id(struct kvm_pmc *pmc, unsigned int perf_hw_id) { - u64 old_eventsel = pmc->eventsel; - unsigned int config; - - pmc->eventsel &= (ARCH_PERFMON_EVENTSEL_EVENT | ARCH_PERFMON_EVENTSEL_UMASK); - config = kvm_x86_ops.pmu_ops->pmc_perf_hw_id(pmc); - pmc->eventsel = old_eventsel; - return config == perf_hw_id; + return !((pmc->eventsel ^ perf_get_hw_event_config(perf_hw_id)) && + AMD64_RAW_EVENT_MASK_NB); } static inline bool cpl_is_matched(struct kvm_pmc *pmc) -- 2.35.0