From patchwork Wed Dec 7 10:37:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 87021 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp246897qgi; Wed, 7 Dec 2016 02:48:18 -0800 (PST) X-Received: by 10.84.157.74 with SMTP id u10mr146397809plu.153.1481107698523; Wed, 07 Dec 2016 02:48:18 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si23560107pli.211.2016.12.07.02.48.18; Wed, 07 Dec 2016 02:48:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753140AbcLGKsP (ORCPT + 25 others); Wed, 7 Dec 2016 05:48:15 -0500 Received: from mail-pg0-f42.google.com ([74.125.83.42]:34245 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751792AbcLGKsO (ORCPT ); Wed, 7 Dec 2016 05:48:14 -0500 Received: by mail-pg0-f42.google.com with SMTP id x23so160881827pgx.1 for ; Wed, 07 Dec 2016 02:48:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=UdWdMvpJk9VqOkTzrdeqK7k84z6tkHzopkfLzrh52SU=; b=XQwAzx/zI3Fs3bHcsYpQCo872B+MS2zBf2q5cyzDWUvQfec4Mhk9RFxFfW6mMdIzba StynKV7sAQFPXs+0siOFakWI0gmNly671XphGgGrAglgnrOYfOOEfEDk5Z4BGJkZEM4q 9WNOMgSAPKkxxZ8fh0EGTkgINQEH0eMkiQhE4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=UdWdMvpJk9VqOkTzrdeqK7k84z6tkHzopkfLzrh52SU=; b=coD5Yx1/mVZG2/pV1mdNa5SvuqVFd/+cE8MsO8qodQn2arTlG5I/cDH7oZKDMEtAjA QFXp348qxjxOqjI+jDiWMGisPzYCkVkzr/ezkCrtG+U8BBROamZ6gRqjH2Yinjs6DSjv SKKZmhN0rF0gXO7a4OR3CtMNMEL2tW6KSBfrZqtSpxr53dlYDtEtDBcnRHOnA6KFA9f6 XOeSIvTTq40EIaO9NbwcYC0u17cBGhBaGj3ugPAHUmr7yNGj6iuDMq+SH2zhmQKTHFvE 7bbT7rt1SxAgy8sDyZhUO1woyNzvQLl3zA/zmAnL6RCNsJZbsNB3sXjoIRgbPE61dIJ9 n8HA== X-Gm-Message-State: AKaTC02jrHav5hrNSwTZ0Xgj6CzPJ7H6kxwEoH3hkmTxfKSLiyxS4RBJR8rfni2BbcdRetNw X-Received: by 10.99.145.74 with SMTP id l71mr119534353pge.128.1481107272797; Wed, 07 Dec 2016 02:41:12 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id r2sm41476530pfi.67.2016.12.07.02.41.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 02:41:12 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar Subject: [PATCH 01/12] PM / OPP: Add per OPP table mutex Date: Wed, 7 Dec 2016 16:07:39 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add per OPP table lock to protect opp_table->opp_list. Note that at few places opp_list is used under the rcu_read_lock() and so a mutex can't be added there for now. This will be fixed by a later patch. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 31 +++++++++++++++++++++++++++---- drivers/base/power/opp/opp.h | 2 ++ 2 files changed, 29 insertions(+), 4 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 6af371a55062..212b7dbecae2 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -854,6 +854,7 @@ static struct opp_table *_allocate_opp_table(struct device *dev) srcu_init_notifier_head(&opp_table->srcu_head); INIT_LIST_HEAD(&opp_table->opp_list); + mutex_init(&opp_table->lock); /* Secure the device table modification */ list_add_rcu(&opp_table->node, &opp_tables); @@ -909,6 +910,7 @@ static void _free_opp_table(struct opp_table *opp_table) /* dev_list must be empty now */ WARN_ON(!list_empty(&opp_table->dev_list)); + mutex_destroy(&opp_table->lock); list_del_rcu(&opp_table->node); call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head, _kfree_device_rcu); @@ -969,6 +971,8 @@ static void _kfree_opp_rcu(struct rcu_head *head) */ static void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp) { + mutex_lock(&opp_table->lock); + /* * Notify the changes in the availability of the operable * frequency/voltage list. @@ -978,6 +982,8 @@ static void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp) list_del_rcu(&opp->node); call_srcu(&opp_table->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu); + mutex_unlock(&opp_table->lock); + _remove_opp_table(opp_table); } @@ -1007,6 +1013,8 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) if (IS_ERR(opp_table)) goto unlock; + mutex_lock(&opp_table->lock); + list_for_each_entry(opp, &opp_table->opp_list, node) { if (opp->rate == freq) { found = true; @@ -1014,6 +1022,8 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) } } + mutex_unlock(&opp_table->lock); + if (!found) { dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n", __func__, freq); @@ -1084,7 +1094,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table) { struct dev_pm_opp *opp; - struct list_head *head = &opp_table->opp_list; + struct list_head *head; int ret; /* @@ -1095,6 +1105,9 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, * loop, don't replace it with head otherwise it will become an infinite * loop. */ + mutex_lock(&opp_table->lock); + head = &opp_table->opp_list; + list_for_each_entry_rcu(opp, &opp_table->opp_list, node) { if (new_opp->rate > opp->rate) { head = &opp->node; @@ -1111,12 +1124,17 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, new_opp->supplies[0].u_volt, new_opp->available); /* Should we compare voltages for all regulators here ? */ - return opp->available && - new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST; + ret = opp->available && + new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST; + + mutex_unlock(&opp_table->lock); + return ret; } - new_opp->opp_table = opp_table; list_add_rcu(&new_opp->node, head); + mutex_unlock(&opp_table->lock); + + new_opp->opp_table = opp_table; ret = opp_debug_create_one(new_opp, opp_table); if (ret) @@ -1780,6 +1798,8 @@ static int _opp_set_availability(struct device *dev, unsigned long freq, goto unlock; } + mutex_lock(&opp_table->lock); + /* Do we have the frequency? */ list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { if (tmp_opp->rate == freq) { @@ -1787,6 +1807,9 @@ static int _opp_set_availability(struct device *dev, unsigned long freq, break; } } + + mutex_unlock(&opp_table->lock); + if (IS_ERR(opp)) { r = PTR_ERR(opp); goto unlock; diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index e32dc80ddc12..81eb6cee7295 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -131,6 +131,7 @@ enum opp_table_access { * @rcu_head: RCU callback head used for deferred freeing * @dev_list: list of devices that share these OPPs * @opp_list: table of opps + * @lock: mutex protecting the opp_list. * @np: struct device_node pointer for opp's DT node. * @clock_latency_ns_max: Max clock latency in nanoseconds. * @shared_opp: OPP is shared between multiple devices. @@ -163,6 +164,7 @@ struct opp_table { struct rcu_head rcu_head; struct list_head dev_list; struct list_head opp_list; + struct mutex lock; struct device_node *np; unsigned long clock_latency_ns_max;