Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp613848img; Fri, 22 Mar 2019 05:10:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJNUcJNzSAkDZHivQIOMK85/dpsPyatQIfP4nJdoHLw8VD5xGDYkNBDD/tuFQUNMWVE3Gj X-Received: by 2002:a63:6949:: with SMTP id e70mr8510549pgc.89.1553256653374; Fri, 22 Mar 2019 05:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553256653; cv=none; d=google.com; s=arc-20160816; b=Ds4oA85vAlpCXjZ43zJgtVINLD3H9rAmOQtipTy09AkOaRYrs420eEFHmtB5yINRSc D61ehZl3kzjJyTy1EpVI/fPOKlObJJMBfne5WHft37oza+fGrTeBdbuykvnefJS0KqMn Q8jFz0liRYNahWGuyvL+/AtTLvOJEw0L/GYhzFKdKmRWp+UlJ4xpScH2f7YFtPASq9ey TR5I0QIzg2id2+o0twb9hfwaPkz+2k/6wDRWUaokc6MDs7CVyaXrekj2vMlTjVzZXRAT u/h7aJvI0706fkwahZU+4DHy1+XSdfvN2feQaA4tM4H1eztD9Ur56f/eMi03ukBQSbQL KRoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D4JMEZHz82xW3qF3CSdMuSfGfdS7ri6ozb6HFir0EDY=; b=gV4GnXFENGkwVKs6lKdUkDkpa6c+D7rQgqY1poSNZDBTnUU2fpZ+pbEe4A8RPH01xV gifTueAnc2FdU0AVLiZuyGftlCk+DHD717CTllhbLK4gyT9FllaznB/Z8UFcpIkBizqm rtZmnTWFrkM6qDp4n0y+F3r7MoRpBy0Hspoon2Ha0en8oD+Q98/Sr6WuSRZEIsVbJIYq xzjro8MeEbEjQbcaRUX4NTsdHIksSg+vXfIt+CqnUAfUSBGvaqfsKmVGndIo8m7rnJX0 D1DfirQ9xzvdc68xBAVnHHeqr8sLC9RCWYekXgXfjPLBw/INu2M78Q+hcwfwby1dEMPo C/Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Roeyuo2I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8si6879837plk.67.2019.03.22.05.10.36; Fri, 22 Mar 2019 05:10:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Roeyuo2I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389162AbfCVMJv (ORCPT + 99 others); Fri, 22 Mar 2019 08:09:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:48280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388950AbfCVMJs (ORCPT ); Fri, 22 Mar 2019 08:09:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0D3BD21929; Fri, 22 Mar 2019 12:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256587; bh=O/Ewb3NjgTvEqvWEx8cTMJ63L8ci/XuWoTONZJyCCuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Roeyuo2I72WQx1XmXjlJgukGeB1W+l48WDrfF5Nw8bDD4fuFj1yFwOjieVY8jo1ZH HCt4PFZ/imEmV52+d2ZTJha2kBpaqfzLIALxBF6W9IzlW2qFN91bJB7HmEioguNjgB OE7T2z2ObpX8sbDqUOVXEM0yFWq8BpQXHAFrmGPk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jin Yao , Kan Liang , "Peter Zijlstra (Intel)" , Alexander Shishkin , Andy Lutomirski , Arnaldo Carvalho de Melo , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Jiri Olsa , Linus Torvalds , Rik van Riel , Stephane Eranian , Thomas Gleixner , Vince Weaver , Ingo Molnar , stable@kernel.org Subject: [PATCH 4.19 257/280] perf/x86/intel/uncore: Fix client IMC events return huge result Date: Fri, 22 Mar 2019 12:16:50 +0100 Message-Id: <20190322111343.254840591@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111306.356185024@linuxfoundation.org> References: <20190322111306.356185024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kan Liang commit 8041ffd36f42d8521d66dd1e236feb58cecd68bc upstream. The client IMC bandwidth events currently return very large values: $ perf stat -e uncore_imc/data_reads/ -e uncore_imc/data_writes/ -I 10000 -a 10.000117222 34,788.76 MiB uncore_imc/data_reads/ 10.000117222 8.26 MiB uncore_imc/data_writes/ 20.000374584 34,842.89 MiB uncore_imc/data_reads/ 20.000374584 10.45 MiB uncore_imc/data_writes/ 30.000633299 37,965.29 MiB uncore_imc/data_reads/ 30.000633299 323.62 MiB uncore_imc/data_writes/ 40.000891548 41,012.88 MiB uncore_imc/data_reads/ 40.000891548 6.98 MiB uncore_imc/data_writes/ 50.001142480 1,125,899,906,621,494.75 MiB uncore_imc/data_reads/ 50.001142480 6.97 MiB uncore_imc/data_writes/ The client IMC events are freerunning counters. They still use the old event encoding format (0x1 for data_read and 0x2 for data write). The counter bit width is calculated by common code, which assume that the standard encoding format is used for the freerunning counters. Error bit width information is calculated. The patch intends to convert the old client IMC event encoding to the standard encoding format. Current common code uses event->attr.config which directly copy from user space. We should not implicitly modify it for a converted event. The event->hw.config is used to replace the event->attr.config in common code. For client IMC events, the event->attr.config is used to calculate a converted event with standard encoding format in the custom event_init(). The converted event is stored in event->hw.config. For other events of freerunning counters, they already use the standard encoding format. The same value as event->attr.config is assigned to event->hw.config in common event_init(). Reported-by: Jin Yao Tested-by: Jin Yao Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Andy Lutomirski Cc: Arnaldo Carvalho de Melo Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rik van Riel Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: stable@kernel.org # v4.18+ Fixes: 9aae1780e7e8 ("perf/x86/intel/uncore: Clean up client IMC uncore") Link: https://lkml.kernel.org/r/20190227165729.1861-1-kan.liang@linux.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/uncore.c | 1 + arch/x86/events/intel/uncore.h | 12 ++++++------ arch/x86/events/intel/uncore_snb.c | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -740,6 +740,7 @@ static int uncore_pmu_event_init(struct /* fixed counters have event field hardcoded to zero */ hwc->config = 0ULL; } else if (is_freerunning_event(event)) { + hwc->config = event->attr.config; if (!check_valid_freerunning_event(box, event)) return -EINVAL; event->hw.idx = UNCORE_PMC_IDX_FREERUNNING; --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -285,8 +285,8 @@ static inline unsigned int uncore_freerunning_counter(struct intel_uncore_box *box, struct perf_event *event) { - unsigned int type = uncore_freerunning_type(event->attr.config); - unsigned int idx = uncore_freerunning_idx(event->attr.config); + unsigned int type = uncore_freerunning_type(event->hw.config); + unsigned int idx = uncore_freerunning_idx(event->hw.config); struct intel_uncore_pmu *pmu = box->pmu; return pmu->type->freerunning[type].counter_base + @@ -360,7 +360,7 @@ static inline unsigned int uncore_freerunning_bits(struct intel_uncore_box *box, struct perf_event *event) { - unsigned int type = uncore_freerunning_type(event->attr.config); + unsigned int type = uncore_freerunning_type(event->hw.config); return box->pmu->type->freerunning[type].bits; } @@ -368,7 +368,7 @@ unsigned int uncore_freerunning_bits(str static inline int uncore_num_freerunning(struct intel_uncore_box *box, struct perf_event *event) { - unsigned int type = uncore_freerunning_type(event->attr.config); + unsigned int type = uncore_freerunning_type(event->hw.config); return box->pmu->type->freerunning[type].num_counters; } @@ -382,8 +382,8 @@ static inline int uncore_num_freerunning static inline bool check_valid_freerunning_event(struct intel_uncore_box *box, struct perf_event *event) { - unsigned int type = uncore_freerunning_type(event->attr.config); - unsigned int idx = uncore_freerunning_idx(event->attr.config); + unsigned int type = uncore_freerunning_type(event->hw.config); + unsigned int idx = uncore_freerunning_idx(event->hw.config); return (type < uncore_num_freerunning_types(box, event)) && (idx < uncore_num_freerunning(box, event)); --- a/arch/x86/events/intel/uncore_snb.c +++ b/arch/x86/events/intel/uncore_snb.c @@ -444,9 +444,11 @@ static int snb_uncore_imc_event_init(str /* must be done before validate_group */ event->hw.event_base = base; - event->hw.config = cfg; event->hw.idx = idx; + /* Convert to standard encoding format for freerunning counters */ + event->hw.config = ((cfg - 1) << 8) | 0x10ff; + /* no group validation needed, we have free running counters */ return 0;