Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1752297ybl; Sat, 11 Jan 2020 02:06:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxWVXaA557l9cV7A/BZ11Vba9bwWuf8HVHwXWJHLOymqTQxW/Kmykh7zTQPWJJaZOYOscT+ X-Received: by 2002:aca:7244:: with SMTP id p65mr5601963oic.50.1578737198932; Sat, 11 Jan 2020 02:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578737198; cv=none; d=google.com; s=arc-20160816; b=cYNGCpGlEfjnBccBAPVKxAlAUuYy8SMvG+xw4U6POEHB3bJITjva3Q1p4lOvGWOKkh O3uhHMSrOjLjmWWg+f3HWFTs2tFPjvscQL8Zy3O52dX5vv/Todi0+6EZRQyUCS9sOWGg 4qpzjmK9AM3t3g0WmnoEJ0/aN4Zw7Q+jGwgPl6ATgZ/dCCn6zXAelvqT69BmtTVPigoE Jy/QcBUrPmMr4uGCzTpEHa8ozFWVpyHCyBBXAODvvbaQbKDPtrUQGNzwFm5YwCqB838t 1LXs9T7nzbXuVzzsNJfFjmedK9eMhYCP7JzkqDzhJGXIUofbcf+oux3ToafrwLJBVzfp wxuA== 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=CJ4NKYWaFw5h1bF5XYZHLRwZgNPFb5436V6AE/qZUwo=; b=N2vB9mpNUU+6xZRaQe7Uvv7Q0SvwHbCAohcxKedHtAAb6vniTwUUN2WLPubeZqppy6 StVCSvIJ89VkPcJdUEHRHNZ93kUIeDhuCyO8DqpJaRjKQb76+M6Jzhftixlb6dsW0m0F PRF3busHBYCQzApal8dDGdBYO3rItV6tyiXwktY1MW5Ii3IDeRDWcSOpSG8dkVMt/60M SjdJUScKOv1eBFFUcT8e5alYV+ZaAKCxX+vNsZDzwacU1gioBXG+153G7rUMu7BGIoIa b8kLUI4s999+Sj8qJU0w5FkIZlG31e9Enu/BA3aJfG/EPe6Wfd38bJVJ/Gd78GSQutsr jLOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KagLk3NM; 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 e18si3478325oti.153.2020.01.11.02.06.27; Sat, 11 Jan 2020 02:06:38 -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; dkim=pass header.i=@kernel.org header.s=default header.b=KagLk3NM; 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 S1729098AbgAKKEm (ORCPT + 99 others); Sat, 11 Jan 2020 05:04:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:37230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729021AbgAKKEl (ORCPT ); Sat, 11 Jan 2020 05:04:41 -0500 Received: from localhost (unknown [62.119.166.9]) (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 754322082E; Sat, 11 Jan 2020 10:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578737080; bh=ehWXxgL2qGAl8OpB2pwYtJRf+xpwsJCv8hYXYxukeQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KagLk3NME//JH/8tH7Kq8JQasxpCaXa25jhs8Ww+gGqHiyAJELNyyWQczEAi99y69 MGyPp0puZ2ng8+AJ8L7e2XsRi44QNPSzb6eEsyG829S8Emy0/vVveQiYiBqXHQXReS IfKO+mKKfOYCT+RuNCcfxlfvlt+kNX+Sa1W/k64k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Slobodskoy , Alexander Shishkin , "Peter Zijlstra (Intel)" , Alexey Budankov , Jiri Olsa , Ingo Molnar , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 75/91] perf/x86/intel: Fix PT PMI handling Date: Sat, 11 Jan 2020 10:50:08 +0100 Message-Id: <20200111094911.589419533@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094844.748507863@linuxfoundation.org> References: <20200111094844.748507863@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Alexander Shishkin [ Upstream commit 92ca7da4bdc24d63bb0bcd241c11441ddb63b80a ] 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. Fixes: ccbebba4c6bf ("perf/x86/intel/pt: Bypass PT vs. LBR exclusivity if the core supports it") Reported-by: Vitaly Slobodskoy Signed-off-by: Alexander Shishkin Signed-off-by: Peter Zijlstra (Intel) Acked-by: Alexey Budankov Cc: Jiri Olsa Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Link: https://lkml.kernel.org/r/20191210105101.77210-1-alexander.shishkin@linux.intel.com Signed-off-by: Sasha Levin --- 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 1e9f610d36a4..c26cca506f64 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -374,7 +374,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); @@ -386,6 +386,7 @@ int x86_add_exclusive(unsigned int what) mutex_unlock(&pmc_reserve_mutex); } +out: atomic_inc(&active_events); return 0; @@ -396,11 +397,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.20.1