diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 05a547bbe936..b4cf93dec18b 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -2081,6 +2081,15 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) cpc_apply_platform_quirks(gas_t, i - 2, platform_quirks); + /* EPP interfaces require the full 0-255 preference range. */ + if (i - 2 == ENERGY_PERF && gas_t->bit_width < 8 && + !IS_NULL_REG(gas_t)) { + pr_debug("CPU%d: EPP register width %u is not supported\n", + pr->id, gas_t->bit_width); + ret = -EOPNOTSUPP; + goto out_free; + } + /* * The PCC Subspace index is encoded inside * the CPC table entries. The same PCC index @@ -2940,9 +2949,9 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps) if (!high || !low || !nom || !ref || !min_nonlinear || high > U32_MAX || low > U32_MAX || guaranteed > U32_MAX || nom > U32_MAX || ref > U32_MAX || min_nonlinear > U32_MAX || - high < nom || nom < min_nonlinear || min_nonlinear < low || + high < min_nonlinear || min_nonlinear < low || (CPC_SUPPORTED(guaranteed_reg) && - (guaranteed < low || guaranteed > nom))) { + (guaranteed < low || guaranteed > high))) { ret = -EFAULT; goto out_err; } diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 957fa7775260..b2af24ae5008 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -714,7 +714,17 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) pr_debug("Unsupported CPU co-ord type: %d\n", policy->shared_type); ret = -EFAULT; - goto out; + goto out_put; + } + + /* + * Enable CPPC. The Enable register is optional - some platforms + * may not support it. + */ + ret = cppc_set_enable(cpu, true); + if (ret && ret != -EOPNOTSUPP) { + pr_err("Failed to enable CPPC for CPU%u (%d)\n", cpu, ret); + goto out_put; } policy->fast_switch_possible = cppc_allow_fast_switch(policy->cpus); @@ -742,6 +752,8 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) return 0; out: + cppc_set_enable(cpu, false); +out_put: cppc_cpufreq_put_cpu_data(policy); return ret; } diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 24319b214d7b..4332cb114070 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2452,6 +2452,14 @@ int cpufreq_driver_target(struct cpufreq_policy *policy, { guard(cpufreq_policy_write)(policy); + /* + * The last CPU in the policy may have gone offline after the caller + * obtained it, in which case the policy is inactive and must not be + * used for changing the frequency. + */ + if (unlikely(policy_is_inactive(policy))) + return -EBUSY; + return __cpufreq_driver_target(policy, target_freq, relation); } EXPORT_SYMBOL_GPL(cpufreq_driver_target);