[PATCH v3 06/15] ACPI: CPPC: Serialize PCC EPP payload updates

From: Christian Loehle

Date: Sun Aug 09 2026 - 02:28:59 EST


cppc_set_epp_perf() stages Autonomous Selection and Energy Performance
Preference in the PCC shared region before taking pcc_lock. The platform
may still own the subspace, or a concurrent command may consume or
overwrite only part of the new payload.

Take the PCC write lock and wait for OSPM ownership before staging either
control. Keep the lock held until the complete payload has been submitted
with CMD_WRITE, so firmware cannot observe a mixed transaction.

For a mixed PCC/non-PCC description, complete every fallible non-PCC write
before staging PCC data. Cross-address-space updates cannot be atomic, but
a non-PCC failure can no longer leave an unsent value in shared memory for
a later PCC command to consume.

Classify every probe-validated writable control as either PCC or non-PCC.
This covers SystemIO along with FFH and SystemMemory and avoids repeating a
flexible-address-space _OSC decision that probe has already made.

If ownership acquisition or PCC staging fails, abort any older pending
performance batch before releasing the exclusive lock so its Phase-II
waiters receive the error instead of sleeping indefinitely.

This follows the PCC ownership sequence in ACPI 6.5 Section 14.5.

Fixes: 7bc1fcd39901 ("ACPI: CPPC: Add AMD pstate energy performance preference cppc control")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Link: https://sashiko.dev/#/patchset/20260724134251.1632824-1-christian.loehle%40arm.com
Link: https://sashiko.dev/#/patchset/20260807111303.1062391-1-christian.loehle%40arm.com
Signed-off-by: Christian Loehle <christian.loehle@xxxxxxx>
---
drivers/acpi/cppc_acpi.c | 74 ++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 30 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 3e726da8d564..2b5da5c39cdd 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -1848,8 +1848,10 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
struct cpc_register_resource *auto_sel_reg;
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
struct cppc_pcc_data *pcc_ss_data = NULL;
- bool autosel_ffh_sysmem;
- bool epp_ffh_sysmem;
+ bool auto_sel_pcc;
+ bool auto_sel_non_pcc;
+ bool epp_pcc;
+ bool epp_non_pcc;
int ret;

if (!cpc_desc) {
@@ -1860,52 +1862,64 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE];
epp_set_reg = &cpc_desc->cpc_regs[ENERGY_PERF];

- epp_ffh_sysmem = CPC_SUPPORTED(epp_set_reg) &&
- (CPC_IN_FFH(epp_set_reg) || CPC_IN_SYSTEM_MEMORY(epp_set_reg));
- autosel_ffh_sysmem = CPC_SUPPORTED(auto_sel_reg) &&
- (CPC_IN_FFH(auto_sel_reg) || CPC_IN_SYSTEM_MEMORY(auto_sel_reg));
+ auto_sel_pcc = cpc_is_writable(auto_sel_reg) &&
+ CPC_IN_PCC(auto_sel_reg);
+ epp_pcc = cpc_is_writable(epp_set_reg) && CPC_IN_PCC(epp_set_reg);
+ auto_sel_non_pcc = cpc_is_writable(auto_sel_reg) && !auto_sel_pcc;
+ epp_non_pcc = cpc_is_writable(epp_set_reg) && !epp_pcc;

- if (CPC_IN_PCC(epp_set_reg) || CPC_IN_PCC(auto_sel_reg)) {
+ /* Complete fallible non-PCC writes before staging PCC data. */
+ if (auto_sel_non_pcc) {
+ ret = cpc_write(cpu, auto_sel_reg, enable);
+ if (ret)
+ return ret;
+ }
+ if (epp_non_pcc) {
+ ret = cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf);
+ if (ret)
+ return ret;
+ }
+
+ if (epp_pcc || auto_sel_pcc) {
if (pcc_ss_id < 0) {
pr_debug("Invalid pcc_ss_id for CPU:%d\n", cpu);
return -ENODEV;
}

- if (cpc_is_writable(auto_sel_reg)) {
+ pcc_ss_data = pcc_data[pcc_ss_id];
+ if (!pcc_ss_data)
+ return -ENODEV;
+
+ down_write(&pcc_ss_data->pcc_lock);
+
+ ret = check_pcc_chan(pcc_ss_id, false);
+ if (ret)
+ goto out_unlock;
+
+ if (auto_sel_pcc) {
ret = cpc_write(cpu, auto_sel_reg, enable);
if (ret)
- return ret;
+ goto out_unlock;
}

- if (cpc_is_writable(epp_set_reg)) {
+ if (epp_pcc) {
ret = cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf);
if (ret)
- return ret;
+ goto out_unlock;
}

- pcc_ss_data = pcc_data[pcc_ss_id];
-
- down_write(&pcc_ss_data->pcc_lock);
/* after writing CPC, transfer the ownership of PCC to platform */
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
- up_write(&pcc_ss_data->pcc_lock);
- } else if (osc_cpc_flexible_adr_space_confirmed &&
- (epp_ffh_sysmem || autosel_ffh_sysmem)) {
- if (autosel_ffh_sysmem) {
- ret = cpc_write(cpu, auto_sel_reg, enable);
- if (ret)
- return ret;
- }

- if (epp_ffh_sysmem) {
- ret = cpc_write(cpu, epp_set_reg,
- perf_ctrls->energy_perf);
- if (ret)
- return ret;
- }
+out_unlock:
+ if (ret)
+ cppc_abort_pending_pcc_write(pcc_ss_data, ret);
+ up_write(&pcc_ss_data->pcc_lock);
+ } else if (epp_non_pcc || auto_sel_non_pcc) {
+ ret = 0;
} else {
- ret = -ENOTSUPP;
- pr_debug("_CPC in PCC/FFH/SystemMemory are not supported\n");
+ ret = -EOPNOTSUPP;
+ pr_debug("No writable EPP controls for CPU:%d\n", cpu);
}

return ret;
--
2.34.1