From patchwork Mon Jan 11 17:35:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juri Lelli X-Patchwork-Id: 8007461 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CCA85BEEE5 for ; Mon, 11 Jan 2016 17:41:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2F48D201FE for ; Mon, 11 Jan 2016 17:41:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2DEBD20304 for ; Mon, 11 Jan 2016 17:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761491AbcAKRkO (ORCPT ); Mon, 11 Jan 2016 12:40:14 -0500 Received: from foss.arm.com ([217.140.101.70]:57248 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761161AbcAKRha (ORCPT ); Mon, 11 Jan 2016 12:37:30 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 26F7F5F7; Mon, 11 Jan 2016 09:36:55 -0800 (PST) Received: from e106622-lin.cambridge.arm.com (e106622-lin.cambridge.arm.com [10.1.208.152]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1C64C3F24D; Mon, 11 Jan 2016 09:37:27 -0800 (PST) From: Juri Lelli To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, peterz@infradead.org, rjw@rjwysocki.net, viresh.kumar@linaro.org, mturquette@baylibre.com, steve.muckle@linaro.org, vincent.guittot@linaro.org, morten.rasmussen@arm.com, dietmar.eggemann@arm.com, juri.lelli@arm.com Subject: [RFC PATCH 09/19] cpufreq: fix warning for show_scaling_available_governors unlocked access to cpufreq_governor_list Date: Mon, 11 Jan 2016 17:35:50 +0000 Message-Id: <1452533760-13787-10-git-send-email-juri.lelli@arm.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1452533760-13787-1-git-send-email-juri.lelli@arm.com> References: <1452533760-13787-1-git-send-email-juri.lelli@arm.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP show_scaling_available_governors iterates through cpufreq_governor_list without holding cpufreq_governor_mutex; this generates the following warning: [ 700.910381] ------------[ cut here ]------------ [ 700.924282] WARNING: CPU: 2 PID: 1756 at kernel/drivers/cpufreq/cpufreq.c:700 show_scaling_available_governors+0x6f/0xb8() [ 700.965473] Modules linked in: [ 700.974637] CPU: 2 PID: 1756 Comm: cat Tainted: G W 4.4.0-rc2+ #299 [ 700.996813] Hardware name: ARM-Versatile Express [ 701.010674] [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [ 701.033905] [] (show_stack) from [] (dump_stack+0x55/0x78) [ 701.055561] [] (dump_stack) from [] (warn_slowpath_common+0x59/0x84) [ 701.079839] [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) [ 701.106182] [] (warn_slowpath_null) from [] (show_scaling_available_governors+0x6f/0xb8) [ 701.135656] [] (show_scaling_available_governors) from [] (show+0x27/0x38) [ 701.161488] [] (show) from [] (sysfs_kf_seq_show+0x5f/0xa0) [ 701.183409] [] (sysfs_kf_seq_show) from [] (kernfs_seq_show+0x1b/0x1c) [ 701.208188] [] (kernfs_seq_show) from [] (seq_read+0x129/0x33c) [ 701.231161] [] (seq_read) from [] (__vfs_read+0x1b/0x84) [ 701.252300] [] (__vfs_read) from [] (vfs_read+0x5f/0xb0) [ 701.273436] [] (vfs_read) from [] (SyS_read+0x39/0x68) [ 701.294049] [] (SyS_read) from [] (ret_fast_syscall+0x1/0x1a) [ 701.316484] ---[ end trace 5dd15744a4da127c ]--- Fix this by locking cpufreq_governor_mutex before for_each_governor(). Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Signed-off-by: Juri Lelli --- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index d065435..d91fdb8 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -694,7 +694,7 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, goto out; } - lockdep_assert_held(&cpufreq_governor_mutex); + mutex_lock(&cpufreq_governor_mutex); for_each_governor(t) { if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - (CPUFREQ_NAME_LEN + 2))) @@ -702,6 +702,7 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); } out: + mutex_unlock(&cpufreq_governor_mutex); i += sprintf(&buf[i], "\n"); return i; }