Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10480580ybi; Thu, 25 Jul 2019 00:03:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfskL2VXFjxQpsfnPCMZ+aIheQxwA8oJfEyIpNb1oPKCWvaqIVpvX7eWY7QsHVceaYpkLJ X-Received: by 2002:a17:902:bd06:: with SMTP id p6mr91985606pls.189.1564038205617; Thu, 25 Jul 2019 00:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564038205; cv=none; d=google.com; s=arc-20160816; b=Hf0+XplpL26JHS0LWNHUwmB/7HWzXqr/2+MqfIrgMZ3hbP4Y7atIhihLQoo9nH8jK4 2rqhJG77xal+3p3ExqRCQSYxrYRsndNJibnL1DgW8gUV1IbLB9/cZsPU56vwza/DDe+o l/Gb85/jlx5dmjiU+iay6EjJDen/S7Kcc0DlvsFGMrKoYudNeNDaak5gRcKJlsz8azQP qmBb3/+Hv2/VG8R3sNdQo6z2oHQAva7PcwsRIt+A/A+8D0WFzKUo8LlfcfxCxyjD4i3G +02KD85M6YfIhBZgRt/7UQNO2YNPw4FdxS8hbqCoJLVXcp/j09MLH9GWp+VDETyAAiFy TICA== 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=vw76yvW71kyI+h6QRjsNQsxCdhIGbol2JVawAQBmWkY=; b=1BqtzSxKwv28ZPFCZO4zk4ongyoVHl8HkDprDh562vUbLhUPwweRnnQZ86aNNMRAVm GTj2HHWCvhmW8JaROw523iBNXTMBEMDtsn+K3BdNY1jkgfXGHlev9LpGXoLUBNvmUWpV D29zkrjeTBrNDmDtmADKcZB2055YhLMF8uP+SD+ouK2ASXQVDXTRqYSHqwN2fyj1v/j+ lscNe6ECgCHsrsHjMSsbSrqDhtXfE6NV53GhtyLxG6df7Ans71HPpdAf/B4LiiGCLrsj V+0g6sNwyLShZsqfg2Wrw0uEiSFj0HQ2FbA8ns8fGrU8zSYIa8CyP5zLGBIU4/IrO9hs Pwug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cePPolY7; 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 v5si20697760pgs.285.2019.07.25.00.03.10; Thu, 25 Jul 2019 00:03:25 -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=cePPolY7; 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 S1729302AbfGYHBL (ORCPT + 99 others); Thu, 25 Jul 2019 03:01:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:34198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbfGYHBK (ORCPT ); Thu, 25 Jul 2019 03:01:10 -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 348012070B; Thu, 25 Jul 2019 07:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564038069; bh=86HcYU9n0mFTGn6uNTIrrfgOLIWTZfG6iObg0q1mcx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cePPolY7UxQpBhZF3A4pxWoR4DEAj9TOgo09xWL4qYU0P1YcYfN0FIjWq6KD6MeaO HT+URvLxe4C3Ehahsb7McKVQ/La4nnrZ6GrKOAxWHXxTYWMTEoKxUu4Z4zMOrgqu0o a7yxCoeiIQjMb1U62hD02dWnSIKiR5ve66tamdiE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Yi, Ammy" , Kan Liang , "Peter Zijlstra (Intel)" , Jiri Olsa , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , Ingo Molnar Subject: [PATCH 5.2 354/413] perf/x86/intel: Fix spurious NMI on fixed counter Date: Wed, 24 Jul 2019 21:20:45 +0200 Message-Id: <20190724191801.057976495@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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: Kan Liang commit e4557c1a46b0d32746bd309e1941914b5a6912b4 upstream. If a user first sample a PEBS event on a fixed counter, then sample a non-PEBS event on the same fixed counter on Icelake, it will trigger spurious NMI. For example: perf record -e 'cycles:p' -a perf record -e 'cycles' -a The error message for spurious NMI: [June 21 15:38] Uhhuh. NMI received for unknown reason 30 on CPU 2. [ +0.000000] Do you have a strange power saving mode enabled? [ +0.000000] Dazed and confused, but trying to continue The bug was introduced by the following commit: commit 6f55967ad9d9 ("perf/x86/intel: Fix race in intel_pmu_disable_event()") The commit moves the intel_pmu_pebs_disable() after intel_pmu_disable_fixed(), which returns immediately. The related bit of PEBS_ENABLE MSR will never be cleared for the fixed counter. Then a non-PEBS event runs on the fixed counter, but the bit on PEBS_ENABLE is still set, which triggers spurious NMIs. Check and disable PEBS for fixed counters after intel_pmu_disable_fixed(). Reported-by: Yi, Ammy Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Acked-by: Jiri Olsa Cc: Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Fixes: 6f55967ad9d9 ("perf/x86/intel: Fix race in intel_pmu_disable_event()") Link: https://lkml.kernel.org/r/20190625142135.22112-1-kan.liang@linux.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2161,12 +2161,10 @@ static void intel_pmu_disable_event(stru cpuc->intel_ctrl_host_mask &= ~(1ull << hwc->idx); cpuc->intel_cp_status &= ~(1ull << hwc->idx); - if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) { + if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) intel_pmu_disable_fixed(hwc); - return; - } - - x86_pmu_disable_event(event); + else + x86_pmu_disable_event(event); /* * Needs to be called after x86_pmu_disable_event,