Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2211146imm; Mon, 28 May 2018 04:02:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpwoFW1gHslQ+/eEw3WtGP5CvASjUficUpykeB4AtEWDNLT+1NFSZlKNw1FO2S1OXkFu6fS X-Received: by 2002:a17:902:8303:: with SMTP id bd3-v6mr13019557plb.290.1527505353220; Mon, 28 May 2018 04:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527505353; cv=none; d=google.com; s=arc-20160816; b=TKMCc+/yUNpnqo2E1PQhMrdMp9WdfBNd78qGuM05CvWtwYxIIlwxGOFO9SAa2L2kfT VCEeB3G/KAgpmw2PGwx3PqMesW8C9Tt42qmuY1ehMqP5E+kl+OHaqp7N54XWy+ZyTpw+ +IgWl226wzNOQWD990uy+5NV/5kkgU3xyCQeltm16oJhKHCcMCyVAWGUEvzuPpjK7mKU iFFJiGn7wnfX7oW+XL7a6T3rE0R4RyFjtIyYEEQnZKQtw216Bs2QIcxuDT4v+ex7HZ+9 mXYyBeMsGUuz9v9Wxq6fbllPhyNG5M+GcUM5YgyTzY1VXpTc08WpE9N+UqTlwPMxPd5m +wNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=TgLjijy8NQoVnXi+cjSFlBAaW17mSVugHX8G72ATXGM=; b=DpLcV9NTp76sgbgEpX3eglVKANRwNokswKuJ9grpvXbfxk6hbwiqYz3OAyhpuWlmkU Y9Ej1XimD5aF/BsqgyjaPG3ELWBvFcgo0T0JAKjQ3GyX0X+zED0ZtGFmq3+9VjSEYiyA cYSK5C6rnyoPnnBIa284rrd6cAXRl5asymLBlcFko23rEAWBmmaxuskFbjBGMq9uY0Yg HQEcHH8ddRTMiFIDH66mqXgzDU/S4Nh8SB6kQe9W/K9fpFL4VRflG5jD7YOS3krLiPEm y6WtRmgOtHXOrWXvdYY/qvqai2pGsg5Hukw2va6FsjM2YGURwwxRPvQqeXF+S4SBM+qq /62w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LLGTvrFy; 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 j6-v6si24140407pgc.509.2018.05.28.04.02.18; Mon, 28 May 2018 04:02:33 -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=LLGTvrFy; 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 S1164813AbeE1LAy (ORCPT + 99 others); Mon, 28 May 2018 07:00:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:48370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422680AbeE1LAr (ORCPT ); Mon, 28 May 2018 07:00:47 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 7A049208A1; Mon, 28 May 2018 11:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505247; bh=TUHajU2FubZZmU1oijb4iGCV6ZVQ4CyMZ89W7KoKzSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LLGTvrFyBLxwRhB9AnOIaVP/DJF4toghIIeLjkZigIJ7+j+Ld7jp88CL6LG8jGkVq c5eMQoewAGOAATacHvPBkRfalx0WZgF0fIr1YW2j92aqE0Yp+LLsuFUiw6c4ZnsrqB OMmPctg84bAYunt0y4mEpzOOT5EniAGavtXaiiDQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kan Liang , "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , acme@kernel.org, kernel test robot , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 429/496] perf/x86/intel: Properly save/restore the PMU state in the NMI handler Date: Mon, 28 May 2018 12:03:34 +0200 Message-Id: <20180528100337.822073982@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kan Liang [ Upstream commit 82d71ed0277efc45360828af8c4e4d40e1b45352 ] The PMU is disabled in intel_pmu_handle_irq(), but cpuc->enabled is not updated accordingly. This is fine in current usage because no-one checks it - but fix it for future code: for example, the drain_pebs() will be modified to fix an auto-reload bug. Properly save/restore the old PMU state. Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) 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 Cc: acme@kernel.org Cc: kernel test robot Link: http://lkml.kernel.org/r/6f44ee84-56f8-79f1-559b-08e371eaeb78@linux.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2201,16 +2201,23 @@ static int intel_pmu_handle_irq(struct p int bit, loops; u64 status; int handled; + int pmu_enabled; cpuc = this_cpu_ptr(&cpu_hw_events); /* + * Save the PMU state. + * It needs to be restored when leaving the handler. + */ + pmu_enabled = cpuc->enabled; + /* * No known reason to not always do late ACK, * but just in case do it opt-in. */ if (!x86_pmu.late_ack) apic_write(APIC_LVTPC, APIC_DM_NMI); intel_bts_disable_local(); + cpuc->enabled = 0; __intel_pmu_disable_all(); handled = intel_pmu_drain_bts_buffer(); handled += intel_bts_interrupt(); @@ -2320,7 +2327,8 @@ again: done: /* Only restore PMU state when it's active. See x86_pmu_disable(). */ - if (cpuc->enabled) + cpuc->enabled = pmu_enabled; + if (pmu_enabled) __intel_pmu_enable_all(0, true); intel_bts_enable_local();