public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Liao, Chang" <liaochang1@huawei.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: <rafael@kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] cpufreq: cppc: Set fie_disabled to FIE_DISABLED if fails to create kworker_fie
Date: Thu, 17 Aug 2023 10:33:13 +0800	[thread overview]
Message-ID: <e727d702-314a-e3ec-4ee6-8d4e2df73c92@huawei.com> (raw)
In-Reply-To: <20230816103731.qwx3j3rmwyszq45j@vireshk-i7>



在 2023/8/16 18:37, Viresh Kumar 写道:
> On 16-08-23, 09:49, Liao Chang wrote:
>> The function cppc_freq_invariance_init() may failed to create
>> kworker_fie, make it more robust by setting fie_disabled to FIE_DISBALED
>> to prevent an invalid pointer dereference in kthread_destroy_worker(),
>> which called from cppc_freq_invariance_exit().
>>
>> Link: https://lore.kernel.org/all/20230816034630.a4hvsj373q6aslk3@vireshk-i7/
>>
>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>> ---
>>  drivers/cpufreq/cppc_cpufreq.c | 28 ++++++++++++++++------------
>>  1 file changed, 16 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
>> index 022e3555407c..bff4cde06083 100644
>> --- a/drivers/cpufreq/cppc_cpufreq.c
>> +++ b/drivers/cpufreq/cppc_cpufreq.c
>> @@ -220,6 +220,15 @@ static void cppc_cpufreq_cpu_fie_exit(struct cpufreq_policy *policy)
>>  	}
>>  }
>>  
>> +static void cppc_freq_invariance_exit(void)
>> +{
>> +	if (fie_disabled)
>> +		return;
>> +
>> +	kthread_destroy_worker(kworker_fie);
>> +	kworker_fie = NULL;
>> +}
>> +
>>  static void __init cppc_freq_invariance_init(void)
>>  {
>>  	struct sched_attr attr = {
>> @@ -249,27 +258,22 @@ static void __init cppc_freq_invariance_init(void)
>>  		return;
>>  
>>  	kworker_fie = kthread_create_worker(0, "cppc_fie");
>> -	if (IS_ERR(kworker_fie))
>> +	if (IS_ERR(kworker_fie)) {
>> +		pr_warn("%s: failed to create kworker_fie: %ld\n", __func__,
>> +			PTR_ERR(kworker_fie));
>> +		fie_disabled = FIE_DISABLED;
>>  		return;
>> +	}
>>  
>>  	ret = sched_setattr_nocheck(kworker_fie->task, &attr);
>>  	if (ret) {
>>  		pr_warn("%s: failed to set SCHED_DEADLINE: %d\n", __func__,
>>  			ret);
>> -		kthread_destroy_worker(kworker_fie);
>> -		return;
>> +		cppc_freq_invariance_exit();
> 
> I don't really like this change, there aren't a lot of things that we
> need to do here on cleanup, but just kthread_destroy_worker(). Calling
> it directly makes more sense I guess.

OK,I will simplify code in next revisoin.

> 
>> +		fie_disabled = FIE_DISABLED;
>>  	}
>>  }
>>  
>> -static void cppc_freq_invariance_exit(void)
>> -{
>> -	if (fie_disabled)
>> -		return;
>> -
>> -	kthread_destroy_worker(kworker_fie);
> 
>> -	kworker_fie = NULL;
> 
> I don't see the point of this line. Probably it can be dropped.

I agree with you, when fie_disbaled is set to FIE_DISABLED and kthred_destroy_worker() is called,
the driver has no chance to access the invalid kworker_fie pointer.

Thanks.

> 
>> -}
>> -
>>  #else
>>  static inline void cppc_cpufreq_cpu_fie_init(struct cpufreq_policy *policy)
>>  {
>> -- 
>> 2.34.1
> 

-- 
BR
Liao, Chang

      reply	other threads:[~2023-08-17  2:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16  9:49 [PATCH v2] cpufreq: cppc: Set fie_disabled to FIE_DISABLED if fails to create kworker_fie Liao Chang
2023-08-16 10:37 ` Viresh Kumar
2023-08-17  2:33   ` Liao, Chang [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=e727d702-314a-e3ec-4ee6-8d4e2df73c92@huawei.com \
    --to=liaochang1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.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