Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10481920ybi; Thu, 25 Jul 2019 00:04:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqx08ISbH66BK0Igi8um0kkTnAQgTdcyoMXEtYiOlFBcFwS18rfgGHyHv/2YYA5Z7i5UICmO X-Received: by 2002:a17:90a:db42:: with SMTP id u2mr91754349pjx.48.1564038281903; Thu, 25 Jul 2019 00:04:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564038281; cv=none; d=google.com; s=arc-20160816; b=wliPUJyxTT+Htn85AtQI1x2pjDoiQj5KlP709J7uonk1HV2b2JhXtArXhntrGmuRo5 AiZdNl2jPYGvyT91DTakbS+g+aF/EB2LuQF6IePo7R5mnMgvHWJXBq4CXF04m3z8T8bY H19jJ3cbAePyalyVQw0Fp4zqT1np+z2GarEurxqdEFa2VQI9k6Kc/+32bjyYeMm8KUko dpguymQWb4SDdyxiKt+gndRW2AiPmzUx+ozyySZjYcJ8TZk7hQMO3xacGtW4UfLQ/pei rVuqSX0jsNC7L2xQhi5AWIImz0QvzKzCCa+n7kVZmbFtvm/TboUC9BE88AZcJF6lAlOE WyVw== 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=+huie0MRVx6aPEjjGG/Q8ll51nakITdqoTrRhe7zBnw=; b=BflB3KIOALOVNZrYIF4t92Wg5WC+/KDBkfXvrvQP5yGBMNSgB6JScWjzo4BKqC93w8 Sp4FMrSm53aPbFRVlOw8vNiWiai+b9YNc6UYDBAHPclhSZiMsbETTehhrI5Il2TWoaDZ b/wfr2HoEh/tlUjQ1vfuvsZz6Da76ATe58AjnO6kMotyIIti8hH3EINU97+otMQcL2E7 k2vUJpLCvYhKSiLgEMsWko0UW99mCsgMkQlnWo8qsg5H56w831oyTRdvw6UzzBn0+srH TQ/vNdb2GSpxuWldxey0WIzshCDT5+UJlzo86owZK9ZEIapPpqR+2pES+BD+1pdNztRN 6t3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wdkD2FJ0; 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 g3si18599217pgo.241.2019.07.25.00.04.27; Thu, 25 Jul 2019 00:04:41 -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=wdkD2FJ0; 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 S1729508AbfGYHBq (ORCPT + 99 others); Thu, 25 Jul 2019 03:01:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:34654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728097AbfGYHBq (ORCPT ); Thu, 25 Jul 2019 03:01:46 -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 1389920657; Thu, 25 Jul 2019 07:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564038105; bh=8YVVh3ZDx+QV67v4bqCdoi+CmlKP9V6fZTVJvPaXQ2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wdkD2FJ0eB9OcUMyhApkr9aH9MnvQXUOyzOQUVT5rDPdKcg98ibM3uMIl8TQzUi3s ElgUsWy6g/kI02Ocio2kvD69iggEuMPwAAOvKMwHIZwSiy6i5kTx4j+1AddeJNU3TE IljsxcYHKl1oM+8RrpI2aMs5Wo9boqa8YY2DK3Yc= 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.1 322/371] perf/x86/intel: Fix spurious NMI on fixed counter Date: Wed, 24 Jul 2019 21:21:14 +0200 Message-Id: <20190724191748.152212146@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191724.382593077@linuxfoundation.org> References: <20190724191724.382593077@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 @@ -2092,12 +2092,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,