From patchwork Tue Mar 4 03:44:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 25644 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 36800206F3 for ; Tue, 4 Mar 2014 03:44:58 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id lx4sf7774406iec.11 for ; Mon, 03 Mar 2014 19:44:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=ijlcfyBdBPlbvOUFcoSO6LpguHAHkBBhTEo5orymr5A=; b=gZ1B5i6F/9LwHhmHvjdTemSWd3fpt3/rgr9LbcWp6kiz5KXgaaS4cJEP2+PpHqy3Hv x/q7MhzezXKcAjcS7Iig126VTyuni8QJji19B4iV3SBvIX/nbul0gMH/Iicokk92dmgr gpUMDmyaJqiXq1r+JCJ+7n6xHjYk7FiM6zM1U9fjWgBJnnsuJI6UYmXlF+0QjoUAi0Ya 7ydNq/z8ben//zItE915SiXLX+jbWJTWDJ6NoKPghA+AkC690/h9o1qBzmcl5I7ByLgv xwgQ1kkT7WsNok/m4+eqDuruXl1cDTSFt4PFQR+gna9k4DKRa8nGKae8o/RkJmtCfYJ8 a19w== X-Gm-Message-State: ALoCoQmTVc3/70ETlVSdaZvXebrSUEAhsR4PMwNJ5xDKdT9nQZUKwTFxaztf+OCEiFxNGLgjv3Wa X-Received: by 10.182.216.200 with SMTP id os8mr15858250obc.0.1393904697584; Mon, 03 Mar 2014 19:44:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.35 with SMTP id 32ls2407752qgu.80.gmail; Mon, 03 Mar 2014 19:44:57 -0800 (PST) X-Received: by 10.52.186.230 with SMTP id fn6mr2179850vdc.14.1393904697435; Mon, 03 Mar 2014 19:44:57 -0800 (PST) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id b2si5431354vcy.85.2014.03.03.19.44.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Mar 2014 19:44:57 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id cz12so4788447veb.21 for ; Mon, 03 Mar 2014 19:44:57 -0800 (PST) X-Received: by 10.58.202.4 with SMTP id ke4mr19427518vec.7.1393904697342; Mon, 03 Mar 2014 19:44:57 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.130.193 with SMTP id u1csp98971vcs; Mon, 3 Mar 2014 19:44:56 -0800 (PST) X-Received: by 10.66.141.197 with SMTP id rq5mr3494600pab.64.1393904696167; Mon, 03 Mar 2014 19:44:56 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn5si12668690pbc.56.2014.03.03.19.44.55; Mon, 03 Mar 2014 19:44:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756195AbaCDDoh (ORCPT + 11 others); Mon, 3 Mar 2014 22:44:37 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:46671 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756163AbaCDDoe (ORCPT ); Mon, 3 Mar 2014 22:44:34 -0500 Received: by mail-pa0-f46.google.com with SMTP id kp14so4566010pab.19 for ; Mon, 03 Mar 2014 19:44:34 -0800 (PST) X-Received: by 10.66.164.70 with SMTP id yo6mr3350803pab.85.1393904674051; Mon, 03 Mar 2014 19:44:34 -0800 (PST) Received: from localhost (z88l218.static.ctm.net. [202.175.88.218]) by mx.google.com with ESMTPSA id q7sm41965557pbc.20.2014.03.03.19.44.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Mar 2014 19:44:33 -0800 (PST) From: Viresh Kumar To: rjw@rjwysocki.net, skannan@codeaurora.org Cc: linaro-kernel@lists.linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, srivatsa.bhat@linux.vnet.ibm.com, Viresh Kumar Subject: [PATCH V2 3/3] cpufreq: initialize governor for a new policy under policy->rwsem Date: Tue, 4 Mar 2014 11:44:01 +0800 Message-Id: <2f6efe0c9058f64212ee220a1b386e04ba415686.1393904428.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> References: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> In-Reply-To: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> References: <98b7ae22d936456bf830aa749556a115969cfa47.1393904428.git.viresh.kumar@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , policy->rwsem is used to lock access to all parts of code modifying struct cpufreq_policy but wasn't used on a new policy created from __cpufreq_add_dev(). Because of which if we call cpufreq_update_policy() repeatedly on one CPU and do offline/online of another CPU then we might see these crashes: Unable to handle kernel NULL pointer dereference at virtual address 00000020 pgd = c0003000 [00000020] *pgd=80000000004003, *pmd=00000000 Internal error: Oops: 206 [#1] PREEMPT SMP ARM PC is at __cpufreq_governor+0x10/0x1ac LR is at cpufreq_update_policy+0x114/0x150 ---[ end trace f23a8defea6cd706 ]--- Kernel panic - not syncing: Fatal exception CPU0: stopping CPU: 0 PID: 7136 Comm: mpdecision Tainted: G D W 3.10.0-gd727407-00074-g979ede8 #396 [] (notifier_call_chain+0x40/0x68) from [] (__blocking_notifier_call_chain+0x40/0x58) [] (__blocking_notifier_call_chain+0x40/0x58) from [] (blocking_notifier_call_chain+0x14/0x1c) [] (blocking_notifier_call_chain+0x14/0x1c) from [] (cpufreq_set_policy+0xd4/0x2b8) [] (cpufreq_set_policy+0xd4/0x2b8) from [] (cpufreq_init_policy+0x30/0x98) [] (cpufreq_init_policy+0x30/0x98) from [] (__cpufreq_add_dev.isra.17+0x4dc/0x7a4) [] (__cpufreq_add_dev.isra.17+0x4dc/0x7a4) from [] (cpufreq_cpu_callback+0x58/0x84) [] (cpufreq_cpu_callback+0x58/0x84) from [] (notifier_call_chain+0x40/0x68) [] (notifier_call_chain+0x40/0x68) from [] (__cpu_notify+0x28/0x44) [] (__cpu_notify+0x28/0x44) from [] (_cpu_up+0xf4/0x1dc) [] (_cpu_up+0xf4/0x1dc) from [] (cpu_up+0x5c/0x78) [] (cpu_up+0x5c/0x78) from [] (store_online+0x44/0x74) [] (store_online+0x44/0x74) from [] (sysfs_write_file+0x108/0x14c) [] (sysfs_write_file+0x108/0x14c) from [] (vfs_write+0xd0/0x180) [] (vfs_write+0xd0/0x180) from [] (SyS_write+0x38/0x68) [] (SyS_write+0x38/0x68) from [] (ret_fast_syscall+0x0/0x30) Fix these by taking locks at appropriate places in __cpufreq_add_dev() as well. Reported-by: Saravana Kannan Suggested-by: Srivatsa S. Bhat Signed-off-by: Viresh Kumar --- V1->V2: No change drivers/cpufreq/cpufreq.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 3c6f9a5..e2a1e67 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1128,6 +1128,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, policy->user_policy.max = policy->max; } + down_write(&policy->rwsem); write_lock_irqsave(&cpufreq_driver_lock, flags); for_each_cpu(j, policy->cpus) per_cpu(cpufreq_cpu_data, j) = policy; @@ -1202,6 +1203,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, policy->user_policy.policy = policy->policy; policy->user_policy.governor = policy->governor; } + up_write(&policy->rwsem); kobject_uevent(&policy->kobj, KOBJ_ADD); up_read(&cpufreq_rwsem);