Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10481473ybi; Thu, 25 Jul 2019 00:04:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0zhbpL+ngsYOhQxEb9hZBP6cOM+4cbncJEi2ozcexEtaqmeIKOu3Xto6UfEFMsD36DOGj X-Received: by 2002:a17:902:145:: with SMTP id 63mr92312590plb.55.1564038254230; Thu, 25 Jul 2019 00:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564038254; cv=none; d=google.com; s=arc-20160816; b=J9XizdUVGJ2rhPS8U6G4JvNeLxbUjXM5T60HW/XVPUeE+jhGK3Z96+n1CQpRfgcjvk wMNfTr/M4LVDLGMu5aDlodch7lAEQzoEWwxawMb1N0uI6kRLsIvWBbf+N/Gvxc8YJIjs +7X/N33aL3/rVg9j69iBPUopp+lujFbaM+Vzyd2hEISh8b4QDJKzFNruE9pStsbEDmbG i5TXV+hoGTX9uTIKOv4NVapEJVKD+cgxIE5bKIoWIB6d1JLlWu3fuXp+FzI3irUqrjpn n7Jg5SxeA/O2Thl2UfjOInsm4FwyP1nTnKNcX7qpc2Su+doQUiUQ+4UmQqIuPS2OIgVK 5Tug== 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=8V7hBHFnwjXhbcFi/cfF9A/R3dWarlhigkDqYw77z8M=; b=NhKT96cwFgrRd9TWIaqvXN9WbNZLZLaAAkQfhU0KSxPLN+eEW2fYv6UlNq178v3A4w N50hDFIkpYrecybesYTiH0ii15dA3U177nv7O2GD0Sek5Xm6WnIRWfIXTRrtOtXKJIr2 CMb+/5jTtVk+TUPNx7Xip1ie9RuB0H7yjci0L4MguehxfSerKy0m2MPcZaMqINxVJsJp jJdEuCbiz1B7YmEYLgBGz0FCcX+xBxjD8UtjXaw67a0TRvqxYPyM4SuDNPPXmUB2FeCV Xl+HUeuAwaDEyM+hhQWW0dhwM92nrqIsmRYHlN+QmVHiYTou+2DxE5IomSpcS4LL7H0W 4jsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XjJqtVQv; 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 r19si16784300pfh.50.2019.07.25.00.03.59; Thu, 25 Jul 2019 00:04:14 -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=XjJqtVQv; 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 S1729465AbfGYHB0 (ORCPT + 99 others); Thu, 25 Jul 2019 03:01:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:34510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728097AbfGYHBY (ORCPT ); Thu, 25 Jul 2019 03:01:24 -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 DB7BF20657; Thu, 25 Jul 2019 07:01:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564038083; bh=zAjhHSsJhZ6oAn03Z7pWLillY7bVUdhE6rcmIWjShpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XjJqtVQv5/q2UhBZY205lrIvIaIE6hTj2YLzE3d8t5b2i/vWhU0kzcHzgDgAwBaV1 AKUyhWIGwGykoGelnUF4pHIKN5UF46AVkm+6WoRKI2uOM95niPjKv3tPlKTI4R/nhK BvxkvjW65pMrAkqtZtO+ROSqlitmm5K8f5lcoF+4= 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 4.19 224/271] perf/x86/intel: Fix spurious NMI on fixed counter Date: Wed, 24 Jul 2019 21:21:33 +0200 Message-Id: <20190724191714.344365170@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 @@ -2074,12 +2074,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,