Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2240809imm; Mon, 28 May 2018 04:35:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrEegYvCuN14k6I+DNFgOLWompOIPKN+lXrtwJReKY1lISbP+LJig5ZI+LiDgFlgA76jPTl X-Received: by 2002:a62:b509:: with SMTP id y9-v6mr13168704pfe.121.1527507330621; Mon, 28 May 2018 04:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527507330; cv=none; d=google.com; s=arc-20160816; b=gzsxV8izP8iqnzQwC/qJX8qm4//aryAvXmLKz7VVr+C60QKgksfwMqi9YBik5u2iaY P0HBL+XzzFOtQ5tFrsL62xtc8jyiBMABWy5mP+ubsq3NerjIZLLWSaavOKWrmM/OyLUi BRDdbl9RghrAuOngd2M7os3UHjlUvrNIwmGOuvuw3qyQ6chjnFXBjfg0buSnNso3kuKj Mk+/tfMTf8FbzT/sATncP0XCEEHTxnUMAbG7lxZURJEtgH/rt/CAJrhUW23ABJUqRIzw I7UhxZSO7+oAGsUsnJjqzDBvMPhb9pjBLQI3Rz8HmAfCfT0hQS/paEZOpBPrwCE11z44 cy7Q== 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=Czk7O0SPkHetPAUo8FA78RJfGpYNbNhhNkp+2+5Cths=; b=o2jCUnep/QvWkOwdYdzd0wSWdJTVyTozKZZCXym8AK7mmLATKbf290na7sp0I8BdZk vWrTtAQB+wKdNnruJaj5Eix9DnpyYJ5Kp6c4Edul5KIKr7RAGcgQKGJGAzlSoZtM+nrY Dk4ANKbSeohQusIUXVkTN1qtECaCIVzaymSNkfiqyKZ0acxrjfSQaXNxEqj917CM0xeV Iwgos2jQimxnamfLS4j4soh11pToG/F9ztzMWNS7x+D20R3gT+KEbcU+my/QzPcYQXPV OclL1ZW/0jzQsm7XnwR+ClbQLdE+T8swVZmmNPH9aX4prEmyXtUVODh34UYtkm6MKksY 4tMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v8vHhNo7; 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 d17-v6si23452179pgp.214.2018.05.28.04.35.15; Mon, 28 May 2018 04:35:30 -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=v8vHhNo7; 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 S1424421AbeE1Le3 (ORCPT + 99 others); Mon, 28 May 2018 07:34:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:33010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424293AbeE1LNm (ORCPT ); Mon, 28 May 2018 07:13:42 -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 371CB2089E; Mon, 28 May 2018 11:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527506022; bh=Vcz0/kk1qdHd48BFEL69iroGibWVCkpJ8OeHxumXO1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v8vHhNo7W/j1v/6dYBXReG2pchXwKLRK2gB2qrnPCyixM8NYXQZ0C2/nwY1ptoLvm pLSJha1uaoJRMHkthf+Uy+ovKqiog22949EAYGeNW/46Eu4Uk7/eT5Uuy9y8rqZFOU F9we1byE0gj5qE4nWMBWYsXgqyA0hym2GAaRTGD0= 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.16 189/272] perf/x86/intel: Properly save/restore the PMU state in the NMI handler Date: Mon, 28 May 2018 12:03:42 +0200 Message-Id: <20180528100256.516703715@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@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.16-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();