Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6373440ybl; Wed, 15 Jan 2020 03:38:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxICEN0nRFO6RMty5IxwRSuZMjwxJwxJ5TpQSZJZ+bzTWshkpZrCfEg6T+c85u+7OxfHONb X-Received: by 2002:a05:6830:4c2:: with SMTP id s2mr2465011otd.144.1579088304414; Wed, 15 Jan 2020 03:38:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579088304; cv=none; d=google.com; s=arc-20160816; b=vC5lNExwb9O3kRWjRbPqCJNqedjW+lVGsc4eoYWmHfT007nd2/Jq5ewGtecdZpZ/P1 iKX5PM+KYkkNscLWypUJgneWAuqNJVO1eNSpjo4g/89iRvKEQZLCrvGG4YPSSMWwtpdD MC0LddYx+Pt6SU5EXcsIIenmVAaBz0pUb2X1J4r/UW8t4sKv4SDUfNQGaOD8e2EYPYav b1YU1aU76vOzzVgw1k5oY9VBmuOIo6jT4anA4hvRmS1Ax7qFh8maX91UGk/FR8vbzjz6 i6M3dNhxh2tVi8OilHrB2j1Brcx36nenmOKGW4HS2QcruaeE39KDiEgtONlYyf0rEI9L AZiw== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=nsUoolABL03sijjqfZnxOiMeY5XIIUTCy09szAvoV5Y=; b=vLVvGuUimph8xUmQkDOEh86fxfar3zQm1VPtzOw5zrs3fhBS6ceY7QbNoTpZkbH+Cx +kk3Qais5SevYFMqVaP9ahXtKGftI8Vl3CJ0ydptBSbCDJFcEwk97ZOlmqCwvKSoN64a 6epfH0u74bqlGURR7FqrxMH2pNqBmhV6H1iYG29lXCUVN3S+Im25fvW+AbuCly1GDXDG 5e0jr6K3AdXIYz9Jbt9wXIxykbT9naP7Vu9WfJ5FDZMeQhV3tP7n+4gxnbfd8zIrYKlO RSzEypRPagYxxyKA5SjJOi6i9JBWV+y4laOJnHi5tendJR72qtvnRg0jNZ+9/wUvMEg2 xeFQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d20si10380768otq.157.2020.01.15.03.38.11; Wed, 15 Jan 2020 03:38:24 -0800 (PST) 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; 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 S1729976AbgAOLhS (ORCPT + 99 others); Wed, 15 Jan 2020 06:37:18 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:46866 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729892AbgAOLhS (ORCPT ); Wed, 15 Jan 2020 06:37:18 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1irgyx-0002fw-Ud; Wed, 15 Jan 2020 12:37:08 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 8546E1C086F; Wed, 15 Jan 2020 12:37:07 +0100 (CET) Date: Wed, 15 Jan 2020 11:37:07 -0000 From: "tip-bot2 for Chuansheng Liu" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: ras/urgent] x86/mce/therm_throt: Do not access uninitialized therm_work Cc: Chuansheng Liu , Borislav Petkov , Tony Luck , x86 , LKML In-Reply-To: <20200107004116.59353-1-chuansheng.liu@intel.com> References: <20200107004116.59353-1-chuansheng.liu@intel.com> MIME-Version: 1.0 Message-ID: <157908822728.396.5161866899997303064.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the ras/urgent branch of tip: Commit-ID: 978370956d2046b19313659ce65ed12d5b996626 Gitweb: https://git.kernel.org/tip/978370956d2046b19313659ce65ed12d5b996626 Author: Chuansheng Liu AuthorDate: Tue, 07 Jan 2020 00:41:16 Committer: Borislav Petkov CommitterDate: Wed, 15 Jan 2020 11:31:33 +01:00 x86/mce/therm_throt: Do not access uninitialized therm_work It is relatively easy to trigger the following boot splat on an Ice Lake client platform. The call stack is like: kernel BUG at kernel/timer/timer.c:1152! Call Trace: __queue_delayed_work queue_delayed_work_on therm_throt_process intel_thermal_interrupt ... The reason is that a CPU's thermal interrupt is enabled prior to executing its hotplug onlining callback which will initialize the throttling workqueues. Such a race can lead to therm_throt_process() accessing an uninitialized therm_work, leading to the above BUG at a very early bootup stage. Therefore, unmask the thermal interrupt vector only after having setup the workqueues completely. [ bp: Heavily massage commit message and correct comment formatting. ] Fixes: f6656208f04e ("x86/mce/therm_throt: Optimize notifications of thermal throttle") Signed-off-by: Chuansheng Liu Signed-off-by: Borislav Petkov Acked-by: Tony Luck Link: https://lkml.kernel.org/r/20200107004116.59353-1-chuansheng.liu@intel.com --- arch/x86/kernel/cpu/mce/therm_throt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/therm_throt.c b/arch/x86/kernel/cpu/mce/therm_throt.c index b38010b..6c3e1c9 100644 --- a/arch/x86/kernel/cpu/mce/therm_throt.c +++ b/arch/x86/kernel/cpu/mce/therm_throt.c @@ -467,6 +467,7 @@ static int thermal_throttle_online(unsigned int cpu) { struct thermal_state *state = &per_cpu(thermal_state, cpu); struct device *dev = get_cpu_device(cpu); + u32 l; state->package_throttle.level = PACKAGE_LEVEL; state->core_throttle.level = CORE_LEVEL; @@ -474,6 +475,10 @@ static int thermal_throttle_online(unsigned int cpu) INIT_DELAYED_WORK(&state->package_throttle.therm_work, throttle_active_work); INIT_DELAYED_WORK(&state->core_throttle.therm_work, throttle_active_work); + /* Unmask the thermal vector after the above workqueues are initialized. */ + l = apic_read(APIC_LVTTHMR); + apic_write(APIC_LVTTHMR, l & ~APIC_LVT_MASKED); + return thermal_throttle_add_dev(dev, cpu); } @@ -722,10 +727,6 @@ void intel_init_thermal(struct cpuinfo_x86 *c) rdmsr(MSR_IA32_MISC_ENABLE, l, h); wrmsr(MSR_IA32_MISC_ENABLE, l | MSR_IA32_MISC_ENABLE_TM1, h); - /* Unmask the thermal vector: */ - l = apic_read(APIC_LVTTHMR); - apic_write(APIC_LVTTHMR, l & ~APIC_LVT_MASKED); - pr_info_once("CPU0: Thermal monitoring enabled (%s)\n", tm2 ? "TM2" : "TM1");