From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754150AbaIVNqe (ORCPT ); Mon, 22 Sep 2014 09:46:34 -0400 Received: from v094114.home.net.pl ([79.96.170.134]:61020 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753625AbaIVNqb (ORCPT ); Mon, 22 Sep 2014 09:46:31 -0400 From: "Rafael J. Wysocki" To: Viresh Kumar , Prarit Bhargava Cc: Linux Kernel Mailing List , "linux-pm@vger.kernel.org" Subject: Re: [PATCH] cpufreq, release policy->rwsem on error Date: Mon, 22 Sep 2014 16:06:17 +0200 Message-ID: <13071541.1DqE9E64rV@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/3.16.0-rc5+; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: <1410358328-27303-1-git-send-email-prarit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday, September 11, 2014 10:05:43 AM Viresh Kumar wrote: > On 10 September 2014 19:42, Prarit Bhargava wrote: > > I have not been able to reliably reproduce the hardware failure that caused > > the warning. In order to reproduce this I resorted to (sorry for the > > cut-and-paste) > > > > diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c > > index 728a2d8..c7724d2 100644 > > --- a/drivers/cpufreq/pcc-cpufreq.c > > +++ b/drivers/cpufreq/pcc-cpufreq.c > > @@ -146,6 +146,8 @@ static unsigned int pcc_get_freq(unsigned int cpu) > > u32 input_buffer; > > u32 output_buffer; > > > > + return 0; > > + > > spin_lock(&pcc_lock); > > > > pr_debug("get: get_freq for CPU %d\n", cpu); > > > > to simulate the cpufreq_driver->get() hardware failure. > > > > ---8<--- > > > > While debugging a cpufreq-related hardware failure on a system I saw the > > following lockdep warning: > > > > ========================= > > [ BUG: held lock freed! ] 3.17.0-rc4+ #1 Tainted: G E > > ------------------------- > > insmod/2247 is freeing memory ffff88006e1b1400-ffff88006e1b17ff, with a lock still held there! > > (&policy->rwsem){+.+...}, at: [] __cpufreq_add_dev.isra.21+0x47d/0xb80 > > 3 locks held by insmod/2247: > > #0: (subsys mutex#5){+.+.+.}, at: [] subsys_interface_register+0x69/0x120 > > #1: (cpufreq_rwsem){.+.+.+}, at: [] __cpufreq_add_dev.isra.21+0x73/0xb80 > > #2: (&policy->rwsem){+.+...}, at: [] __cpufreq_add_dev.isra.21+0x47d/0xb80 > > > > stack backtrace: > > CPU: 0 PID: 2247 Comm: insmod Tainted: G E 3.17.0-rc4+ #1 > > Hardware name: HP ProLiant MicroServer Gen8, BIOS J06 08/24/2013 > > 0000000000000000 000000008f3063c4 ffff88006f87bb30 ffffffff8171b358 > > ffff88006bcf3750 ffff88006f87bb68 ffffffff810e09e1 ffff88006e1b1400 > > ffffea0001b86c00 ffffffff8156d327 ffff880073003500 0000000000000246 > > Call Trace: > > [] dump_stack+0x4d/0x66 > > [] debug_check_no_locks_freed+0x171/0x180 > > [] ? __cpufreq_add_dev.isra.21+0x427/0xb80 > > [] kfree+0xab/0x2b0 > > [] __cpufreq_add_dev.isra.21+0x427/0xb80 > > [] ? _raw_spin_unlock+0x27/0x40 > > [] ? pcc_cpufreq_do_osc+0x17f/0x17f [pcc_cpufreq] > > [] cpufreq_add_dev+0xe/0x10 > > [] subsys_interface_register+0xc1/0x120 > > [] cpufreq_register_driver+0x112/0x340 > > [] ? kfree+0xda/0x2b0 > > [] ? pcc_cpufreq_do_osc+0x17f/0x17f [pcc_cpufreq] > > [] pcc_cpufreq_init+0x4af/0xe81 [pcc_cpufreq] > > [] ? pcc_cpufreq_do_osc+0x17f/0x17f [pcc_cpufreq] > > [] do_one_initcall+0xd4/0x210 > > [] ? __vunmap+0xd2/0x120 > > [] load_module+0x1315/0x1b70 > > [] ? store_uevent+0x70/0x70 > > [] ? copy_module_from_fd.isra.44+0x129/0x180 > > [] SyS_finit_module+0xa6/0xd0 > > [] system_call_fastpath+0x16/0x1b > > cpufreq: __cpufreq_add_dev: ->get() failed > > insmod: ERROR: could not insert module pcc-cpufreq.ko: No such device > > > > The warning occurs in the __cpufreq_add_dev() code which does > > > > down_write(&policy->rwsem); > > ... > > if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { > > policy->cur = cpufreq_driver->get(policy->cpu); > > if (!policy->cur) { > > pr_err("%s: ->get() failed\n", __func__); > > goto err_get_freq; > > } > > > > If cpufreq_driver->get(policy->cpu) returns an error we execute the > > code at err_get_freq, which does not up the policy->rwsem. This causes > > the lockdep warning. > > > > Trivial patch to up the policy->rwsem in the error path. > > > > After the patch has been applied, and an error occurs in the > > cpufreq_driver->get(policy->cpu) call we will now see > > > > cpufreq: __cpufreq_add_dev: ->get() failed > > cpufreq: __cpufreq_add_dev: ->get() failed > > modprobe: ERROR: could not insert 'pcc_cpufreq': No such device > > > > Signed-off-by: Prarit Bhargava > > Cc: "Rafael J. Wysocki" > > Cc: Viresh Kumar > > Cc: linux-pm@vger.kernel.org > > --- > > drivers/cpufreq/cpufreq.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > > index d9fdedd..aadaed0 100644 > > --- a/drivers/cpufreq/cpufreq.c > > +++ b/drivers/cpufreq/cpufreq.c > > @@ -1289,6 +1289,8 @@ err_get_freq: > > per_cpu(cpufreq_cpu_data, j) = NULL; > > write_unlock_irqrestore(&cpufreq_driver_lock, flags); > > > > + up_write(&policy->rwsem); > > + > > if (cpufreq_driver->exit) > > cpufreq_driver->exit(policy); > > err_set_policy_cpu: Queued up for 3.17-rc7, thanks! > Fixes: "4e97b63 cpufreq: Initialize governor for a new policy under > policy->rwsem" > Stable: 3.14+ And thanks for the info above. > Acked-by: Viresh Kumar -- I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.