ACPI: CPPC: Avoid Desired Performance reads on ACPI 6.6+
Subsystems (5)
Christian Loehle
maintainerv2 cover ACPI: CPPC: Avoid Desired Performance reads on ACPI 6.6+
ACPI 6.6 changed the Optional Attribute of Desired Performance from Read/Write to Write.
cppc-cpufreq reads Desired Performance when feedback counters cannot provide a usable sample because some older platforms repurpose the register to report actual delivered performance. Preserve that workaround on systems reporting an older ACPI revision, but do not attempt the read on ACPI 6.6 or later, where firmware no longer promises a readable value and cppc-cpufreq can fall back to its cached OSPM request instead.
cppc_get_perf() also reads Desired Performance while populating the control values used during cppc-cpufreq initialization. Its only in-tree caller overwrites that value with highest_perf before the controls are first written, so the value is never consumed.
Patches 1 and 2 provide minimal, backportable fixes for the two read paths. Patch 3 simplifies the mainline API by no longer reading Desired Performance through cppc_get_perf() on any ACPI revision.
Changes since v1:
- Mask the FADT minor revision's errata-generation bits.
- Add patch 2 as fix to also avoid reading Desired Performance from cppc_get_perf(), as suggested by Zhongqiu Han.
- Add patch 3 to change the API as there's currently no in-tree use of Desired Performance in cppc_get_perf()
Christian Loehle (3):
ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
ACPI: CPPC: Skip desired_perf read in cppc_get_perf()
ACPI: CPPC: Stop reading desired_perf in cppc_get_perf()
drivers/acpi/cppc_acpi.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.1
Christian Loehle
maintainerPATCH v2 1/3 ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
When CPPC feedback counters cannot provide a usable sample, cppc-cpufreq calls cppc_get_desired_perf() because some platforms repurpose Desired Performance to report actual delivered performance.
The fallback was added for platforms on which Desired Performance reflects delivered performance. ACPI 6.6 defines the register as write-only, so invoking that workaround on an ACPI 6.6 or later platform would require an invalid register read.
Make cppc_get_desired_perf() return -EOPNOTSUPP in that case. Its caller already handles an error by using the cached desired-performance value. When checking the FADT minor revision, mask off its upper errata-generation bits and compare only the specification minor version.
--- drivers/acpi/cppc_acpi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +14 -1
@@ -1316,15 +1316,28 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)return cpc_write (cpu, reg, val); } +static bool cppc_desired_perf_readable (void ) +{ +u8 minor_revision = acpi_gbl_FADT.minor_revision &0x0f ; + +return acpi_gbl_FADT.header.revision <6 || + (acpi_gbl_FADT.header.revision ==6 && minor_revision <6 ); +} +/** * cppc_get_desired_perf - Get the desired performance register value. * @cpunum: CPU from which to get desired performance. * @desired_perf: Return address. * -* Return: 0 for success, -EIO otherwise. +* Return: 0 for success, -EOPNOTSUPP for ACPI 6.6 or later, and a negative +* errno otherwise. */ int cppc_get_desired_perf (int cpunum,u64 *desired_perf) { +/* ACPI 6.6 no longer specifies Desired Performance as readable. */ +if (!cppc_desired_perf_readable ()) +return -EOPNOTSUPP ; +return cppc_get_reg_val (cpunum,DESIRED_PERF , desired_perf); }EXPORT_SYMBOL_GPL (cppc_get_desired_perf);
Signature · 1 line
2.34.1
Re: [PATCHv2 1/3] ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
Quoted 9 lines · Christian Loehle
When CPPC feedback counters cannot provide a usable sample, cppc-cpufreq calls
cppc_get_desired_perf()because some platforms repurpose Desired Performance to report actual delivered performance.The fallback was added for platforms on which Desired Performance reflects delivered performance. ACPI 6.6 defines the register as write-only, so invoking that workaround on an ACPI 6.6 or later platform would require an invalid register read.
Quoted 6 lines
Make
cppc_get_desired_perf()return-EOPNOTSUPPin that case. Its caller already handles an error by using the cached desired-performance value. When checking the FADT minor revision, mask off its upper errata-generation bits and compare only the specification minor version.Fixes c47195631960 ("cppc_cpufreq: Use desired perf if feedback ctrs are 0 or unchanged")
Hi Christian,
Please feel free to correct me if there is any misunderstanding.
ACPI 6.6 was released on 05/13/2025:
https://uefi.org/sites/default/files/resources/ACPI_Spec_6.6.pdf
And the fixes tag commit c47195631960 was committed on 09/29/2024.
Would this be considered an adaptation rather than a regression fix?
With the Fixes tag confirmed/fixed:
Quoted 40 lines
Signed-off-by Christian Loehle <[email protected]>--- drivers/acpi/cppc_acpi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)drivers/acpi/cppc_acpi.c +14
-1@@ -1316,15 +1316,28 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)return cpc_write (cpu, reg, val); } +static bool cppc_desired_perf_readable (void ) +{ +u8 minor_revision = acpi_gbl_FADT.minor_revision &0x0f ; + +return acpi_gbl_FADT.header.revision <6 || + (acpi_gbl_FADT.header.revision ==6 && minor_revision <6 ); +} +/** * cppc_get_desired_perf - Get the desired performance register value. * @cpunum: CPU from which to get desired performance. * @desired_perf: Return address. * -* Return: 0 for success, -EIO otherwise. +* Return: 0 for success, -EOPNOTSUPP for ACPI 6.6 or later, and a negative +* errno otherwise. */ int cppc_get_desired_perf (int cpunum,u64 *desired_perf) { +/* ACPI 6.6 no longer specifies Desired Performance as readable. */ +if (!cppc_desired_perf_readable ()) +return -EOPNOTSUPP ; +return cppc_get_reg_val (cpunum,DESIRED_PERF , desired_perf); }EXPORT_SYMBOL_GPL (cppc_get_desired_perf);
Signature · 2 lines
Thx and BRs, Zhongqiu Han
Christian Loehle
maintainerRe: [PATCHv2 1/3] ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
Quoted 20 lines · Zhongqiu Han
Quoted 9 lines · Christian Loehle
When CPPC feedback counters cannot provide a usable sample, cppc-cpufreq calls
cppc_get_desired_perf()because some platforms repurpose Desired Performance to report actual delivered performance.The fallback was added for platforms on which Desired Performance reflects delivered performance. ACPI 6.6 defines the register as write-only, so invoking that workaround on an ACPI 6.6 or later platform would require an invalid register read.
Quoted 6 lines
Make
cppc_get_desired_perf()return-EOPNOTSUPPin that case. Its caller already handles an error by using the cached desired-performance value. When checking the FADT minor revision, mask off its upper errata-generation bits and compare only the specification minor version.Fixes c47195631960 ("cppc_cpufreq: Use desired perf if feedback ctrs are 0 or unchanged")Hi Christian,
Please feel free to correct me if there is any misunderstanding.
Quoted 6 lines
ACPI 6.6 was released on 05/13/2025:
https://uefi.org/sites/default/files/resources/ACPI_Spec_6.6.pdfAnd the fixes tag commit
c47195631960was committed on 09/29/2024.Would this be considered an adaptation rather than a regression fix?
That is all correct, but the fixes tag is supposed to mean "this patch makes the commit in question work" (and therefore should be backported to all kernels containing this), which is then correct, as older kernels may still boot on newer (6.6) ACPI systems.
It doesn't mean that the mentioned commit is 'bad' or 'wrong'.
Quoted 4 lines
With the Fixes tag confirmed/fixed:
Reviewed-by Zhongqiu Han <[email protected]>
Thanks, I'll leave as-is and pick this up if you don't mind.
Quoted 42 lines
Quoted 40 lines
Signed-off-by Christian Loehle <[email protected]>---
drivers/acpi/cppc_acpi.c| 15 ++++++++++++++-1 file changed, 14 insertions(+), 1 deletion(-)drivers/acpi/cppc_acpi.c +13
-1@@ -1316,15 +1316,28 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val) return cpc_write(cpu, reg, val); } +static bool cppc_desired_perf_readable(void) +{ + u8 minor_revision = acpi_gbl_FADT.minor_revision & 0x0f; + + return acpi_gbl_FADT.header.revision < 6 || + (acpi_gbl_FADT.header.revision == 6 && minor_revision < 6); +} + /** * cppc_get_desired_perf - Get the desired performance register value. * @cpunum: CPU from which to get desired performance. * @desired_perf: Return address. * - * Return: 0 for success, -EIO otherwise. + * Return: 0 for success, -EOPNOTSUPP for ACPI 6.6 or later, and a negative + * errno otherwise. */ int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { + /* ACPI 6.6 no longer specifies Desired Performance as readable. */ + if (!cppc_desired_perf_readable()) + return -EOPNOTSUPP; + return cppc_get_reg_val(cpunum, DESIRED_PERF, desired_perf); } EXPORT_SYMBOL_GPL(cppc_get_desired_perf);
Sumit Gupta
reviewerRe: [PATCHv2 1/3] ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
In reply to Christian LoehleQuoted 30 lines · Christian Loehle
External email: Use caution opening links or attachments
When CPPC feedback counters cannot provide a usable sample, cppc-cpufreq calls
cppc_get_desired_perf()because some platforms repurpose Desired Performance to report actual delivered performance.The fallback was added for platforms on which Desired Performance reflects delivered performance. ACPI 6.6 defines the register as write-only, so invoking that workaround on an ACPI 6.6 or later platform would require an invalid register read.
Make
cppc_get_desired_perf()return-EOPNOTSUPPin that case. Its caller already handles an error by using the cached desired-performance value. When checking the FADT minor revision, mask off its upper errata-generation bits and compare only the specification minor version.Fixes c47195631960 ("cppc_cpufreq: Use desired perf if feedback ctrs are 0 or unchanged")Signed-off-by Christian Loehle <[email protected]>--- drivers/acpi/cppc_acpi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)drivers/acpi/cppc_acpi.c +0
-0@@ -1316,15 +1316,28 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)return cpc_write (cpu, reg, val);
drivers/acpi/cppc_acpi.c static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val) · line 1326
Quoted 10 lines
drivers/acpi/cppc_acpi.c +8
-0} +static bool cppc_desired_perf_readable (void ) +{ +u8 minor_revision = acpi_gbl_FADT.minor_revision &0x0f ; + +return acpi_gbl_FADT.header.revision <6 || + (acpi_gbl_FADT.header.revision ==6 && minor_revision <6 ); +} +
A platform whose _CPC follows ACPI 6.6 semantics but whose FADT still reports 6.5 would pass this check as readable. If the register read returns zero, cppc_cpufreq_get_rate() reports 0 kHz and policy online fails with:
cpufreq: cpufreq_policy_online: ->get() failed
Since the FADT version cannot be fully relied upon, would it make sense to also harden the consumer? Although zero is valid Desired Performance value, it is not usable as a frequency estimate.
So, cppc_cpufreq_get_rate() could fall back to the cached OSPM request:
- if (cppc_get_desired_perf(cpu, &delivered_perf))
+ if (cppc_get_desired_perf(cpu, &delivered_perf) || !delivered_perf) delivered_perf = cpu_data->perf_ctrls.desired_perf;
Thanks,
Sumit
Quoted 21 lines
drivers/acpi/cppc_acpi.c +6
-2/** * cppc_get_desired_perf - Get the desired performance register value. * @cpunum: CPU from which to get desired performance. * @desired_perf: Return address. * -* Return: 0 for success, -EIO otherwise. +* Return: 0 for success, -EOPNOTSUPP for ACPI 6.6 or later, and a negative +* errno otherwise. */ int cppc_get_desired_perf (int cpunum,u64 *desired_perf) { +/* ACPI 6.6 no longer specifies Desired Performance as readable. */ +if (!cppc_desired_perf_readable ()) +return -EOPNOTSUPP ; +return cppc_get_reg_val (cpunum,DESIRED_PERF , desired_perf); }EXPORT_SYMBOL_GPL (cppc_get_desired_perf); --2.34.1
Christian Loehle
maintainerPATCH v2 2/3 ACPI: CPPC: Skip desired_perf read in cppc_get_perf()
In reply to Christian LoehleACPI 6.6 changed the Optional Attribute of Desired Performance from Read/Write to Write. cppc_get_perf() nevertheless reads the register when initializing performance controls, even though cppc-cpufreq overwrites the value before using it.
Use the readability check from cppc_get_desired_perf() and leave desired_perf zero instead of reading it on ACPI 6.6 or later. Also exclude the register from PCC read-command detection so it cannot trigger an otherwise unnecessary read command.
--- drivers/acpi/cppc_acpi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/cppc_acpi.c +4 -2
@@ -1843,6 +1843,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; +bool read_desired_perf =cppc_desired_perf_readable ();int ret =0 , regs_in_pcc =0 ;if (!cpc_desc) {
@@ -1862,7 +1863,8 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ -if (CPC_IN_PCC (desired_perf_reg) ||CPC_IN_PCC (min_perf_reg) || +if ((read_desired_perf &&CPC_IN_PCC (desired_perf_reg)) || +CPC_IN_PCC (min_perf_reg) ||CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {
@@ -1894,7 +1896,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) } perf_ctrls->min_perf = min; -if (CPC_SUPPORTED (desired_perf_reg)) { +if (read_desired_perf &&CPC_SUPPORTED (desired_perf_reg)) { ret =cpc_read (cpu, desired_perf_reg, &desired_perf);if (ret) goto out_err;
Signature · 1 line
2.34.1
Re: [PATCHv2 2/3] ACPI: CPPC: Skip desired_perf read in cppc_get_perf()
Quoted 10 lines · Christian Loehle
ACPI 6.6 changed the Optional Attribute of Desired Performance from Read/Write to Write.
cppc_get_perf()nevertheless reads the register when initializing performance controls, even though cppc-cpufreq overwrites the value before using it.Use the readability check from
cppc_get_desired_perf()and leavedesired_perfzero instead of reading it on ACPI 6.6 or later. Also exclude the register from PCC read-command detection so it cannot trigger an otherwise unnecessary read command.
Quoted 4 lines
Fixes 658fa7b1c47a ("ACPI: CPPC: Add cppc_get_perf() API to read performance controls")Suggested-by Zhongqiu Han <[email protected]>Signed-off-by Christian Loehle <[email protected]>
Looks good to me.
Quoted 35 lines
--- drivers/acpi/cppc_acpi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/acpi/cppc_acpi.c +4
-2@@ -1843,6 +1843,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; +bool read_desired_perf =cppc_desired_perf_readable ();int ret =0 , regs_in_pcc =0 ;if (!cpc_desc) {@@ -1862,7 +1863,8 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ -if (CPC_IN_PCC (desired_perf_reg) ||CPC_IN_PCC (min_perf_reg) || +if ((read_desired_perf &&CPC_IN_PCC (desired_perf_reg)) || +CPC_IN_PCC (min_perf_reg) ||CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {@@ -1894,7 +1896,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) } perf_ctrls->min_perf = min; -if (CPC_SUPPORTED (desired_perf_reg)) { +if (read_desired_perf &&CPC_SUPPORTED (desired_perf_reg)) { ret =cpc_read (cpu, desired_perf_reg, &desired_perf);if (ret) goto out_err;
Signature · 2 lines
Thx and BRs, Zhongqiu Han
Christian Loehle
maintainerPATCH v2 3/3 ACPI: CPPC: Stop reading desired_perf in cppc_get_perf()
In reply to Christian Loehlecppc_get_perf() has one in-tree caller, cppc_cpufreq_get_cpu_data(). It uses the function to preserve existing controls before writing them, but overwrites desired_perf with highest_perf before the first cppc_set_perf(). Consequently, the current Desired Performance value is not consumed.
Remove the Desired Performance read from this aggregate getter and document that the field is returned as zero.
--- drivers/acpi/cppc_acpi.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
drivers/acpi/cppc_acpi.c +8 -15
@@ -1828,22 +1828,22 @@ int cppc_set_enable(int cpu, bool enable)EXPORT_SYMBOL_GPL (cppc_set_enable);/** -* cppc_get_perf - Get a CPU's performance controls. +* cppc_get_perf - Get a CPU's readable performance controls. * @cpu: CPU for which to get performance controls. * @perf_ctrls: ptr to cppc_perf_ctrls. See cppc_acpi.h * +* Desired Performance is not read and is returned as 0. +* * Return: 0 for success with perf_ctrls, -ERRNO otherwise. */ int cppc_get_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls) {struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpu); -struct cpc_register_resource *desired_perf_reg, - *min_perf_reg, *max_perf_reg, +struct cpc_register_resource *min_perf_reg, *max_perf_reg, *energy_perf_reg, *auto_sel_reg; -u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 , auto_sel =0 ; +u64 min =0 , max =0 , energy_perf =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; -bool read_desired_perf =cppc_desired_perf_readable ();int ret =0 , regs_in_pcc =0 ;if (!cpc_desc) {
@@ -1856,16 +1856,14 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)return -EINVAL ; } - desired_perf_reg = &cpc_desc->cpc_regs[DESIRED_PERF ]; min_perf_reg = &cpc_desc->cpc_regs[MIN_PERF ]; max_perf_reg = &cpc_desc->cpc_regs[MAX_PERF ]; energy_perf_reg = &cpc_desc->cpc_regs[ENERGY_PERF ]; auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ -if ((read_desired_perf &&CPC_IN_PCC (desired_perf_reg)) || -CPC_IN_PCC (min_perf_reg) || -CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg) || +if (CPC_IN_PCC (min_perf_reg) ||CPC_IN_PCC (max_perf_reg) || +CPC_IN_PCC (energy_perf_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {pr_debug ("Invalid pcc_ss_id for CPU:%d\n" , cpu);
@@ -1896,12 +1894,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) } perf_ctrls->min_perf = min; -if (read_desired_perf &&CPC_SUPPORTED (desired_perf_reg)) { - ret =cpc_read (cpu, desired_perf_reg, &desired_perf); -if (ret) - goto out_err; - } - perf_ctrls->desired_perf = desired_perf; + perf_ctrls->desired_perf =0 ;if (CPC_SUPPORTED (energy_perf_reg)) { ret =cpc_read (cpu, energy_perf_reg, &energy_perf);
Signature · 1 line
2.34.1
Re: [PATCHv2 3/3] ACPI: CPPC: Stop reading desired_perf in cppc_get_perf()
Quoted 18 lines · Christian Loehle
cppc_get_perf()has one in-tree caller,cppc_cpufreq_get_cpu_data(). It uses the function to preserve existing controls before writing them, but overwritesdesired_perfwithhighest_perfbefore the firstcppc_set_perf(). Consequently, the current Desired Performance value is not consumed.Remove the Desired Performance read from this aggregate getter and document that the field is returned as zero.
Signed-off-by Christian Loehle <[email protected]>--- drivers/acpi/cppc_acpi.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)drivers/acpi/cppc_acpi.c +0
-0
drivers/acpi/cppc_acpi.c int cppc_set_enable(int cpu, bool enable) · line 1831
Quoted 5 lines
drivers/acpi/cppc_acpi.c +1
-1@@ -1828,22 +1828,22 @@ int cppc_set_enable(int cpu, bool enable)EXPORT_SYMBOL_GPL (cppc_set_enable);/** -* cppc_get_perf - Get a CPU's performance controls. +* cppc_get_perf - Get a CPU's readable performance controls.
Small nit: is this also applicable to ACPI <6.6?
drivers/acpi/cppc_acpi.c int cppc_set_enable(int cpu, bool enable) · line 1835
Quoted 4 lines
drivers/acpi/cppc_acpi.c +1
-0* @cpu: CPU for which to get performance controls. * @perf_ctrls: ptr to cppc_perf_ctrls. See cppc_acpi.h * +* Desired Performance is not read and is returned as 0.
Likewise.
Quoted 41 lines
drivers/acpi/cppc_acpi.c +5
-8+* * Return: 0 for success with perf_ctrls, -ERRNO otherwise. */ int cppc_get_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls) {struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpu); -struct cpc_register_resource *desired_perf_reg, - *min_perf_reg, *max_perf_reg, +struct cpc_register_resource *min_perf_reg, *max_perf_reg, *energy_perf_reg, *auto_sel_reg; -u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 , auto_sel =0 ; +u64 min =0 , max =0 , energy_perf =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; -bool read_desired_perf =cppc_desired_perf_readable ();int ret =0 , regs_in_pcc =0 ;if (!cpc_desc) {@@ -1856,16 +1856,14 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)return -EINVAL ; } - desired_perf_reg = &cpc_desc->cpc_regs[DESIRED_PERF ]; min_perf_reg = &cpc_desc->cpc_regs[MIN_PERF ]; max_perf_reg = &cpc_desc->cpc_regs[MAX_PERF ]; energy_perf_reg = &cpc_desc->cpc_regs[ENERGY_PERF ]; auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ -if ((read_desired_perf &&CPC_IN_PCC (desired_perf_reg)) || -CPC_IN_PCC (min_perf_reg) || -CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg) || +if (CPC_IN_PCC (min_perf_reg) ||CPC_IN_PCC (max_perf_reg) || +CPC_IN_PCC (energy_perf_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {pr_debug ("Invalid pcc_ss_id for CPU:%d\n" , cpu);@@ -1896,12 +1894,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) } perf_ctrls->min_perf = min;
drivers/acpi/cppc_acpi.c int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) · line 1900
Quoted 10 lines
drivers/acpi/cppc_acpi.c +1
-6-if (read_desired_perf &&CPC_SUPPORTED (desired_perf_reg)) { - ret =cpc_read (cpu, desired_perf_reg, &desired_perf); -if (ret) - goto out_err; - } - perf_ctrls->desired_perf = desired_perf; + perf_ctrls->desired_perf =0 ;if (CPC_SUPPORTED (energy_perf_reg)) { ret =cpc_read (cpu, energy_perf_reg, &energy_perf);
This is an exported API, I'm not sure whether this would break any out of-tree users, but I don't think compatibility concerns for out-of-tree users should weigh heavily in this case.
Looks good to me.
Signature · 2 lines
Thx and BRs, Zhongqiu Han
Christian Loehle
maintainerv3 cover ACPI: CPPC: Avoid Desired Performance reads on ACPI 6.6+
In reply to Christian LoehleACPI 6.6 changed the Optional Attribute of Desired Performance from Read/Write to Write.
cppc-cpufreq reads Desired Performance when feedback counters cannot provide a usable sample because some older platforms repurpose the register to report actual delivered performance. Preserve that workaround on systems reporting an older ACPI revision, but do not attempt the read on ACPI 6.6 or later, where firmware no longer promises a readable value and cppc-cpufreq can fall back to its cached OSPM request instead.
cppc_get_perf() also reads Desired Performance while populating the control values used during cppc-cpufreq initialization. Its only in-tree caller overwrites that value with highest_perf before the controls are first written, so the value is never consumed.
Patches 1 and 2 provide minimal, backportable fixes for the two read paths. Patch 3 simplifies the mainline API by no longer reading Desired Performance through cppc_get_perf() on any ACPI revision.
Changes since v2:
- Fall back to the cached OSPM request when reading Desired Performance returns zero as suggested by Sumit Gupta.
- Pick up Reviewed-by tags from Zhongqiu Han for patches 2 and 3.
- Rebase onto v7.2-rc6
Christian Loehle (3):
ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
ACPI: CPPC: Skip desired_perf read in cppc_get_perf()
ACPI: CPPC: Stop reading desired_perf in cppc_get_perf()
drivers/acpi/cppc_acpi.c | 36 +++++++++++++++++++++------------- drivers/cpufreq/cppc_cpufreq.c | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-)
base-commit: 075b74841bd0065a3bda3440873c747938e69b68
Signature · 1 line
2.34.1
Christian Loehle
maintainerPATCH v3 1/3 ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
When CPPC feedback counters cannot provide a usable sample, cppc-cpufreq calls cppc_get_desired_perf() because some platforms repurpose Desired Performance to report actual delivered performance.
The fallback was added for platforms on which Desired Performance reflects delivered performance. ACPI 6.6 defines the register as write-only, so invoking that workaround on an ACPI 6.6 or later platform would require an invalid register read.
Make cppc_get_desired_perf() return -EOPNOTSUPP in that case. When checking the FADT minor revision, mask off its upper errata-generation bits and compare only the specification minor version.
The FADT revision may not accurately describe the semantics implemented by _CPC. If a nominally pre-6.6 platform implements Desired Performance as write-only, a read may return zero and make cppc_cpufreq_get_rate() report 0 kHz. Treat a zero read as unusable and fall back to the cached OSPM request, just as for a failed read.
--- drivers/acpi/cppc_acpi.c | 15 ++++++++++++++- drivers/cpufreq/cppc_cpufreq.c | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/acpi/cppc_acpi.c +14 -1
@@ -1316,15 +1316,28 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)return cpc_write (cpu, reg, val); } +static bool cppc_desired_perf_readable (void ) +{ +u8 minor_revision = acpi_gbl_FADT.minor_revision &0x0f ; + +return acpi_gbl_FADT.header.revision <6 || + (acpi_gbl_FADT.header.revision ==6 && minor_revision <6 ); +} +/** * cppc_get_desired_perf - Get the desired performance register value. * @cpunum: CPU from which to get desired performance. * @desired_perf: Return address. * -* Return: 0 for success, -EIO otherwise. +* Return: 0 for success, -EOPNOTSUPP for ACPI 6.6 or later, and a negative +* errno otherwise. */ int cppc_get_desired_perf (int cpunum,u64 *desired_perf) { +/* ACPI 6.6 no longer specifies Desired Performance as readable. */ +if (!cppc_desired_perf_readable ()) +return -EOPNOTSUPP ; +return cppc_get_reg_val (cpunum,DESIRED_PERF , desired_perf); }EXPORT_SYMBOL_GPL (cppc_get_desired_perf);
drivers/cpufreq/cppc_cpufreq.c +1 -1
@@ -836,7 +836,7 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)* value first as some platforms may update the actual delivered perf * there; if failed, resort to the cached desired perf. */ -if (cppc_get_desired_perf (cpu, &delivered_perf)) +if (cppc_get_desired_perf (cpu, &delivered_perf) || !delivered_perf) delivered_perf = cpu_data->perf_ctrls.desired_perf;return cppc_perf_to_khz (&cpu_data->perf_caps, delivered_perf);
Signature · 1 line
2.34.1
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v3 1/3] ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
Quoted 5 lines · Christian Loehle
When CPPC feedback counters cannot provide a usable sample, cppc-cpufreq calls
cppc_get_desired_perf()because some platforms repurpose Desired Performance to report actual delivered performance.
Quoted 8 lines
The fallback was added for platforms on which Desired Performance reflects delivered performance. ACPI 6.6 defines the register as write-only, so invoking that workaround on an ACPI 6.6 or later platform would require an invalid register read.
Make
cppc_get_desired_perf()return-EOPNOTSUPPin that case. When checking the FADT minor revision, mask off its upper errata-generation bits and compare only the specification minor version.
I'm wondering if the _CPC revision can be used for this instead of the spec revision?
The _CPC revision changed from 3 to 4 between ACPI 6.5 and ACPI 6.6, so doing that should be straightforward.
Quoted 65 lines
The FADT revision may not accurately describe the semantics implemented by
_CPC. If a nominally pre-6.6 platform implements Desired Performance as write-only, a read may return zero and makecppc_cpufreq_get_rate()report 0 kHz. Treat a zero read as unusable and fall back to the cached OSPM request, just as for a failed read.Fixes c47195631960 ("cppc_cpufreq: Use desired perf if feedback ctrs are 0 or unchanged")Suggested-by Sumit Gupta <[email protected]>Signed-off-by Christian Loehle <[email protected]>--- drivers/acpi/cppc_acpi.c | 15 ++++++++++++++- drivers/cpufreq/cppc_cpufreq.c | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-)drivers/acpi/cppc_acpi.c +14
-1@@ -1316,15 +1316,28 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)return cpc_write (cpu, reg, val); } +static bool cppc_desired_perf_readable (void ) +{ +u8 minor_revision = acpi_gbl_FADT.minor_revision &0x0f ; + +return acpi_gbl_FADT.header.revision <6 || + (acpi_gbl_FADT.header.revision ==6 && minor_revision <6 ); +} +/** * cppc_get_desired_perf - Get the desired performance register value. * @cpunum: CPU from which to get desired performance. * @desired_perf: Return address. * -* Return: 0 for success, -EIO otherwise. +* Return: 0 for success, -EOPNOTSUPP for ACPI 6.6 or later, and a negative +* errno otherwise. */ int cppc_get_desired_perf (int cpunum,u64 *desired_perf) { +/* ACPI 6.6 no longer specifies Desired Performance as readable. */ +if (!cppc_desired_perf_readable ()) +return -EOPNOTSUPP ; +return cppc_get_reg_val (cpunum,DESIRED_PERF , desired_perf); }EXPORT_SYMBOL_GPL (cppc_get_desired_perf);drivers/cpufreq/cppc_cpufreq.c +1
-2@@ -836,7 +836,7 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)* value first as some platforms may update the actual delivered perf * there; if failed, resort to the cached desired perf. */ -if (cppc_get_desired_perf (cpu, &delivered_perf)) +if (cppc_get_desired_perf (cpu, &delivered_perf) || !delivered_perf) delivered_perf = cpu_data->perf_ctrls.desired_perf;return cppc_perf_to_khz (&cpu_data->perf_caps, delivered_perf); --2.34.1
Christian Loehle
maintainerRe: [PATCH v3 1/3] ACPI: CPPC: Reject desired_perf reads on ACPI 6.6+
Quoted 9 lines · Rafael J. Wysocki (Intel)
Quoted 9 lines
When CPPC feedback counters cannot provide a usable sample, cppc-cpufreq calls
cppc_get_desired_perf()because some platforms repurpose Desired Performance to report actual delivered performance.The fallback was added for platforms on which Desired Performance reflects delivered performance. ACPI 6.6 defines the register as write-only, so invoking that workaround on an ACPI 6.6 or later platform would require an invalid register read.
Quoted 8 lines
Quoted 3 lines
Make
cppc_get_desired_perf()return-EOPNOTSUPPin that case. When checking the FADT minor revision, mask off its upper errata-generation bits and compare only the specification minor version.I'm wondering if the
_CPCrevision can be used for this instead of the spec revision?The
_CPCrevision changed from 3 to 4 between ACPI 6.5 and ACPI 6.6, so doing that should be straightforward.
Yup you're correct, much nicer, I'll fix that
Christian Loehle
maintainerPATCH v3 2/3 ACPI: CPPC: Skip desired_perf read in cppc_get_perf()
In reply to Christian LoehleACPI 6.6 changed the Optional Attribute of Desired Performance from Read/Write to Write. cppc_get_perf() nevertheless reads the register when initializing performance controls, even though cppc-cpufreq overwrites the value before using it.
Use the readability check from cppc_get_desired_perf() and leave desired_perf zero instead of reading it on ACPI 6.6 or later. Also exclude the register from PCC read-command detection so it cannot trigger an otherwise unnecessary read command.
--- drivers/acpi/cppc_acpi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/cppc_acpi.c +4 -2
@@ -1843,6 +1843,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; +bool read_desired_perf =cppc_desired_perf_readable ();int ret =0 , regs_in_pcc =0 ;if (!cpc_desc) {
@@ -1862,7 +1863,8 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ -if (CPC_IN_PCC (desired_perf_reg) ||CPC_IN_PCC (min_perf_reg) || +if ((read_desired_perf &&CPC_IN_PCC (desired_perf_reg)) || +CPC_IN_PCC (min_perf_reg) ||CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {
@@ -1894,7 +1896,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) } perf_ctrls->min_perf = min; -if (CPC_SUPPORTED (desired_perf_reg)) { +if (read_desired_perf &&CPC_SUPPORTED (desired_perf_reg)) { ret =cpc_read (cpu, desired_perf_reg, &desired_perf);if (ret) goto out_err;
Signature · 1 line
2.34.1
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v3 2/3] ACPI: CPPC: Skip desired_perf read in cppc_get_perf()
Quoted 5 lines · Christian Loehle
ACPI 6.6 changed the Optional Attribute of Desired Performance from Read/Write to Write.
cppc_get_perf()nevertheless reads the register when initializing performance controls, even though cppc-cpufreq overwrites the value before using it.
IMV it would be better to say that the change from R/W to W happened between _CPC rev 3 (in ACPI 6.5) and _CPC rev 4 (in ACPI 6.6).
It would also be better to refer to the _CPC revision in the paragraph below.
Quoted 48 lines
Use the readability check from
cppc_get_desired_perf()and leavedesired_perfzero instead of reading it on ACPI 6.6 or later. Also exclude the register from PCC read-command detection so it cannot trigger an otherwise unnecessary read command.Fixes 658fa7b1c47a ("ACPI: CPPC: Add cppc_get_perf() API to read performance controls")Suggested-by Zhongqiu Han <[email protected]>Reviewed-by Zhongqiu Han <[email protected]>Signed-off-by Christian Loehle <[email protected]>--- drivers/acpi/cppc_acpi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/acpi/cppc_acpi.c +4
-3@@ -1843,6 +1843,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; +bool read_desired_perf =cppc_desired_perf_readable ();int ret =0 , regs_in_pcc =0 ;if (!cpc_desc) {@@ -1862,7 +1863,8 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ -if (CPC_IN_PCC (desired_perf_reg) ||CPC_IN_PCC (min_perf_reg) || +if ((read_desired_perf &&CPC_IN_PCC (desired_perf_reg)) || +CPC_IN_PCC (min_perf_reg) ||CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {@@ -1894,7 +1896,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) } perf_ctrls->min_perf = min; -if (CPC_SUPPORTED (desired_perf_reg)) { +if (read_desired_perf &&CPC_SUPPORTED (desired_perf_reg)) { ret =cpc_read (cpu, desired_perf_reg, &desired_perf);if (ret) goto out_err; --2.34.1
Christian Loehle
maintainerPATCH v3 3/3 ACPI: CPPC: Stop reading desired_perf in cppc_get_perf()
In reply to Christian Loehlecppc_get_perf() has one in-tree caller, cppc_cpufreq_get_cpu_data(). It uses the function to preserve existing controls before writing them, but overwrites desired_perf with highest_perf before the first cppc_set_perf(). Consequently, the current Desired Performance value is not consumed.
Remove the Desired Performance read from this aggregate getter and document that the field is returned as zero.
--- drivers/acpi/cppc_acpi.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
drivers/acpi/cppc_acpi.c +8 -15
@@ -1828,22 +1828,22 @@ int cppc_set_enable(int cpu, bool enable)EXPORT_SYMBOL_GPL (cppc_set_enable);/** -* cppc_get_perf - Get a CPU's performance controls. +* cppc_get_perf - Get a CPU's readable performance controls. * @cpu: CPU for which to get performance controls. * @perf_ctrls: ptr to cppc_perf_ctrls. See cppc_acpi.h * +* Desired Performance is not read and is returned as 0. +* * Return: 0 for success with perf_ctrls, -ERRNO otherwise. */ int cppc_get_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls) {struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpu); -struct cpc_register_resource *desired_perf_reg, - *min_perf_reg, *max_perf_reg, +struct cpc_register_resource *min_perf_reg, *max_perf_reg, *energy_perf_reg, *auto_sel_reg; -u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 , auto_sel =0 ; +u64 min =0 , max =0 , energy_perf =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; -bool read_desired_perf =cppc_desired_perf_readable ();int ret =0 , regs_in_pcc =0 ;if (!cpc_desc) {
@@ -1856,16 +1856,14 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)return -EINVAL ; } - desired_perf_reg = &cpc_desc->cpc_regs[DESIRED_PERF ]; min_perf_reg = &cpc_desc->cpc_regs[MIN_PERF ]; max_perf_reg = &cpc_desc->cpc_regs[MAX_PERF ]; energy_perf_reg = &cpc_desc->cpc_regs[ENERGY_PERF ]; auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ -if ((read_desired_perf &&CPC_IN_PCC (desired_perf_reg)) || -CPC_IN_PCC (min_perf_reg) || -CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg) || +if (CPC_IN_PCC (min_perf_reg) ||CPC_IN_PCC (max_perf_reg) || +CPC_IN_PCC (energy_perf_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {pr_debug ("Invalid pcc_ss_id for CPU:%d\n" , cpu);
@@ -1896,12 +1894,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) } perf_ctrls->min_perf = min; -if (read_desired_perf &&CPC_SUPPORTED (desired_perf_reg)) { - ret =cpc_read (cpu, desired_perf_reg, &desired_perf); -if (ret) - goto out_err; - } - perf_ctrls->desired_perf = desired_perf; + perf_ctrls->desired_perf =0 ;if (CPC_SUPPORTED (energy_perf_reg)) { ret =cpc_read (cpu, energy_perf_reg, &energy_perf);
Signature · 1 line
2.34.1
Quoted 28 lines · Christian Loehle
External email: Use caution opening links or attachments
ACPI 6.6 changed the Optional Attribute of Desired Performance from Read/Write to Write.
cppc-cpufreq reads Desired Performance when feedback counters cannot provide a usable sample because some older platforms repurpose the register to report actual delivered performance. Preserve that workaround on systems reporting an older ACPI revision, but do not attempt the read on ACPI 6.6 or later, where firmware no longer promises a readable value and cppc-cpufreq can fall back to its cached OSPM request instead.
cppc_get_perf()also reads Desired Performance while populating the control values used during cppc-cpufreq initialization. Its only in-tree caller overwrites that value withhighest_perfbefore the controls are first written, so the value is never consumed.Patches 1 and 2 provide minimal, backportable fixes for the two read paths. Patch 3 simplifies the mainline API by no longer reading Desired Performance through
cppc_get_perf()on any ACPI revision.Changes since v2:
- Fall back to the cached OSPM request when reading Desired Performance returns zero as suggested by Sumit Gupta.
- Pick up Reviewed-by tags from Zhongqiu Han for patches 2 and 3.
- Rebase onto v7.2-rc6
Quoted 4 lines
Christian Loehle (3):
ACPI: CPPC: Rejectdesired_perfreads on ACPI 6.6+
ACPI: CPPC: Skipdesired_perfread incppc_get_perf()
ACPI: CPPC: Stop readingdesired_perfincppc_get_perf()
For the entire series:
Thanks,
Sumit