From patchwork Wed Oct 29 15:45:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 5188951 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E3E879F30B for ; Wed, 29 Oct 2014 15:46:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 076722015A for ; Wed, 29 Oct 2014 15:46:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF8B920131 for ; Wed, 29 Oct 2014 15:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933770AbaJ2PqT (ORCPT ); Wed, 29 Oct 2014 11:46:19 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:51507 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933664AbaJ2PqQ (ORCPT ); Wed, 29 Oct 2014 11:46:16 -0400 Received: by mail-wi0-f179.google.com with SMTP id h11so4969118wiw.6 for ; Wed, 29 Oct 2014 08:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=pZaxmOQ+k1DbcmHOhJaOiP5t3nCj6mD0PouDBoV5Pss=; b=kCgE97CVk7RBE22HEJ3v+KQ6Sqx94+OWsGchZieeqn07jg3d3ddy9Sf2ehAbSk4D2o ZkLMP5hMg40ENzMr321LBi8wf4xZF1prVDpnD1QSFgC4TdIP4PcURTf+JjW2Eju+rIlV EnXOZzHwJyU+lXGQGG1f2JKFiFim9ueLXfaRok0XxS58cTX0IFxLrQ5dERxaMVTzNA+s in0VnKD2tbIXd9C7jWC4PTdfWxFK6kbZIMojkbS/rnieMRE6vgg1jsSH5BGeHCETyKAP FOace+FmFNcAnAMsYNNlENv/wZFQ1VAOzFMtI0csWPRsesNX7Lwfa88IjVSfYEzc1SOn eAwQ== X-Received: by 10.194.243.164 with SMTP id wz4mr3741081wjc.129.1414597575046; Wed, 29 Oct 2014 08:46:15 -0700 (PDT) Received: from cizrna.lan (37-48-36-243.tmcz.cz. [37.48.36.243]) by mx.google.com with ESMTPSA id ny6sm19110233wic.22.2014.10.29.08.46.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Oct 2014 08:46:14 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Cc: Javier Martinez Canillas , Tomeu Vizoso , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH v2] cpufreq: Guard against not-yet-initialized policies in cpufreq_cpu_get() Date: Wed, 29 Oct 2014 16:45:47 +0100 Message-Id: <1414597547-16506-1-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <20141029024426.GA7468@kroah.com> References: <20141029024426.GA7468@kroah.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=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 There's a substantial window of opportunity from the time the policy objects are created until they are initialized, causing this: WARNING: CPU: 1 PID: 64 at include/linux/kref.h:47 kobject_get+0x64/0x70() Modules linked in: CPU: 1 PID: 64 Comm: irq/77-tegra-ac Not tainted 3.18.0-rc1-next-20141027ccu-00049-g21a0041 #248 [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0x98/0xd8) [] (dump_stack) from [] (warn_slowpath_common+0x70/0x8c) [] (warn_slowpath_common) from [] (warn_slowpath_null+0x1c/0x24) [] (warn_slowpath_null) from [] (kobject_get+0x64/0x70) [] (kobject_get) from [] (cpufreq_cpu_get+0x88/0xc8) [] (cpufreq_cpu_get) from [] (cpufreq_get+0xc/0x64) [] (cpufreq_get) from [] (actmon_thread_isr+0x140/0x1a4) [] (actmon_thread_isr) from [] (irq_thread_fn+0x1c/0x40) [] (irq_thread_fn) from [] (irq_thread+0x134/0x174) [] (irq_thread) from [] (kthread+0xdc/0xf4) [] (kthread) from [] (ret_from_fork+0x14/0x3c) This commit checks that initialization has finished before trying to do anything with the policy. Signed-off-by: Tomeu Vizoso --- drivers/cpufreq/cpufreq.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 644b54e..7b84d1a 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -48,6 +48,9 @@ static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); /* Flag to suspend/resume CPUFreq governors */ static bool cpufreq_suspended; +/* Flag that tells whether initialization is completed */ +static atomic_t cpufreq_initialized = ATOMIC_INIT(0); + static inline bool has_target(void) { return cpufreq_driver->target_index || cpufreq_driver->target; @@ -211,7 +214,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) /* get the cpufreq driver */ read_lock_irqsave(&cpufreq_driver_lock, flags); - if (cpufreq_driver) { + if (atomic_read(&cpufreq_initialized)) { /* get the CPU */ policy = per_cpu(cpufreq_cpu_data, cpu); if (policy) @@ -1289,6 +1292,8 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) kobject_uevent(&policy->kobj, KOBJ_ADD); up_read(&cpufreq_rwsem); + atomic_set(&cpufreq_initialized, 1); + pr_debug("initialization complete\n"); return 0;