Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp797580pxb; Tue, 12 Apr 2022 13:44:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4njAp6Vh56K8G9ppqNoZyD/iyewm/KfptpNzHaOcg4qesukHYArPd8ocoaB4FqclpXyO4 X-Received: by 2002:a17:903:120c:b0:154:c135:60d3 with SMTP id l12-20020a170903120c00b00154c13560d3mr39107539plh.48.1649796280135; Tue, 12 Apr 2022 13:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649796280; cv=none; d=google.com; s=arc-20160816; b=hFrKiklmr8gOjNGMiQankIP4QdBYv9j2N8kbOy3M6bJAAYnJGSwnNhhWOkQcxZQeBs kU+mkm1RaG26IzgKMpsQEqBwf99NlRuuETbWmgstKiuULBCp+xUURq+qK2j4XB2ssOJj 3reVeo24BwqaiIIFik12Oky9sWOjlQajnAjBPyHvjIXgz56KG1/Vp5M861Z4mEl2QnbR Ll396blilMK6LNQWXzShv/fu85YzboI+2uVhMdMZi90UVm/+1HD+FCOp6zMeQWJscoyd bpGB3mn33+U7lF8vipZvOOoABIBUc4loihV2gnzfiCsEwyWrLDLU5VZYAF5S7Kl7Gwn/ 5LVg== 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=UmNyaMK4bFew/PWcRyv4X4/6eoTpeVHRgk0kJVklvk8=; b=AiVgLlMyNnr42gC6bHn7ct+45VplYxGHrFixDKxhrfaSsntsF3K6BdXrXnppvan5Vq zKU0N+xbYn9c+6AWDPSExYLQYmaxPoJmt1JbqTUQvIrPsiHwSHGX0UiCypBkAKaz56s1 oUV+kBZ1FiiHOOWiiDrUU8ku8/J75LROI8qQXkXKHYGM+FioESWO4PSPsKfU9kg/9/Yu QNk5wiYZ7sh5m4gN+xtdJw78JJr0KGc73IG8T6K+UyDM+KtBot3wx06geIXoPb2vazbl WUMnoee8OdUWbDVxp3p+pHatcs+4d3O8zVinQ6lOtWeTWZBGih6obEPt1ilK9kflBiTz jhmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="2bcEbQq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c9-20020a056a000ac900b004fa3a8e004asi13758447pfl.257.2022.04.12.13.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:44:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="2bcEbQq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 4CAC7BCB4A; Tue, 12 Apr 2022 13:14:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354879AbiDLIGL (ORCPT + 99 others); Tue, 12 Apr 2022 04:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354029AbiDLH0A (ORCPT ); Tue, 12 Apr 2022 03:26:00 -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 9707215722; Tue, 12 Apr 2022 00:05:24 -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 9BBD5B81B4D; Tue, 12 Apr 2022 07:05:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA116C385A6; Tue, 12 Apr 2022 07:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649747122; bh=yqQ8br7MQ3MrgXQimt529wUVNzkOSYPYS0M367HdvJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2bcEbQq/S3Wp3sTnywYSEHs4+bBeRcO7hEuHc8pjC21AfEb3l65FAnenLgkST1sNK 3FnbjzcvQiW907WjJxSemqtwf5/fSdqVtqdTDsEutAU9E/KxR7tuFHjDivFTJ3K49D teLKHSnM+kIvoP9dGwP/Utn6NlKDnobkGAWM2V4A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kan Liang , "Peter Zijlstra (Intel)" Subject: [PATCH 5.16 244/285] perf/x86/intel: Dont extend the pseudo-encoding to GP counters Date: Tue, 12 Apr 2022 08:31:41 +0200 Message-Id: <20220412062950.703096996@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062943.670770901@linuxfoundation.org> References: <20220412062943.670770901@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.0 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=no 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: Kan Liang commit 4a263bf331c512849062805ef1b4ac40301a9829 upstream. The INST_RETIRED.PREC_DIST event (0x0100) doesn't count on SPR. perf stat -e cpu/event=0xc0,umask=0x0/,cpu/event=0x0,umask=0x1/ -C0 Performance counter stats for 'CPU(s) 0': 607,246 cpu/event=0xc0,umask=0x0/ 0 cpu/event=0x0,umask=0x1/ The encoding for INST_RETIRED.PREC_DIST is pseudo-encoding, which doesn't work on the generic counters. However, current perf extends its mask to the generic counters. The pseudo event-code for a fixed counter must be 0x00. Check and avoid extending the mask for the fixed counter event which using the pseudo-encoding, e.g., ref-cycles and PREC_DIST event. With the patch, perf stat -e cpu/event=0xc0,umask=0x0/,cpu/event=0x0,umask=0x1/ -C0 Performance counter stats for 'CPU(s) 0': 583,184 cpu/event=0xc0,umask=0x0/ 583,048 cpu/event=0x0,umask=0x1/ Fixes: 2de71ee153ef ("perf/x86/intel: Fix ICL/SPR INST_RETIRED.PREC_DIST encodings") Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1648482543-14923-1-git-send-email-kan.liang@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/core.c | 6 +++++- arch/x86/include/asm/perf_event.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5521,7 +5521,11 @@ static void intel_pmu_check_event_constr /* Disabled fixed counters which are not in CPUID */ c->idxmsk64 &= intel_ctrl; - if (c->idxmsk64 != INTEL_PMC_MSK_FIXED_REF_CYCLES) + /* + * Don't extend the pseudo-encoding to the + * generic counters + */ + if (!use_fixed_pseudo_encoding(c->code)) c->idxmsk64 |= (1ULL << num_counters) - 1; } c->idxmsk64 &= --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -241,6 +241,11 @@ struct x86_pmu_capability { #define INTEL_PMC_IDX_FIXED_SLOTS (INTEL_PMC_IDX_FIXED + 3) #define INTEL_PMC_MSK_FIXED_SLOTS (1ULL << INTEL_PMC_IDX_FIXED_SLOTS) +static inline bool use_fixed_pseudo_encoding(u64 code) +{ + return !(code & 0xff); +} + /* * We model BTS tracing as another fixed-mode PMC. *