mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
To: Mario Limonciello <superm1@kernel.org>,
	"Gautham R . Shenoy" <gautham.shenoy@amd.com>,
	Perry Yuan <perry.yuan@amd.com>
Cc: "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<linux-kernel@vger.kernel.org>,
	"open list:CPU FREQUENCY SCALING FRAMEWORK"
	<linux-pm@vger.kernel.org>,
	Mario Limonciello <mario.limonciello@amd.com>,
	Klara Modin <klarasmodin@gmail.com>
Subject: Re: [PATCH] cpufreq: amd-pstate: Register driver after static call update
Date: Mon, 28 Oct 2024 09:57:15 +0530	[thread overview]
Message-ID: <145ac73d-000e-46c2-818b-d0d5deefd37a@amd.com> (raw)
In-Reply-To: <20241027122612.749674-1-superm1@kernel.org>

Hello Mario,

On 10/27/2024 5:56 PM, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> The driver must be registered specifically after the static call
> update.
> 
> Fixes: e238968a2087 ("cpufreq/amd-pstate: Remove the redundant amd_pstate_set_driver() call")
> Reported-and-tested-by: Klara Modin <klarasmodin@gmail.com>
> Closes: https://lore.kernel.org/linux-pm/cf9c146d-bacf-444e-92e2-15ebf513af96@gmail.com/#t
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>  drivers/cpufreq/amd-pstate.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 206725219d8c9..2f0e29b05963d 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1857,12 +1857,6 @@ static int __init amd_pstate_init(void)
>  		return -ENODEV;
>  	}
>  
> -	ret = amd_pstate_register_driver(cppc_state);
> -	if (ret) {
> -		pr_err("failed to register with return %d\n", ret);
> -		return ret;
> -	}
> -
>  	/* capability check */
>  	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
>  		pr_debug("AMD CPPC MSR based functionality is supported\n");
1865                 if (cppc_state != AMD_PSTATE_ACTIVE)
1866                         current_pstate_driver->adjust_perf = amd_pstate_adjust_perf;

If we move the "amd_pstate_register_driver()" call to the below point, wont the above dereference (current_pstate_driver->) 
cause a null pointer error in MSR based systems with amd_pstate=passive/guided boot param. As we initialize 
"current_pstate_driver" in amd_pstate_register_driver().

We probably need to break up the if-else condition and handle the MSR based "if" part after the register call and "else" 
part before the "amd_pstate_register_driver()" call.

Something like,
		
	if (!cpu_feature_enabled(X86_FEATURE_CPPC)) {
                 pr_debug("AMD CPPC shared memory based functionality is supported\n");
                 static_call_update(amd_pstate_enable, shmem_enable);
                 static_call_update(amd_pstate_init_perf, shmem_init_perf);
                 static_call_update(amd_pstate_update_perf, shmem_update_perf);  	<---- static call updates done
    	}
	
	ret = amd_pstate_register_driver(cppc_state);					<---- Initializes "current_pstate_driver"
	if (ret) {
		pr_err("failed to register with return %d\n", ret);
		return ret;
	}
	
	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
		pr_debug("AMD CPPC MSR based functionality is supported\n");
                if (cppc_state != AMD_PSTATE_ACTIVE)
                         current_pstate_driver->adjust_perf = amd_pstate_adjust_perf;	<---- Now we dereference "current_pstate_driver"
	}
	

What do you think?

Thanks,
Dhananjay

> @@ -1881,6 +1875,12 @@ static int __init amd_pstate_init(void)
>  			return ret;
>  	}
>  
> +	ret = amd_pstate_register_driver(cppc_state);
> +	if (ret) {
> +		pr_err("failed to register with return %d\n", ret);
> +		return ret;
> +	}
> +
>  	dev_root = bus_get_dev_root(&cpu_subsys);
>  	if (dev_root) {
>  		ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group);

  reply	other threads:[~2024-10-28  4:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-27 12:26 Mario Limonciello
2024-10-28  4:27 ` Dhananjay Ugwekar [this message]
2024-10-28 13:34   ` Mario Limonciello

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=145ac73d-000e-46c2-818b-d0d5deefd37a@amd.com \
    --to=dhananjay.ugwekar@amd.com \
    --cc=gautham.shenoy@amd.com \
    --cc=klarasmodin@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=perry.yuan@amd.com \
    --cc=superm1@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

all inboxes | Powered by JetHome®