From patchwork Tue Dec 1 06:52:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 57477 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1985603lbb; Mon, 30 Nov 2015 22:53:05 -0800 (PST) X-Received: by 10.98.15.91 with SMTP id x88mr77815184pfi.144.1448952785424; Mon, 30 Nov 2015 22:53:05 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xq4si9337603pab.229.2015.11.30.22.53.05; Mon, 30 Nov 2015 22:53:05 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755002AbbLAGxE (ORCPT + 11 others); Tue, 1 Dec 2015 01:53:04 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:33553 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750795AbbLAGxD (ORCPT ); Tue, 1 Dec 2015 01:53:03 -0500 Received: by pabfh17 with SMTP id fh17so218287724pab.0 for ; Mon, 30 Nov 2015 22:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=MHheP+4BZFAuraKR8YWe25XDEB2UkmZDYzSFVjcNpQo=; b=S5e+imrR9hI0fbGN3lmbh1hmhoJqxehfqvbGV8V/+GrFvm//0dN7afQYfO+YZybDUq s04ry3WVJdERZmZ5A4O9AArYRglQzEZbYgyxuA8VMfUVgycgRehWaFQDXy5ASlWAGHj8 mGPYCkPYe79LFrZjSnBmD9v4RoWIhZQt9L1wMxdgIrepHtGkp0Jzx1kSwHc6Zk8+eQbs pJ99AQmEeCqBIo+2rRHA96KQOB4nH9z+i9MDZp9+W/xnKYnw9wWrs9KUgnE4V0LF+mJ7 Fi3k4Z2g5VQZNSk+IVxGf03eIH63E76eJK66uemEu75IkRwfGrf0kzuZJhzmNUVeErJU H5+Q== 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=MHheP+4BZFAuraKR8YWe25XDEB2UkmZDYzSFVjcNpQo=; b=IdF9X5iezJW5dvS6XDtDRCcAiVIOhGbWJmuv0picwUtOS7ns35H/3v5zuilqh9Vl7J 1mJmn/igJu7CmEeExXo2HAOfBSfNugBRZjRJZfN8BroehCJa0G7GiZR7w790MxjygNra CKx50zgEFZdM2pUmpqcHldwDZqqYjUjm9RYy37o+dor2MSnfOeelMWYs7iCSjedB1+oc 5tEIzPy2bW2y1Il29q1hbna6x0YMP8lmeE/6C6xygSMhAbJt3CACrQV2mypyfwQiFAzl JG9jyfZj49SVgbNZxSMR3DrRBcRwGTKntX2NnCWFW1YClXA40co0luYbbhv0YN5iWW8T 3YoQ== X-Gm-Message-State: ALoCoQk5kR1H1Bo6i94JqtQZNsRWnfuWuCS8EwP5Zu/+oMmnkWRVmUqDqgzwGArwL/s+uWyCXO9V X-Received: by 10.98.15.215 with SMTP id 84mr77419077pfp.49.1448952781741; Mon, 30 Nov 2015 22:53:01 -0800 (PST) Received: from localhost ([223.227.235.8]) by smtp.gmail.com with ESMTPSA id f67sm51238054pfd.9.2015.11.30.22.52.57 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 30 Nov 2015 22:53:00 -0800 (PST) Date: Tue, 1 Dec 2015 12:22:52 +0530 From: Viresh Kumar To: Stephen Boyd Cc: Rafael Wysocki , nm@ti.com, linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Bartlomiej Zolnierkiewicz , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , open list , Pavel Machek , Shawn Guo Subject: Re: [PATCH V2 2/3] PM / OPP: Parse 'opp-supported-hw' binding Message-ID: <20151201065252.GD4459@ubuntu> References: <4341a83dc6591364cd9deb3dfa8343961b8605d6.1447904566.git.viresh.kumar@linaro.org> <20151125205147.GE11298@codeaurora.org> <20151127044517.GU3869@ubuntu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151127044517.GU3869@ubuntu> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On 27-11-15, 10:15, Viresh Kumar wrote: > > > + dev_opp->supported_hw = kmemdup(versions, count * sizeof(*versions), > > > + GFP_KERNEL); > > > > And then we're going to modify said opp here under the mutex > > lock. > > opp-dev .. > > > > + if (!dev_opp->supported_hw) { > > > + ret = -ENOMEM; > > > + goto err; > > > + } > > > + > > > + dev_opp->supported_hw_count = count; > > > > So we've properly handled the concurrent writer case (which is > > probably not even real), but we have improperly handled the case > > where a reader is running in parallel to the writer. We should > > only list_add_rcu the pointer once we're done modifying the > > pointer we created. Otherwise a reader can come along and see the > > half initialized structure, which is not good. > > This function will be called, from some platform code, before the OPP > table is initialized. It isn't useful to call it after the OPPs are > added for the device. So there wouldn't be any concurrent reader. Since these functions are *only* going to be called before any OPPs are added for the device, and hence ruling out any concurrent readers, maybe we can guarantee that with this: I don't really want to create a duplicate dev_opp here and then replace that in the list, because we know that we have just created it. Over that, if a reference to dev_opp is used somewhere else, lets say within the pm_opp structure, then updating all OPPs at such times would be really hard. Lets close this before you go for vacations. I will get whatever solution you feel is right. -- viresh -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 5449bae74a44..ec74d98afe75 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -876,6 +876,9 @@ int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, goto err; } + /* Make sure there are no concurrent readers while updating dev_opp */ + WARN_ON(!list_empty(&dev_opp->opp_list)); + dev_opp->supported_hw = kmemdup(versions, count * sizeof(*versions), GFP_KERNEL); if (!dev_opp->supported_hw) { @@ -924,6 +927,9 @@ void dev_pm_opp_put_supported_hw(struct device *dev) goto unlock; } + /* Make sure there are no concurrent readers while updating dev_opp */ + WARN_ON(!list_empty(&dev_opp->opp_list)); + if (!dev_opp->supported_hw) { dev_err(dev, "%s: Doesn't have supported hardware list\n", __func__);