linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-pm@vger.kernel.org,
	Vincent Guittot <vincent.guittot@linaro.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] OPP: Protect `lazy_opp_tables` list with `opp_table_lock`
Date: Tue, 13 Jun 2023 15:01:02 +0200	[thread overview]
Message-ID: <ZIhojuakyEUct7YN@kernkonzept.com> (raw)
In-Reply-To: <c0bac65236cf77fa8ac17c2645449544b73a0104.1686210112.git.viresh.kumar@linaro.org>

On Thu, Jun 08, 2023 at 01:13:23PM +0530, Viresh Kumar wrote:
> The `opp_table_lock` lock is already used to protect the list elsewhere,
> use it while adding or removing entries from it.
> 
> Reported-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Stephan: Can you please give this a try ?

Thanks, works fine for me. (Note that I don't have any races or
corruption without this patch either so the testing result might
not mean too much.) The patch also looks good!

Tested-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>

> 
>  drivers/opp/of.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/opp/of.c b/drivers/opp/of.c
> index c740a907ef76..ac2179d5da4c 100644
> --- a/drivers/opp/of.c
> +++ b/drivers/opp/of.c
> @@ -21,7 +21,7 @@
>  
>  #include "opp.h"
>  
> -/* OPP tables with uninitialized required OPPs */
> +/* OPP tables with uninitialized required OPPs, protected by opp_table_lock */
>  static LIST_HEAD(lazy_opp_tables);
>  
>  /*
> @@ -148,7 +148,10 @@ static void _opp_table_free_required_tables(struct opp_table *opp_table)
>  
>  	opp_table->required_opp_count = 0;
>  	opp_table->required_opp_tables = NULL;
> +
> +	mutex_lock(&opp_table_lock);
>  	list_del(&opp_table->lazy);
> +	mutex_unlock(&opp_table_lock);
>  }
>  
>  /*
> @@ -197,8 +200,15 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
>  	}
>  
>  	/* Let's do the linking later on */
> -	if (lazy)
> +	if (lazy) {
> +		/*
> +		 * The OPP table is not held while allocating the table, take it
> +		 * now to avoid corruption to the lazy_opp_tables list.
> +		 */
> +		mutex_lock(&opp_table_lock);
>  		list_add(&opp_table->lazy, &lazy_opp_tables);
> +		mutex_unlock(&opp_table_lock);
> +	}
>  	else
>  		_update_set_required_opps(opp_table);
>  
> -- 
> 2.31.1.272.g89b43f80a514
> 

-- 
Stephan Gerhold
Kernkonzept GmbH at Dresden, Germany, HRB 31129, CEO Dr.-Ing. Michael Hohmuth

      reply	other threads:[~2023-06-13 13:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08  7:43 [PATCH 1/2] OPP: Staticize `lazy_opp_tables` in of.c Viresh Kumar
2023-06-08  7:43 ` [PATCH 2/2] OPP: Protect `lazy_opp_tables` list with `opp_table_lock` Viresh Kumar
2023-06-13 13:01   ` Stephan Gerhold [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZIhojuakyEUct7YN@kernkonzept.com \
    --to=stephan.gerhold@kernkonzept.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=rafael@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=vireshk@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).