From patchwork Wed Aug 12 08:12:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 6997611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E3CF99F358 for ; Wed, 12 Aug 2015 08:15:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0952620703 for ; Wed, 12 Aug 2015 08:15:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0CA9E206FD for ; Wed, 12 Aug 2015 08:15:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZPRA7-0000e8-2w; Wed, 12 Aug 2015 08:13:27 +0000 Received: from mail-pa0-f54.google.com ([209.85.220.54]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZPRA3-0000UL-H6 for linux-arm-kernel@lists.infradead.org; Wed, 12 Aug 2015 08:13:24 +0000 Received: by pawu10 with SMTP id u10so9605744paw.1 for ; Wed, 12 Aug 2015 01:13:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=U0VxBJb7sK5+GDbCH4fNgweQ9mSAaIUl2bHdDqtbP3Y=; b=VTX8zRxY7qLQCtxnFGZ/kwIRAZC+X5QvJeCLYYYku26R1g50pwzIuvNQMqIEp6w9TY 0CNLlQmnYr1/HS0YK8AGyuYBLBosqEPWDA2YNwXZNvZjnY9g5zlDXz/gX/juLsqG4Yvo KmzBlZm77xEN10S83orXQI+It/l0MUUZ2ggYBM6PBpXMumd7h+biCqh+xJ8WmGysfkkP M2HuT+GJcxAwDeMQdAjfavCnhcy/dhp261pkLkxJhn5mFhfQe8+neW9qvk2dRcuTo5Eu zCvsLY5SQynF1e2HbaRPl+xU4MBAjAoz+JPyISxwOdD5PDG0QqCptBoN7DFx8QeMk7yT vsxw== X-Gm-Message-State: ALoCoQn12qz8p8+KOhWBPE4gLVWtcvhcya3Il2v1mLCQ8Xuk2JsmeO8aL1jnN7ej5UPtgS8nSVsu X-Received: by 10.68.218.104 with SMTP id pf8mr65147330pbc.31.1439367181491; Wed, 12 Aug 2015 01:13:01 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id m4sm5384439pda.90.2015.08.12.01.13.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 12 Aug 2015 01:13:00 -0700 (PDT) Date: Wed, 12 Aug 2015 13:42:57 +0530 From: Viresh Kumar To: Russell King - ARM Linux Subject: Re: 3.18: lockdep problems in cpufreq Message-ID: <20150812081257.GC16445@linux> References: <20141214213655.GA11285@n2100.arm.linux.org.uk> <20150518185645.GA28053@n2100.arm.linux.org.uk> <2574268.XBqpdL2VLI@vostro.rjw.lan> <20150811170357.GA24529@n2100.arm.linux.org.uk> <20150812051659.GI32049@linux> <20150812072129.GD7557@n2100.arm.linux.org.uk> <20150812073530.GA16445@linux> <20150812074925.GG7557@n2100.arm.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150812074925.GG7557@n2100.arm.linux.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150812_011323_619026_2BA57A43 X-CRM114-Status: GOOD ( 19.95 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Valentin , Yadwinder Singh Brar , "Rafael J. Wysocki" , "linux-arm-kernel@lists.infradead.org" , "linux-pm@vger.kernel.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 On 12-08-15, 08:49, Russell King - ARM Linux wrote: > The problem will be back-porting it to stable kernels, because I think > it's had to be updated at least a couple of times. I don't have the old > versions anymore, so I'm just going to say "not my problem" - sorry. Your old 3.18 version :) 8<=== From: Russell King thermal: cpu_cooling: fix lockdep problems in cpu_cooling A recent change to the cpu_cooling code introduced a AB-BA deadlock scenario between the cpufreq_policy_notifier_list rwsem and the cooling_cpufreq_lock. This is caused by cooling_cpufreq_lock being held before the registration/removal of the notifier block (an operation which takes the rwsem), and the notifier code itself which takes the locks in the reverse order. Solve this by moving to finer grained locking - use one mutex to protect the cpufreq_dev_list as a whole, and a separate lock to ensure correct ordering of cpufreq notifier registration and removal. I considered taking the cooling_list_lock within cooling_cpufreq_lock to protect the registration sequence as a whole, but that adds a dependency between these two locks which is best avoided (lest someone tries to take those two new locks in the reverse order.) In any case, it's safer to have an empty cpufreq_dev_list than to have unnecessary dependencies between locks. Fixes: 2dcd851fe4b4 ("thermal: cpu_cooling: Update always cpufreq policy with thermal constraints") Reviewed-by: Viresh Kumar Signed-off-by: Russell King --- drivers/thermal/cpu_cooling.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index ad09e51ffae4..9e42c6f30785 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -57,6 +57,7 @@ static DEFINE_MUTEX(cooling_cpufreq_lock); static unsigned int cpufreq_dev_count; +static DEFINE_MUTEX(cooling_list_lock); static LIST_HEAD(cpufreq_dev_list); /** @@ -317,7 +318,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, if (event != CPUFREQ_ADJUST) return 0; - mutex_lock(&cooling_cpufreq_lock); + mutex_lock(&cooling_list_lock); list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { if (!cpumask_test_cpu(policy->cpu, &cpufreq_dev->allowed_cpus)) @@ -333,7 +334,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, if (policy->max != max_freq) cpufreq_verify_within_limits(policy, 0, max_freq); } - mutex_unlock(&cooling_cpufreq_lock); + mutex_unlock(&cooling_list_lock); return 0; } @@ -482,6 +483,11 @@ __cpufreq_cooling_register(struct device_node *np, } cpufreq_dev->cool_dev = cool_dev; cpufreq_dev->cpufreq_state = 0; + + mutex_lock(&cooling_list_lock); + list_add(&cpufreq_dev->node, &cpufreq_dev_list); + mutex_unlock(&cooling_list_lock); + mutex_lock(&cooling_cpufreq_lock); /* Register the notifier for first cpufreq cooling device */ @@ -489,7 +495,6 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_register_notifier(&thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); cpufreq_dev_count++; - list_add(&cpufreq_dev->node, &cpufreq_dev_list); mutex_unlock(&cooling_cpufreq_lock); @@ -553,7 +558,6 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) cpufreq_dev = cdev->devdata; mutex_lock(&cooling_cpufreq_lock); - list_del(&cpufreq_dev->node); cpufreq_dev_count--; /* Unregister the notifier for the last cpufreq cooling device */ @@ -562,6 +566,10 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) CPUFREQ_POLICY_NOTIFIER); mutex_unlock(&cooling_cpufreq_lock); + mutex_lock(&cooling_list_lock); + list_del(&cpufreq_dev->node); + mutex_unlock(&cooling_list_lock); + thermal_cooling_device_unregister(cpufreq_dev->cool_dev); release_idr(&cpufreq_idr, cpufreq_dev->id); kfree(cpufreq_dev);