Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1770691ybl; Sat, 11 Jan 2020 02:28:48 -0800 (PST) X-Google-Smtp-Source: APXvYqzm0Whj+lNnB5KLfQDtrwJd6aSvhc9eVugB1tDq2aytMSCObb8EA8TnY8VHAj9eiCz3a8G0 X-Received: by 2002:a05:6808:9a4:: with SMTP id e4mr5950492oig.127.1578738528637; Sat, 11 Jan 2020 02:28:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578738528; cv=none; d=google.com; s=arc-20160816; b=Mxz+yiHR+8d73On+z6drVQzhYNpjAF5UPTjVUmY/IOQrh7oYkxQym18PNgpjmpqlsa uK9ZaYbBDsePJFd4eVY1lFWowe/CIOgcAQCGvHe5awpuLS93Si8NugXXygPMHSOr40Jb w5D64DXvZopx6S0I5N5JVJtWqPC7GjjGDDNRFIY//6hSNu+8CJe6BrqLmMqndWGWtScV uq//u7o7CVcEZCV4WG7BmJy2NiE+MxQQmPOF+geW45M06/rAcZgsjdHnGe16REPqXec+ rAXmyregnP3mbJQYutPXAxTbghDMulkD+ehdD0n4d+W8B9+2fsFOblDncY7DwU8OAHa1 W7hA== 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=WF0HYrHy0y4ubOZAYqMygBnREx1zQUw2tPeslmXWyXI=; b=X2681227ioZwg0u2Glh8TfW4T5v8TBsmzhnaCBb75ECyCqr1/vf8hufb/vWLFW7sx4 G7NVUcGpZ9EVz6WWKzf15Bif+4fdGAGbb7Y4Gcjl9uZ6YinZkwKtm06gxQlmNCf0W4Sz 4J8ihcy9fjRX0cYbwmc50XF45xKuC7hHXCh9EqH56huABKrlwGkVPCAAOFCjJz9LE1Ki esABWnrA8+jxD9WJIVKMGypwD+H8Ux/G/Sg3rv1eeRXdi56LMobt15LvlCLz/kJHuJ57 RLvAW/plv8eZ1DyZK8ViMZceGt9WC4F9IuAB62P6zU4W/r2Qq+MNu1OcAoTRL3Vmv4yY ZIow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZX2Tml3L; 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 l84si2845059oig.5.2020.01.11.02.28.37; Sat, 11 Jan 2020 02:28:48 -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=ZX2Tml3L; 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 S1731103AbgAKK1q (ORCPT + 99 others); Sat, 11 Jan 2020 05:27:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:34024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729453AbgAKK1o (ORCPT ); Sat, 11 Jan 2020 05:27:44 -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 340F620842; Sat, 11 Jan 2020 10:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578738464; bh=mPnIziU1WI+Cdnd2zDTDHWhEYD0fDDA3WPrsrAkV9S0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZX2Tml3LFHE6/w8sdsv3jjiuTknUHHViElhbBiECA79C/7S4lD0X0c3EFP3bGXBNR zJbh1BtuizoUpic7VdvErcx5wKevD/8xFmCY5lxKb4fPmwn7f2sNWwWN5zhAZdLbFX P3fY4A+YwIQVMDOH3sMaobFnGSCas+Aapzww3Y3E= 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 5.4 099/165] perf/x86/intel: Fix PT PMI handling Date: Sat, 11 Jan 2020 10:50:18 +0100 Message-Id: <20200111094929.966208470@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094921.347491861@linuxfoundation.org> References: <20200111094921.347491861@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 b9673396b571..e622158f5659 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.20.1