[PATCH v4] cpufreq/amd-pstate: Prevent the driver from loading on unsupported hardware

Rong Zhang posted 1 patch 3 days, 5 hours ago
drivers/cpufreq/amd-pstate.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH v4] cpufreq/amd-pstate: Prevent the driver from loading on unsupported hardware
Posted by Rong Zhang 3 days, 5 hours ago
X86_FEATURE_HW_PSTATE indicates if the processor supports frequency
scaling or not. Without it, the driver is unusable and thus will not
load. This check also prevents the driver from loading in guests and
thus not confuse users with misleading prints.

Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Acked-by: Mario Limonciello (AMD) <superm1@kernel.org>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Rong Zhang <i@rong.moe>
---
Changes in v4:
- Clean up the commit message (thanks Borislav Petkov)
- Drop the Fixes: tag (ditto)
- Link to v3: https://patch.msgid.link/20260721-amd-pstate-vm-v3-1-8b59574fb714@rong.moe

Changes in v3:
- Move the check into amd_cppc_supported() and add a pr_debug_once()
  message (thanks K Prateek Nayak and Mario Limonciello)
  - The check is added before the existing family 17h model 0h-2Fh one,
    as print_cpu_info() already shows family, model, and stepping, and
    will help debugging even if the new check overrides the existing
    one, but not vice versa
- Link to v2: https://patch.msgid.link/20260718-amd-pstate-vm-v2-1-6ed5f3b2c89e@rong.moe

Changes in v2:
- Check for X86_FEATURE_HW_PSTATE instead of X86_FEATURE_HYPERVISOR
  (thanks K Prateek Nayak)
- Remove the check against Xen dom0, as it doesn't need the amd-pstate
  driver (thanks Jason Andryuk)
- Reword comments and the commit message
- Remove Gautham R. Shenoy from the To list due to email bounces
- Link to v1: https://patch.msgid.link/20260716-amd-pstate-vm-v1-1-2ac97d3cf6e7@rong.moe
---
 drivers/cpufreq/amd-pstate.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index a74a4cf99d22..b0b651380732 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -2167,6 +2167,7 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
 };
 
 /*
+ * Processors without frequency scaling support can't do CPPC.
  * CPPC function is not supported for family ID 17H with model_ID ranging from 0x10 to 0x2F.
  * show the debug message that helps to check if the CPU has CPPC support for loading issue.
  */
@@ -2175,6 +2176,11 @@ static bool amd_cppc_supported(void)
 	struct cpuinfo_x86 *c = &cpu_data(0);
 	bool warn = false;
 
+	if (!cpu_feature_enabled(X86_FEATURE_HW_PSTATE)) {
+		pr_debug_once("frequency scaling is not supported by the processor\n");
+		return false;
+	}
+
 	if ((boot_cpu_data.x86 == 0x17) && (boot_cpu_data.x86_model < 0x30)) {
 		pr_debug_once("CPPC feature is not supported by the processor\n");
 		return false;

---
base-commit: 248951ddc14de84de3910f9b13f51491a8cd91df
change-id: 1cc24037-amd-pstate-vm-d6ab4c959bd3

Thanks,
Rong
Re: [PATCH v4] cpufreq/amd-pstate: Prevent the driver from loading on unsupported hardware
Posted by Mario Limonciello 3 days, 5 hours ago

On 7/21/26 13:13, Rong Zhang wrote:
> X86_FEATURE_HW_PSTATE indicates if the processor supports frequency
> scaling or not. Without it, the driver is unusable and thus will not
> load. This check also prevents the driver from loading in guests and
> thus not confuse users with misleading prints.
> 
> Reviewed-by: Michael Kelley <mhklinux@outlook.com>
> Tested-by: Michael Kelley <mhklinux@outlook.com>
> Acked-by: Mario Limonciello (AMD) <superm1@kernel.org>
> Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
> Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
> Signed-off-by: Rong Zhang <i@rong.moe>
> ---
Thanks, will include it in a PR this week.

> Changes in v4:
> - Clean up the commit message (thanks Borislav Petkov)
> - Drop the Fixes: tag (ditto)
> - Link to v3: https://patch.msgid.link/20260721-amd-pstate-vm-v3-1-8b59574fb714@rong.moe
> 
> Changes in v3:
> - Move the check into amd_cppc_supported() and add a pr_debug_once()
>    message (thanks K Prateek Nayak and Mario Limonciello)
>    - The check is added before the existing family 17h model 0h-2Fh one,
>      as print_cpu_info() already shows family, model, and stepping, and
>      will help debugging even if the new check overrides the existing
>      one, but not vice versa
> - Link to v2: https://patch.msgid.link/20260718-amd-pstate-vm-v2-1-6ed5f3b2c89e@rong.moe
> 
> Changes in v2:
> - Check for X86_FEATURE_HW_PSTATE instead of X86_FEATURE_HYPERVISOR
>    (thanks K Prateek Nayak)
> - Remove the check against Xen dom0, as it doesn't need the amd-pstate
>    driver (thanks Jason Andryuk)
> - Reword comments and the commit message
> - Remove Gautham R. Shenoy from the To list due to email bounces
> - Link to v1: https://patch.msgid.link/20260716-amd-pstate-vm-v1-1-2ac97d3cf6e7@rong.moe
> ---
>   drivers/cpufreq/amd-pstate.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index a74a4cf99d22..b0b651380732 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -2167,6 +2167,7 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
>   };
>   
>   /*
> + * Processors without frequency scaling support can't do CPPC.
>    * CPPC function is not supported for family ID 17H with model_ID ranging from 0x10 to 0x2F.
>    * show the debug message that helps to check if the CPU has CPPC support for loading issue.
>    */
> @@ -2175,6 +2176,11 @@ static bool amd_cppc_supported(void)
>   	struct cpuinfo_x86 *c = &cpu_data(0);
>   	bool warn = false;
>   
> +	if (!cpu_feature_enabled(X86_FEATURE_HW_PSTATE)) {
> +		pr_debug_once("frequency scaling is not supported by the processor\n");
> +		return false;
> +	}
> +
>   	if ((boot_cpu_data.x86 == 0x17) && (boot_cpu_data.x86_model < 0x30)) {
>   		pr_debug_once("CPPC feature is not supported by the processor\n");
>   		return false;
> 
> ---
> base-commit: 248951ddc14de84de3910f9b13f51491a8cd91df
> change-id: 1cc24037-amd-pstate-vm-d6ab4c959bd3
> 
> Thanks,
> Rong
>