From patchwork Mon Nov 21 21:34:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 9440073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4673E600BA for ; Mon, 21 Nov 2016 21:37:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3836F287BB for ; Mon, 21 Nov 2016 21:37:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29B022888F; Mon, 21 Nov 2016 21:37:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15F37287BB for ; Mon, 21 Nov 2016 21:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753466AbcKUVhn (ORCPT ); Mon, 21 Nov 2016 16:37:43 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:57640 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752889AbcKUVhn (ORCPT ); Mon, 21 Nov 2016 16:37:43 -0500 Received: from localhost ([127.0.0.1]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1c8wEb-0005Jd-HF; Mon, 21 Nov 2016 22:34:41 +0100 Date: Mon, 21 Nov 2016 22:34:38 +0100 (CET) From: Thomas Gleixner To: "Pandruvada, Srinivas" cc: "linux-kernel@vger.kernel.org" , "Zhang, Rui" , "edubezval@gmail.com" , "peterz@infradead.org" , "bp@alien8.de" , "linux-pm@vger.kernel.org" , "x86@kernel.org" , "rt@linutronix.de" Subject: Re: [patch 00/12] thermal/x86_pkg_temp: Sanitize yet another hotplug and locking trainwreck In-Reply-To: <1479758532.6544.169.camel@intel.com> Message-ID: References: <20161117231435.891545908@linutronix.de> <1479758532.6544.169.camel@intel.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 21 Nov 2016, Pandruvada, Srinivas wrote: > On Fri, 2016-11-18 at 00:03 +0000, Thomas Gleixner wrote: > > We solely intended to convert that driver to the hotplug state > > machine and > > stumbled over a large pile of insanities, which are all interwoven > > with the > > package management: > > Thanks Thomas for fixes. > But I did a very simple test on 4.9.0-rc5 on a client machine, just > rmmod and read zone, it will cause crash. I have not tested on a multi- > socket system, which is also required where the real test of  last cpu > on a package goes offline can be tested. Stupid me. I tested putting a socket offline, which works, but did not check what happens on module removal. Delta fix below. That needs to be folded into the series as the wreckage already happens before the last patch. Thanks, tglx 8<-------------------- --- a/drivers/thermal/x86_pkg_temp_thermal.c +++ b/drivers/thermal/x86_pkg_temp_thermal.c @@ -63,6 +63,7 @@ struct pkg_device { u32 msr_pkg_therm_high; struct delayed_work work; struct thermal_zone_device *tzone; + struct cpumask cpumask; }; static struct thermal_zone_params pkg_temp_tz_params = { @@ -391,6 +392,7 @@ static int pkg_temp_thermal_device_add(u rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, pkgdev->msr_pkg_therm_low, pkgdev->msr_pkg_therm_high); + cpumask_set_cpu(cpu, &pkgdev->cpumask); spin_lock_irq(&pkg_temp_lock); packages[pkgid] = pkgdev; spin_unlock_irq(&pkg_temp_lock); @@ -399,13 +401,15 @@ static int pkg_temp_thermal_device_add(u static int pkg_thermal_cpu_offline(unsigned int cpu) { - int target = cpumask_any_but(topology_core_cpumask(cpu), cpu); struct pkg_device *pkgdev = pkg_temp_thermal_get_dev(cpu); bool lastcpu, was_target; + int target; if (!pkgdev) return 0; + target = cpumask_any_but(&pkgdev->cpumask, cpu); + cpumask_clear_cpu(cpu, &pkgdev->cpumask); lastcpu = target >= nr_cpu_ids; /* @@ -492,8 +496,10 @@ static int pkg_thermal_cpu_online(unsign return -ENODEV; /* If the package exists, nothing to do */ - if (pkgdev) + if (pkgdev) { + cpumask_set_cpu(cpu, &pkgdev->cpumask); return 0; + } return pkg_temp_thermal_device_add(cpu); }