* [PATCH] cpufreq: amd-pstate: Register driver after static call update
@ 2024-10-27 12:26 Mario Limonciello
2024-10-28 4:27 ` Dhananjay Ugwekar
0 siblings, 1 reply; 3+ messages in thread
From: Mario Limonciello @ 2024-10-27 12:26 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>
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");
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cpufreq: amd-pstate: Register driver after static call update
2024-10-27 12:26 [PATCH] cpufreq: amd-pstate: Register driver after static call update Mario Limonciello
@ 2024-10-28 4:27 ` Dhananjay Ugwekar
2024-10-28 13:34 ` Mario Limonciello
0 siblings, 1 reply; 3+ messages in thread
From: Dhananjay Ugwekar @ 2024-10-28 4:27 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
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);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cpufreq: amd-pstate: Register driver after static call update
2024-10-28 4:27 ` Dhananjay Ugwekar
@ 2024-10-28 13:34 ` Mario Limonciello
0 siblings, 0 replies; 3+ messages in thread
From: Mario Limonciello @ 2024-10-28 13:34 UTC (permalink / raw)
To: Dhananjay Ugwekar, 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/27/2024 23:27, Dhananjay Ugwekar wrote:
> 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?
Makes sense, I'll send out a v2 like this, thanks for the suggestion.
>
> 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);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-28 13:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-27 12:26 [PATCH] cpufreq: amd-pstate: Register driver after static call update Mario Limonciello
2024-10-28 4:27 ` Dhananjay Ugwekar
2024-10-28 13:34 ` Mario Limonciello
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox