[PATCH v6 05/15] ACPI: CPPC: Serialize PCC single-register payload updates
Christian Loehle <[email protected]>
| Newsgroups | org.kernel.vger.linux-acpi,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pm |
|---|---|
| Message-ID | <[email protected]> |
The PCC doorbell protocol requires OSPM to confirm ownership of the shared
subspace before placing a command and its payload there.
cppc_set_reg_val_in_pcc() instead modifies the payload before taking
pcc_lock.
A concurrent command can consequently overwrite or consume the staged
value, and OSPM can write the shared region while the platform still owns
it.
Take the PCC write lock first, wait for the previous command to complete,
and keep the lock held while staging the value and submitting CMD_WRITE.
This follows the ownership sequence in ACPI 6.5 Section 14.5 and the
existing contract documented by send_pcc_cmd().
If ownership acquisition or staging fails, abort any older performance
batch before dropping the exclusive lock. This advances its generation and
wakes cppc_set_perf() callers which otherwise wait indefinitely for a
command this path did not submit.
Fixes: e05c75072c2e ("ACPI: CPPC: Add cppc_set_reg_val()")
Reported-by: Sashiko <[email protected]>
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 <[email protected]>
---
drivers/acpi/cppc_acpi.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 9ddcce7dc1a9..085e775b3637 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -407,6 +407,17 @@ static void cppc_complete_pcc_write(struct cppc_pcc_data *pcc_ss_data,
wake_up_all(&pcc_ss_data->pcc_write_wait_q);
}
+/* The caller must hold pcc_lock for write. */
+static void cppc_abort_pending_pcc_write(struct cppc_pcc_data *pcc_ss_data,
+ int ret)
+{
+ if (!pcc_ss_data->pending_pcc_write_cmd)
+ return;
+
+ pcc_ss_data->pending_pcc_write_cmd = false;
+ cppc_complete_pcc_write(pcc_ss_data, ret);
+}
+
/*
* This function transfers the ownership of the PCC to the platform
* So it must be called while holding write_lock(pcc_lock)
@@ -1507,7 +1518,7 @@ static int cppc_get_reg_val(int cpu, enum cppc_regs reg_idx, u64 *val)
static int cppc_set_reg_val_in_pcc(int cpu, struct cpc_register_resource *reg, u64 val)
{
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
- struct cppc_pcc_data *pcc_ss_data = NULL;
+ struct cppc_pcc_data *pcc_ss_data;
int ret;
if (pcc_ss_id < 0) {
@@ -1515,15 +1526,26 @@ static int cppc_set_reg_val_in_pcc(int cpu, struct cpc_register_resource *reg, u
return -ENODEV;
}
- ret = cpc_write(cpu, reg, val);
- if (ret)
- return ret;
-
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;
+
+ ret = cpc_write(cpu, reg, val);
+ if (ret)
+ goto out;
+
/* after writing CPC, transfer the ownership of PCC to platform */
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
+
+out:
+ if (ret)
+ cppc_abort_pending_pcc_write(pcc_ss_data, ret);
up_write(&pcc_ss_data->pcc_lock);
return ret;
--
2.34.1