public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init
@ 2024-10-28 14:55 Mario Limonciello
  2024-10-28 14:55 ` [PATCH v2 2/2] cpufreq/amd-pstate: Move registration after static function call update Mario Limonciello
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mario Limonciello @ 2024-10-28 14:55 UTC (permalink / raw)
  To: Gautham R . Shenoy, Perry Yuan
  Cc: Dhananjay Ugwekar, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello,
	Klara Modin

From: Mario Limonciello <mario.limonciello@amd.com>

As the driver can be changed in and out of different modes it's possible
that adjust_perf is assigned when it shouldn't be.

This could happen if an MSR design is started up in passive mode and then
switches to active mode.

To solve this explicitly clear `adjust_perf` in amd_pstate_epp_cpu_init().

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
Cc: Klara Modin <klarasmodin@gmail.com>
 drivers/cpufreq/amd-pstate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 206725219d8c9..e480da818d6f5 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1504,6 +1504,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
 		WRITE_ONCE(cpudata->cppc_cap1_cached, value);
 	}
 
+	current_pstate_driver->adjust_perf = NULL;
+
 	return 0;
 
 free_cpudata1:
@@ -1866,8 +1868,6 @@ static int __init amd_pstate_init(void)
 	/* capability check */
 	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;
 	} else {
 		pr_debug("AMD CPPC shared memory based functionality is supported\n");
 		static_call_update(amd_pstate_cppc_enable, shmem_cppc_enable);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] cpufreq/amd-pstate: Move registration after static function call update
  2024-10-28 14:55 [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init Mario Limonciello
@ 2024-10-28 14:55 ` Mario Limonciello
  2024-10-29  4:57   ` Dhananjay Ugwekar
  2024-10-28 21:48 ` [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init Klara Modin
  2024-10-29  4:52 ` Dhananjay Ugwekar
  2 siblings, 1 reply; 5+ messages in thread
From: Mario Limonciello @ 2024-10-28 14:55 UTC (permalink / raw)
  To: Gautham R . Shenoy, Perry Yuan
  Cc: Dhananjay Ugwekar, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello,
	Klara Modin

From: Mario Limonciello <mario.limonciello@amd.com>

On shared memory designs the static functions need to work before
registration is done or the system can hang at bootup.

Move the registration later in amd_pstate_init() to solve this.

Fixes: e238968a2087 ("cpufreq/amd-pstate: Remove the redundant amd_pstate_set_driver() call")
Reported-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 e480da818d6f5..f834cc8205e2a 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1859,12 +1859,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");
@@ -1875,6 +1869,12 @@ static int __init amd_pstate_init(void)
 		static_call_update(amd_pstate_update_perf, shmem_update_perf);
 	}
 
+	ret = amd_pstate_register_driver(cppc_state);
+	if (ret) {
+		pr_err("failed to register with return %d\n", ret);
+		return ret;
+	}
+
 	if (amd_pstate_prefcore) {
 		ret = amd_detect_prefcore(&amd_pstate_prefcore);
 		if (ret)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init
  2024-10-28 14:55 [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init Mario Limonciello
  2024-10-28 14:55 ` [PATCH v2 2/2] cpufreq/amd-pstate: Move registration after static function call update Mario Limonciello
@ 2024-10-28 21:48 ` Klara Modin
  2024-10-29  4:52 ` Dhananjay Ugwekar
  2 siblings, 0 replies; 5+ messages in thread
From: Klara Modin @ 2024-10-28 21:48 UTC (permalink / raw)
  To: Mario Limonciello, Gautham R . Shenoy, Perry Yuan
  Cc: Dhananjay Ugwekar, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello

On 2024-10-28 15:55, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> As the driver can be changed in and out of different modes it's possible
> that adjust_perf is assigned when it shouldn't be.
> 
> This could happen if an MSR design is started up in passive mode and then
> switches to active mode.
> 
> To solve this explicitly clear `adjust_perf` in amd_pstate_epp_cpu_init().
> 
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> Cc: Klara Modin <klarasmodin@gmail.com>
>   drivers/cpufreq/amd-pstate.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 206725219d8c9..e480da818d6f5 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1504,6 +1504,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
>   		WRITE_ONCE(cpudata->cppc_cap1_cached, value);
>   	}
>   
> +	current_pstate_driver->adjust_perf = NULL;
> +
>   	return 0;
>   
>   free_cpudata1:
> @@ -1866,8 +1868,6 @@ static int __init amd_pstate_init(void)
>   	/* capability check */
>   	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;
>   	} else {
>   		pr_debug("AMD CPPC shared memory based functionality is supported\n");
>   		static_call_update(amd_pstate_cppc_enable, shmem_cppc_enable);

Both of these patches together also fix the problem I had.

Thanks,
Tested-by: Klara Modin <klarasmodin@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init
  2024-10-28 14:55 [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init Mario Limonciello
  2024-10-28 14:55 ` [PATCH v2 2/2] cpufreq/amd-pstate: Move registration after static function call update Mario Limonciello
  2024-10-28 21:48 ` [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init Klara Modin
@ 2024-10-29  4:52 ` Dhananjay Ugwekar
  2 siblings, 0 replies; 5+ messages in thread
From: Dhananjay Ugwekar @ 2024-10-29  4:52 UTC (permalink / raw)
  To: Mario Limonciello, Gautham R . Shenoy, Perry Yuan
  Cc: open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello,
	Klara Modin

On 10/28/2024 8:25 PM, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> As the driver can be changed in and out of different modes it's possible
> that adjust_perf is assigned when it shouldn't be.
> 
> This could happen if an MSR design is started up in passive mode and then
> switches to active mode.
> 
> To solve this explicitly clear `adjust_perf` in amd_pstate_epp_cpu_init().
>

Great, this solves the overlooked issue as well, looks good to me.

You may also add,
Tested-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>

Thanks,
Dhananjay
 
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> Cc: Klara Modin <klarasmodin@gmail.com>
>  drivers/cpufreq/amd-pstate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 206725219d8c9..e480da818d6f5 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1504,6 +1504,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
>  		WRITE_ONCE(cpudata->cppc_cap1_cached, value);
>  	}
>  
> +	current_pstate_driver->adjust_perf = NULL;
> +
>  	return 0;
>  
>  free_cpudata1:
> @@ -1866,8 +1868,6 @@ static int __init amd_pstate_init(void)
>  	/* capability check */
>  	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;
>  	} else {
>  		pr_debug("AMD CPPC shared memory based functionality is supported\n");
>  		static_call_update(amd_pstate_cppc_enable, shmem_cppc_enable);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] cpufreq/amd-pstate: Move registration after static function call update
  2024-10-28 14:55 ` [PATCH v2 2/2] cpufreq/amd-pstate: Move registration after static function call update Mario Limonciello
@ 2024-10-29  4:57   ` Dhananjay Ugwekar
  0 siblings, 0 replies; 5+ messages in thread
From: Dhananjay Ugwekar @ 2024-10-29  4:57 UTC (permalink / raw)
  To: Mario Limonciello, Gautham R . Shenoy, Perry Yuan
  Cc: open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello,
	Klara Modin

On 10/28/2024 8:25 PM, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> On shared memory designs the static functions need to work before
> registration is done or the system can hang at bootup.
> 
> Move the registration later in amd_pstate_init() to solve this.

Looks good to me.
Also, 
Tested-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com>

Thanks,
Dhananjay

> 
> Fixes: e238968a2087 ("cpufreq/amd-pstate: Remove the redundant amd_pstate_set_driver() call")
> Reported-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 e480da818d6f5..f834cc8205e2a 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1859,12 +1859,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");
> @@ -1875,6 +1869,12 @@ static int __init amd_pstate_init(void)
>  		static_call_update(amd_pstate_update_perf, shmem_update_perf);
>  	}
>  
> +	ret = amd_pstate_register_driver(cppc_state);
> +	if (ret) {
> +		pr_err("failed to register with return %d\n", ret);
> +		return ret;
> +	}
> +
>  	if (amd_pstate_prefcore) {
>  		ret = amd_detect_prefcore(&amd_pstate_prefcore);
>  		if (ret)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-29  4:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28 14:55 [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init Mario Limonciello
2024-10-28 14:55 ` [PATCH v2 2/2] cpufreq/amd-pstate: Move registration after static function call update Mario Limonciello
2024-10-29  4:57   ` Dhananjay Ugwekar
2024-10-28 21:48 ` [PATCH v2 1/2] cpufreq/amd-pstate: Push adjust_perf vfunc init into cpu_init Klara Modin
2024-10-29  4:52 ` Dhananjay Ugwekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox