From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=2Nly=TJ=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-16.5 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,
	DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,
	SIGNED_OFF_BY,SPF_PASS,T_DKIMWL_WL_MED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL
	autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id CBBBDC04AB1
	for <linux-kernel@archiver.kernel.org>; Thu,  9 May 2019 21:46:11 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by mail.kernel.org (Postfix) with ESMTP id 993DB217D7
	for <linux-kernel@archiver.kernel.org>; Thu,  9 May 2019 21:46:11 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="evtcUmo5"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726907AbfEIVqK (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Thu, 9 May 2019 17:46:10 -0400
Received: from mail-pl1-f202.google.com ([209.85.214.202]:35832 "EHLO
        mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1726219AbfEIVqJ (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Thu, 9 May 2019 17:46:09 -0400
Received: by mail-pl1-f202.google.com with SMTP id x5so2342067pll.2
        for <linux-kernel@vger.kernel.org>; Thu, 09 May 2019 14:46:09 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=date:message-id:mime-version:subject:from:to:cc;
        bh=nL0d57hUSvuWMoFDn/5vE0YoiIh4JIjeGFoZupaY4Z0=;
        b=evtcUmo57VHXFRBIP0x3AWI/DRc3GoPZaqq5H22bjls+Q7ydyTuym6zn5aJsVRqI7b
         v/zJxW3n1+HyBoRCOg1Dy+7OAz/B2uwfI1yVI2zq3D43tv5+7W+hqrrGKqeLCNFi0PaY
         14tdO/vksvtSvUg7+DuJibE3hr4PABy6ftpf7prdfwTPOSL9AiA6QR53jppQyadCeITX
         XT8iPNt6mWYzunPDsy28D0PTr4eh4C5LozBF/jjeVLFOX4uoSIN6co5vlToN95JXg50v
         Tuw2aHRraWK8zsKaxkPMM7VWLwL+xpH5BGTP5rDbtCt6QLrT+9KxgDwEQgZFhJaNK5br
         N9XA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc;
        bh=nL0d57hUSvuWMoFDn/5vE0YoiIh4JIjeGFoZupaY4Z0=;
        b=Nk0I2nS447fESeQy5tjupUgG590uyGpzJa0NbHPqiC8IqAY5/k3h2VpOqiJmxpQd0g
         bDOS1LPZkN9BDcfoIhXbKBrc4XffGMaAhTTbrqs5pl92Rcc4OuC4Gjx/s3gEMVyg4D8f
         0UsAeG8cot0956hcc/P5r4L24ZvQnp4xchRN2UZSoji1ThHnA34p5VjE2dqAADwS0S50
         WuJPU0mNCvfckSA/A5bR1UIjK9xJK9bXu7Jex3iRe8NBLdPyy4AupyGcZSSEuBXqvENU
         PwX/eox5rfHCEH5yFWaFpsF6kDI7CYLlN9iKvi33zzzp0KHFjYUqzccQHw+W7xyBgSRe
         aN/w==
X-Gm-Message-State: APjAAAWgs53iYwD1PXm1ZF2s/AclK1tsZo864HkvNA0IS4ThQX/0YKOP
        5Djbvt9JbcohdGAugqQgFGyeeDYgT/ep3lrl6R8VKxXse+GFp+pWjLIfXjUceFlN31TALSMsHRX
        bmIrecDPDfrY1FkimG7kuZArglkUFaJ7p3pKb9l/tXkwK/pAKKGggQBLJ5leiw7zC8Z0xZffz
X-Google-Smtp-Source: APXvYqz1G920x3hGqsde2xN9Ygj/66g/yIf33wS3jq0BN+yz6am8iegOFhahPeJmUmJ8Z6bNdggNXG2mTr71
X-Received: by 2002:a63:4a4f:: with SMTP id j15mr8738947pgl.338.1557438368607;
 Thu, 09 May 2019 14:46:08 -0700 (PDT)
Date:   Thu,  9 May 2019 14:45:56 -0700
Message-Id: <20190509214556.123493-1-eranian@google.com>
Mime-Version: 1.0
X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog
Subject: [PATCH] perf/x86: fix INTEL_FLAGS_EVENT_CONSTRAINT* masking
From:   Stephane Eranian <eranian@google.com>
To:     linux-kernel@vger.kernel.org
Cc:     peterz@infradead.org, ak@linux.intel.com, kan.liang@intel.com,
        mingo@elte.hu, jolsa@redhat.com, vincent.weaver@maine.edu
Content-Type: text/plain; charset="UTF-8"
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Intel Westmere, a cmdline as follows:
$ perf record -e cpu/event=0xc4,umask=0x2,name=br_inst_retired.near_call/p ....

Was failing. Yet the event+ umask support PEBS.

It turns out this is due to a bug in the the PEBS event constraint table for
westmere. All forms of BR_INST_RETIRED.* support PEBS. Therefore the constraint
mask should ignore the umask. The name of the macro INTEL_FLAGS_EVENT_CONSTRAINT()
hint that this is the case but it was not. That macros was checking both the
event code and event umask. Therefore, it was only matching on 0x00c4.
There are code+umask macros, they all have *UEVENT*.

This bug fixes the issue by checking only the event code in the mask.
Both single and range version are modified.

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 arch/x86/events/perf_event.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 07fc84bb85c1..a6ac2f4f76fc 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -394,10 +394,10 @@ struct cpu_hw_events {
 
 /* Event constraint, but match on all event flags too. */
 #define INTEL_FLAGS_EVENT_CONSTRAINT(c, n) \
-	EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
+	EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
 
 #define INTEL_FLAGS_EVENT_CONSTRAINT_RANGE(c, e, n)			\
-	EVENT_CONSTRAINT_RANGE(c, e, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
+	EVENT_CONSTRAINT_RANGE(c, e, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
 
 /* Check only flags, but allow all event/umask */
 #define INTEL_ALL_EVENT_CONSTRAINT(code, n)	\
-- 
2.21.0.1020.gf2820cf01a-goog


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=sufd=TK=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-12.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,
	DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,
	MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham
	autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 88D75C04A6B
	for <linux-kernel@archiver.kernel.org>; Fri, 10 May 2019 06:09:00 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by mail.kernel.org (Postfix) with ESMTP id 5A6CD217F4
	for <linux-kernel@archiver.kernel.org>; Fri, 10 May 2019 06:09:00 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="docbuebc"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1727053AbfEJGI7 (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Fri, 10 May 2019 02:08:59 -0400
Received: from terminus.zytor.com ([198.137.202.136]:42667 "EHLO
        terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1726914AbfEJGI6 (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Fri, 10 May 2019 02:08:58 -0400
Received: from terminus.zytor.com (localhost [127.0.0.1])
        by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x4A67K8r1921226
        (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO);
        Thu, 9 May 2019 23:07:21 -0700
DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x4A67K8r1921226
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com;
        s=2019041745; t=1557468441;
        bh=PmlmIVDFuzfc1ITIkyMA7ltEHqkkvQcVOEDJZ10yuXY=;
        h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From;
        b=docbuebcqP7GPaAl6bwMrdfSSnfRy56z6y+Q0Or9hRWOQHJRm1PXAaunuJIEKSoeS
         KzpS6Tzc5Ad30x+WB5ll9DG1SsXk51hl40n6rdgNozFFzFrsWlebDhW+g/+FjZCzHB
         UvPmgw3Fro6O+9wP3oIOfacq4AyAG4KnYpFb7k1xawnIXnGiI0cwSJ3Q0SSpOnnotJ
         0A/vrHkHMa02LNUvV9eCYIK4EmpXLhVLoqz/qr2KkgXTRUGcnXjiE6/FWQUCZMtezf
         vOTr5poT9jbLd+vitVIwSeq/t+16JipwlaqUvgimR0AFg5eNM4Z/zKaA2ky8I2gFKJ
         7lpGeg6HNgPzA==
Received: (from tipbot@localhost)
        by terminus.zytor.com (8.15.2/8.15.2/Submit) id x4A67Kd61921223;
        Thu, 9 May 2019 23:07:20 -0700
Date:   Thu, 9 May 2019 23:07:20 -0700
X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f
From:   tip-bot for Stephane Eranian <tipbot@zytor.com>
Message-ID: <tip-6b89d4c1ae8596a8c9240f169ef108704de373f2@git.kernel.org>
Cc:     vincent.weaver@maine.edu, hpa@zytor.com, acme@redhat.com,
        alexander.shishkin@linux.intel.com, mingo@kernel.org,
        jolsa@redhat.com, linux-kernel@vger.kernel.org,
        torvalds@linux-foundation.org, eranian@google.com,
        tglx@linutronix.de, peterz@infradead.org
Reply-To: hpa@zytor.com, vincent.weaver@maine.edu, acme@redhat.com,
          alexander.shishkin@linux.intel.com, mingo@kernel.org,
          jolsa@redhat.com, linux-kernel@vger.kernel.org,
          torvalds@linux-foundation.org, eranian@google.com,
          tglx@linutronix.de, peterz@infradead.org
In-Reply-To: <20190509214556.123493-1-eranian@google.com>
References: <20190509214556.123493-1-eranian@google.com>
To:     linux-tip-commits@vger.kernel.org
Subject: [tip:perf/urgent] perf/x86/intel: Fix INTEL_FLAGS_EVENT_CONSTRAINT*
 masking
Git-Commit-ID: 6b89d4c1ae8596a8c9240f169ef108704de373f2
X-Mailer: tip-git-log-daemon
Robot-ID: <tip-bot.git.kernel.org>
Robot-Unsubscribe: Contact <mailto:hpa@kernel.org> to get blacklisted from
 these emails
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

Commit-ID:  6b89d4c1ae8596a8c9240f169ef108704de373f2
Gitweb:     https://git.kernel.org/tip/6b89d4c1ae8596a8c9240f169ef108704de373f2
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Thu, 9 May 2019 14:45:56 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 10 May 2019 08:04:17 +0200

perf/x86/intel: Fix INTEL_FLAGS_EVENT_CONSTRAINT* masking

On Intel Westmere, a cmdline as follows:

  $ perf record -e cpu/event=0xc4,umask=0x2,name=br_inst_retired.near_call/p ....

was failing. Yet the event+ umask support PEBS.

It turns out this is due to a bug in the the PEBS event constraint table for
westmere. All forms of BR_INST_RETIRED.* support PEBS. Therefore the constraint
mask should ignore the umask. The name of the macro INTEL_FLAGS_EVENT_CONSTRAINT()
hint that this is the case but it was not. That macros was checking both the
event code and event umask. Therefore, it was only matching on 0x00c4.
There are code+umask macros, they all have *UEVENT*.

This bug fixes the issue by checking only the event code in the mask.
Both single and range version are modified.

Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: kan.liang@intel.com
Link: http://lkml.kernel.org/r/20190509214556.123493-1-eranian@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/perf_event.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 07fc84bb85c1..a6ac2f4f76fc 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -394,10 +394,10 @@ struct cpu_hw_events {
 
 /* Event constraint, but match on all event flags too. */
 #define INTEL_FLAGS_EVENT_CONSTRAINT(c, n) \
-	EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
+	EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
 
 #define INTEL_FLAGS_EVENT_CONSTRAINT_RANGE(c, e, n)			\
-	EVENT_CONSTRAINT_RANGE(c, e, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
+	EVENT_CONSTRAINT_RANGE(c, e, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
 
 /* Check only flags, but allow all event/umask */
 #define INTEL_ALL_EVENT_CONSTRAINT(code, n)	\

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=//ty=TS=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-11.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE,INCLUDES_PATCH,MAILING_LIST_MULTI,
	MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,
	USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 2F8C9C04AAF
	for <linux-kernel@archiver.kernel.org>; Sat, 18 May 2019 21:16:38 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by mail.kernel.org (Postfix) with ESMTP id E594420833
	for <linux-kernel@archiver.kernel.org>; Sat, 18 May 2019 21:16:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1558214198;
	bh=yJSk1NIeZrHzHSFnPF2cJD8bD4fnPOPzDiTtUflbemM=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From;
	b=PRJbyKXx0NpU5IuLErI7DL/c/ewVNtBK7tk9fNvVL+kdAjsmLpebIb0XnwKxrvYg/
	 xSzH4MHGLUmjVxXouinKLFSfRLAd5zbaud6OtIlqbZ+BfRDC2B1fh7Xkv802nZoAGi
	 c/+rE9oi/wzdKFle732BSKnkFSrfzNGlSGdks6vY=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1729541AbfERVQg (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Sat, 18 May 2019 17:16:36 -0400
Received: from mail-wm1-f67.google.com ([209.85.128.67]:36739 "EHLO
        mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1727600AbfERVQg (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Sat, 18 May 2019 17:16:36 -0400
Received: by mail-wm1-f67.google.com with SMTP id j187so9609777wmj.1;
        Sat, 18 May 2019 14:16:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=sender:date:from:to:cc:subject:message-id:references:mime-version
         :content-disposition:in-reply-to:user-agent;
        bh=cXYOS4OOSBMv4Ps0Tiqsu4mWp1GxtDuXE3E/KT5J9/I=;
        b=uyYxczNureCbUUwGvYKMEfWyjymj/EM8IVIhJ6VJ6Bf6Q06xWNqUhjBcChE7N6xF76
         cwO14JKN/TJwHJerjNKEa7I26T8H/EIw+3/ZFTizPTsxBR0ZoBT1ZChYyYwCkc7UmWgi
         f77Dtj4mVQzLidXt/Zau1R89BkH0MPoqlQSqqiIYpsEmSK2OaaNM1TAk7tgrV1UYuZmg
         ffF5V1VgQqwFzv9WGX6RUjfOH3o3LNogroCwLtcMPmxN5Zl54Ge1kyEmz4miK+LLsr07
         NMwUyfHDResyKqRHZ0rO6Wwmll344+lJNKI6sRJjam96cLeTH6DzrTPkOt5l/AlQX23O
         RQBg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:sender:date:from:to:cc:subject:message-id
         :references:mime-version:content-disposition:in-reply-to:user-agent;
        bh=cXYOS4OOSBMv4Ps0Tiqsu4mWp1GxtDuXE3E/KT5J9/I=;
        b=lCcnLRi5ohSh4G1w17tRQ/JpYzI3xPvxu8Ju7GeC+xrmCqYANu9P3R8aOTL9RtmMTH
         6usYHCQfgKBzRYjIDmDd7YETBV6YGjxXXiDZ52kSdVUAnynXhHmLwma/XjrV6nI8uTRY
         SBuss2nD9yelm49A4DHTAhQc0T/XeH2anFKEkExSlgz7hJTju+kRmM2o5ScVa7Z/+z8G
         pXQcO7IyzVH4L4vhLk0U7U0cLCULQSz/JJhb1Uyn8qcF0LzMkZd5neVU5U6TkfdrRN/b
         DzTsABn6tkJ4Fg3FaSWrRI5WchOA/2jPJYGg+OfsqlLX6lmVZ7xB7UcPa+4TWFx+c4jP
         GVMQ==
X-Gm-Message-State: APjAAAU++u3MMczUsgLVYZFsrhrbM0aUvGInc5ojVFvKSb9HY4LlcsHZ
        4d7KwE2bNsTgjTAj6TI15mA=
X-Google-Smtp-Source: APXvYqz6Rf1bfpudSSsbbsRfT3sEXwYaBGH1ulyHiedeTtQakR8H4zI1d9YK3xiHWwlSe15RAxO0gA==
X-Received: by 2002:a1c:1941:: with SMTP id 62mr6668435wmz.100.1558214193195;
        Sat, 18 May 2019 14:16:33 -0700 (PDT)
Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213])
        by smtp.gmail.com with ESMTPSA id z8sm10927055wrs.84.2019.05.18.14.16.31
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Sat, 18 May 2019 14:16:32 -0700 (PDT)
Date:   Sat, 18 May 2019 23:16:30 +0200
From:   Ingo Molnar <mingo@kernel.org>
To:     hpa@zytor.com, vincent.weaver@maine.edu, acme@redhat.com,
        alexander.shishkin@linux.intel.com, jolsa@redhat.com,
        linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
        eranian@google.com, tglx@linutronix.de, peterz@infradead.org
Cc:     linux-tip-commits@vger.kernel.org
Subject: Re: [tip:perf/urgent] perf/x86/intel: Fix
 INTEL_FLAGS_EVENT_CONSTRAINT* masking
Message-ID: <20190518211630.GC51669@gmail.com>
References: <20190509214556.123493-1-eranian@google.com>
 <tip-6b89d4c1ae8596a8c9240f169ef108704de373f2@git.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <tip-6b89d4c1ae8596a8c9240f169ef108704de373f2@git.kernel.org>
User-Agent: Mutt/1.10.1 (2018-07-13)
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org


* tip-bot for Stephane Eranian <tipbot@zytor.com> wrote:

> Commit-ID:  6b89d4c1ae8596a8c9240f169ef108704de373f2
> Gitweb:     https://git.kernel.org/tip/6b89d4c1ae8596a8c9240f169ef108704de373f2
> Author:     Stephane Eranian <eranian@google.com>
> AuthorDate: Thu, 9 May 2019 14:45:56 -0700
> Committer:  Ingo Molnar <mingo@kernel.org>
> CommitDate: Fri, 10 May 2019 08:04:17 +0200
> 
> perf/x86/intel: Fix INTEL_FLAGS_EVENT_CONSTRAINT* masking
> 
> On Intel Westmere, a cmdline as follows:
> 
>   $ perf record -e cpu/event=0xc4,umask=0x2,name=br_inst_retired.near_call/p ....
> 
> was failing. Yet the event+ umask support PEBS.
> 
> It turns out this is due to a bug in the the PEBS event constraint table for
> westmere. All forms of BR_INST_RETIRED.* support PEBS. Therefore the constraint
> mask should ignore the umask. The name of the macro INTEL_FLAGS_EVENT_CONSTRAINT()
> hint that this is the case but it was not. That macros was checking both the
> event code and event umask. Therefore, it was only matching on 0x00c4.
> There are code+umask macros, they all have *UEVENT*.
> 
> This bug fixes the issue by checking only the event code in the mask.
> Both single and range version are modified.
> 
> Signed-off-by: Stephane Eranian <eranian@google.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Vince Weaver <vincent.weaver@maine.edu>
> Cc: kan.liang@intel.com
> Link: http://lkml.kernel.org/r/20190509214556.123493-1-eranian@google.com
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> ---
>  arch/x86/events/perf_event.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
> index 07fc84bb85c1..a6ac2f4f76fc 100644
> --- a/arch/x86/events/perf_event.h
> +++ b/arch/x86/events/perf_event.h
> @@ -394,10 +394,10 @@ struct cpu_hw_events {
>  
>  /* Event constraint, but match on all event flags too. */
>  #define INTEL_FLAGS_EVENT_CONSTRAINT(c, n) \
> -	EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
> +	EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
>  
>  #define INTEL_FLAGS_EVENT_CONSTRAINT_RANGE(c, e, n)			\
> -	EVENT_CONSTRAINT_RANGE(c, e, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
> +	EVENT_CONSTRAINT_RANGE(c, e, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)

This commit broke one of my testboxes - and unfortunately I noticed this 
too late and the commit is now upstream.

The breakage is that 'perf top' stops working altogether, it errors out 
in the event creation:

 $ perf top --stdio
 Error:
 The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (cycles).

I bisected it back to this commit:

 6b89d4c1ae8596a8c9240f169ef108704de373f2 is the first bad commit
 commit 6b89d4c1ae8596a8c9240f169ef108704de373f2
 Author: Stephane Eranian <eranian@google.com>
 Date:   Thu May 9 14:45:56 2019 -0700

    perf/x86/intel: Fix INTEL_FLAGS_EVENT_CONSTRAINT* masking

The system is IvyBridge model 62, running a defconfig-ish kernel, and 
with perf_event_paranoid set to -1:

 [    3.756600] Performance Events: PEBS fmt1+, IvyBridge events, 16-deep LBR, full-width counters, Intel PMU driver.

 processor	: 39
 vendor_id	: GenuineIntel
 cpu family	: 6
 model		: 62
 model name	: Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
 stepping	: 4
 microcode	: 0x428

If I revert the commit 'perf top' starts working again.

Thanks,

	Ingo

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=AA30=TT=vger.kernel.org=linux-kernel-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-19.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,
	MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,
	URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 0F22BC04AAF
	for <linux-kernel@archiver.kernel.org>; Sun, 19 May 2019 01:41:40 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
	by mail.kernel.org (Postfix) with ESMTP id D1A1220872
	for <linux-kernel@archiver.kernel.org>; Sun, 19 May 2019 01:41:39 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FWlFD/3e"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1729687AbfESBli (ORCPT
        <rfc822;linux-kernel@archiver.kernel.org>);
        Sat, 18 May 2019 21:41:38 -0400
Received: from mail-io1-f67.google.com ([209.85.166.67]:39034 "EHLO
        mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1726962AbfESBli (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Sat, 18 May 2019 21:41:38 -0400
Received: by mail-io1-f67.google.com with SMTP id m7so8401692ioa.6
        for <linux-kernel@vger.kernel.org>; Sat, 18 May 2019 18:41:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :cc;
        bh=B+HeqwAEcCZlxTlN2fPsPmRvYlA8UMTWELs3MdTDPTY=;
        b=FWlFD/3ebRRLCywonkK1V5QyHaUWgp5+enX7C4DTPmQq/+0ZOddkFJv8wtfJozlPD7
         PdWr96cjJh0exNAtBjPS0bTYeRJdxVsLiP6m0kUEtobZSygqFw+ItjXcgXEWo9QyI+6t
         fXrGhg7LQlDs64VGOfh96k1ZXK70QND8msR6K/rY3ni8qJ4ZAqzMHoc1m4+f1w2rVzJo
         V/WFiCxX0Eq5ngh0DQy9e9ooY2MWmHuNUHodaJLn6u1xddzAwwNexabtGE5739t+YVLo
         uRqQ5B3xsFm2lPEVnBZauIF6ma/iXrYcLusEvSKiT+O8Ubeaew1MBk3z5zL3XKmv96mr
         79QA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc;
        bh=B+HeqwAEcCZlxTlN2fPsPmRvYlA8UMTWELs3MdTDPTY=;
        b=K6tcRV9Z+MlNNnVgixqTUB+hXNr2sS6kcN490VtGICVHtHI+jxmq+cSfd4nprlaGBq
         VdqMMtdru/ieIMBZmJc94HDxNSLS51nSf1s0lFxQ7FEVTfeL4TN75n866hjpA9hdlj3I
         a8PzoXNjDSQD7YFuGCzKioA169N955N4oToK7oNcACOHEzk+MfaV4y+66QGOpjdVZJVV
         wJivveyhCCVN5k2/F2CbMGKkg+Ft1KlpYaPwEWO3zjh8tCJh6FrkCeEGOx61lh27wxYp
         KDENgEev8usScrsiMyesOcdSxkQRJc8fGLZn+gxfP9Qjw3/BQuZ84UP0gDiLB02sxnRI
         MpeQ==
X-Gm-Message-State: APjAAAW0aR/0JKl/ByxfvOq8k5MCn7mu2A2s659G84LUVwQOwqj2Qi+o
        Fwbr88XQApH31oFFo9tkE+JwLkT6x3bLqSCbf8wGpg==
X-Google-Smtp-Source: APXvYqxw7z6yLYUkJ+gWXvTxERjZmblTFTr1I6hJ8+3UBc0x/URaQgoudoPl7MXtnLGMFZI9j+EBMcoWuzrKeCzjVyI=
X-Received: by 2002:a5d:96c4:: with SMTP id r4mr10137168iol.193.1558230096974;
 Sat, 18 May 2019 18:41:36 -0700 (PDT)
MIME-Version: 1.0
References: <20190509214556.123493-1-eranian@google.com> <tip-6b89d4c1ae8596a8c9240f169ef108704de373f2@git.kernel.org>
 <20190518211630.GC51669@gmail.com>
In-Reply-To: <20190518211630.GC51669@gmail.com>
From:   Stephane Eranian <eranian@google.com>
Date:   Sat, 18 May 2019 18:41:25 -0700
Message-ID: <CABPqkBSS5b583+sxGjLj=N-OSOMFRiTtbZLNF0=+cCqvvEigqw@mail.gmail.com>
Subject: Re: [tip:perf/urgent] perf/x86/intel: Fix INTEL_FLAGS_EVENT_CONSTRAINT*
 masking
To:     Ingo Molnar <mingo@kernel.org>
Cc:     "H. Peter Anvin" <hpa@zytor.com>,
        Vince Weaver <vincent.weaver@maine.edu>,
        Arnaldo Carvalho de Melo <acme@redhat.com>,
        Alexander Shishkin <alexander.shishkin@linux.intel.com>,
        Jiri Olsa <jolsa@redhat.com>,
        LKML <linux-kernel@vger.kernel.org>,
        Linus Torvalds <torvalds@linux-foundation.org>,
        Thomas Gleixner <tglx@linutronix.de>,
        Peter Zijlstra <peterz@infradead.org>,
        linux-tip-commits@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Sat, May 18, 2019 at 2:16 PM Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * tip-bot for Stephane Eranian <tipbot@zytor.com> wrote:
>
> > Commit-ID:  6b89d4c1ae8596a8c9240f169ef108704de373f2
> > Gitweb:     https://git.kernel.org/tip/6b89d4c1ae8596a8c9240f169ef108704de373f2
> > Author:     Stephane Eranian <eranian@google.com>
> > AuthorDate: Thu, 9 May 2019 14:45:56 -0700
> > Committer:  Ingo Molnar <mingo@kernel.org>
> > CommitDate: Fri, 10 May 2019 08:04:17 +0200
> >
> > perf/x86/intel: Fix INTEL_FLAGS_EVENT_CONSTRAINT* masking
> >
> > On Intel Westmere, a cmdline as follows:
> >
> >   $ perf record -e cpu/event=0xc4,umask=0x2,name=br_inst_retired.near_call/p ....
> >
> > was failing. Yet the event+ umask support PEBS.
> >
> > It turns out this is due to a bug in the the PEBS event constraint table for
> > westmere. All forms of BR_INST_RETIRED.* support PEBS. Therefore the constraint
> > mask should ignore the umask. The name of the macro INTEL_FLAGS_EVENT_CONSTRAINT()
> > hint that this is the case but it was not. That macros was checking both the
> > event code and event umask. Therefore, it was only matching on 0x00c4.
> > There are code+umask macros, they all have *UEVENT*.
> >
> > This bug fixes the issue by checking only the event code in the mask.
> > Both single and range version are modified.
> >
> > Signed-off-by: Stephane Eranian <eranian@google.com>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Linus Torvalds <torvalds@linux-foundation.org>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Vince Weaver <vincent.weaver@maine.edu>
> > Cc: kan.liang@intel.com
> > Link: http://lkml.kernel.org/r/20190509214556.123493-1-eranian@google.com
> > Signed-off-by: Ingo Molnar <mingo@kernel.org>
> > ---
> >  arch/x86/events/perf_event.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
> > index 07fc84bb85c1..a6ac2f4f76fc 100644
> > --- a/arch/x86/events/perf_event.h
> > +++ b/arch/x86/events/perf_event.h
> > @@ -394,10 +394,10 @@ struct cpu_hw_events {
> >
> >  /* Event constraint, but match on all event flags too. */
> >  #define INTEL_FLAGS_EVENT_CONSTRAINT(c, n) \
> > -     EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
> > +     EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
> >
> >  #define INTEL_FLAGS_EVENT_CONSTRAINT_RANGE(c, e, n)                  \
> > -     EVENT_CONSTRAINT_RANGE(c, e, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
> > +     EVENT_CONSTRAINT_RANGE(c, e, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
>
> This commit broke one of my testboxes - and unfortunately I noticed this
> too late and the commit is now upstream.
>
> The breakage is that 'perf top' stops working altogether, it errors out
> in the event creation:
>
>  $ perf top --stdio
>  Error:
>  The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (cycles).
>
> I bisected it back to this commit:
>
>  6b89d4c1ae8596a8c9240f169ef108704de373f2 is the first bad commit
>  commit 6b89d4c1ae8596a8c9240f169ef108704de373f2
>  Author: Stephane Eranian <eranian@google.com>
>  Date:   Thu May 9 14:45:56 2019 -0700
>
>     perf/x86/intel: Fix INTEL_FLAGS_EVENT_CONSTRAINT* masking
>
> The system is IvyBridge model 62, running a defconfig-ish kernel, and
> with perf_event_paranoid set to -1:
>
>  [    3.756600] Performance Events: PEBS fmt1+, IvyBridge events, 16-deep LBR, full-width counters, Intel PMU driver.
>
>  processor      : 39
>  vendor_id      : GenuineIntel
>  cpu family     : 6
>  model          : 62
>  model name     : Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
>  stepping       : 4
>  microcode      : 0x428
>
> If I revert the commit 'perf top' starts working again.
>
I have some ivybridge systems, let me debug this. This is likely
related to cycles:ppp stuff given what perf top does.
I think my patch is right, but there may be assumptions or bugs
elsewhere exposed by the fix.

>
> Thanks,
>
>         Ingo

