Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5238056ybl; Tue, 10 Dec 2019 02:51:54 -0800 (PST) X-Google-Smtp-Source: APXvYqxBYE+ZmkDYA/TdI5O5BxPPUBoEXBa8LBF2HeDHXNXtrnl70lP6BHJp0bTH88O5W5PLIagv X-Received: by 2002:a05:6830:1251:: with SMTP id s17mr24830630otp.108.1575975114383; Tue, 10 Dec 2019 02:51:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575975114; cv=none; d=google.com; s=arc-20160816; b=TvQWYfLOtt0J9PuKCUTPNygazLiddyOEA06iLthh7jaFmXggM1HC+Q/jK2qRfFgn0X ppdJL57sjdSmxgBYpISrUz11HxM0PPToDM794Clog8ArnK/lXB44BL148olXW4GSqDJY S+l+CNVVi0aLqeE+UIodMeeTqjiLPyuRRHAEG6J/6RwoXJjJahjzGWBS9Z1hPxYHYKih d+aH8VhAobA3LuE8pRcVJclwtwyztXwq3/UBvSLzdRKW1nt1fYBLxzxdRH4DRANDjTXg bpkGTwYwLRnCFsqWcDcj2RGxU2eOXAtQ05nX3xed4gLANBNcsAG3ZlS3NZGoPI0ycxbV V42g== 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 :message-id:date:subject:cc:to:from; bh=eGogomah6xAb0ZtHHjNLGuL+5eHnC/qNHT/Y7OPAlOk=; b=kK+L6ob1xYbsNRBTuYH5E6XyPdHoysAGmTQIACHna4MOo65mtg2A/ZNYRZBVDJJN68 OAURpoO/oIEA5OfbX6iW2DBspQ3zCzGi3SugREUklNYtHuUU9ecg0n9kEuAofToZvx7c q3wa4j1kzxS8J2Ixh+wczaPfLPMWvvazsO0MI/K0jOoXBXaKW5Djs1d0F8vAyNlVXoEa O/C1ZBxRKBv51u2ogO3WVtdakW2x3ojkIoDX78pitpxmO3ce7aETSKbyOpeqzZMosVGN egqkxS663vZ7PAMV6YLaPvt1Ih0fdZ69e3XC8eV1FjmGPp+/bB7OnqIpBGEe2vjtOY0t IlcQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d27si1834507otk.206.2019.12.10.02.51.41; Tue, 10 Dec 2019 02:51:54 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727143AbfLJKvN (ORCPT + 99 others); Tue, 10 Dec 2019 05:51:13 -0500 Received: from mga01.intel.com ([192.55.52.88]:4952 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbfLJKvN (ORCPT ); Tue, 10 Dec 2019 05:51:13 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 02:51:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,299,1571727600"; d="scan'208";a="215533286" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 10 Dec 2019 02:51:10 -0800 From: Alexander Shishkin To: Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Ingo Molnar , linux-kernel@vger.kernel.org, Jiri Olsa , Alexander Shishkin , Vitaly Slobodskoy , stable@vger.kernel.org Subject: [PATCH] perf/x86/intel: Fix PT PMI handling Date: Tue, 10 Dec 2019 12:51:01 +0200 Message-Id: <20191210105101.77210-1-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit: ccbebba4c6bf ("perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it") skips the PT/LBR exclusivity check on CPUs where PT and LBRs coexist, but also inadvertently skips the active_events bump for PT in that case, which is a bug. If there aren't any hardware events at the same time as PT, the PMI handler will ignore PT PMIs, as active_events reads zero in that case, resulting in the "Uhhuh" spurious NMI warning and PT data loss. Fix this by always increasing active_events for PT events. Signed-off-by: Alexander Shishkin Fixes: ccbebba4c6bf ("perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it") Reported-by: Vitaly Slobodskoy Cc: stable@vger.kernel.org # v4.7 --- arch/x86/events/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 6e3f0c18908e..5a736197dfa4 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -375,7 +375,7 @@ int x86_add_exclusive(unsigned int what) * LBR and BTS are still mutually exclusive. */ if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt) - return 0; + goto out; if (!atomic_inc_not_zero(&x86_pmu.lbr_exclusive[what])) { mutex_lock(&pmc_reserve_mutex); @@ -387,6 +387,7 @@ int x86_add_exclusive(unsigned int what) mutex_unlock(&pmc_reserve_mutex); } +out: atomic_inc(&active_events); return 0; @@ -397,11 +398,15 @@ int x86_add_exclusive(unsigned int what) void x86_del_exclusive(unsigned int what) { + atomic_dec(&active_events); + + /* + * See the comment in x86_add_exclusive(). + */ if (x86_pmu.lbr_pt_coexist && what == x86_lbr_exclusive_pt) return; atomic_dec(&x86_pmu.lbr_exclusive[what]); - atomic_dec(&active_events); } int x86_setup_perfctr(struct perf_event *event) -- 2.24.0