From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794590047; b=ESc6XHSonA8dNloYaf1KPooKhBDv3m0oxzrjM1tkRHhQpW4spRjET44FtJyND8xmCaeN QEH5LbaTi4pndcjZs1nqAH7daOgbV2YE09svQcpMlfj9dFCk8HajfJTDImhwv23XL2llC dhQPwrplY8V8S0jEt/syFr8lbP5F9/RVOh7wUPyxPFkWlC2+joSlKRk2YFQlHeXBBR2Qt l5jzj4mcBzUMaHz6VC/CHxHw8cIEEl1pclIbnkXWUYjCXaw6no/Vt83bDp0d4BSytW8E2 4NiMTnNn55CHXqDQps5mMymQY8ayy9eZLOe+eyHJbulRek9wID8Q2U/aL2ZFWHQoS2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590047; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=FQjKBQugbQth2vhiKHfq3ZcuQY1GXSHQlqhlVLbHyvU=; b=WHcz5tF6MQb63SVkffzWBjDvFS3al8XkBMcGBv3dqzBmPMsq6wy8N6DBbiXVZfVBqebJ iVlqMZaRJ13pWloZ905VCGPm9q1IalracMvOcmk00h9sGUiyqSbdn7C1PJO7DhcSvcLkP w/R3dhTI1iaXBckYUBMYafyLtVjTC2OVQqYPlIk9JwPSHXUkXwCm15CGIo0/qWmrSatoK pMG0yvT0EdLNaixnY0SztNDmryznz/qY+DktA4KYdvR22qFDsw09m4545q82scjhu4MBL FB3ZoBKSJtYP3GXKRBC0l2cBC6UXUxYvjzyNUItzrcIENuz9s1emdQf9M7KtDPIVTsg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ts072M+1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50E15606A33B; Fri, 13 Nov 2026 17:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ts072M+1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1D911F000C5; Fri, 13 Nov 2026 17:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590047; bh=FQjKBQugbQth2vhiKHfq3ZcuQY1GXSHQlqhlVLbHyvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ts072M+1rYrhby2CHakB4Ft47fPQa6CvemOSr/qN3CNGmcLYWAWInMqcB+UKO5luL hZCVmTMBBP90oQjmTeNNQUrUMBh4CMIg5Bxnh7l1bHZn4WvvYQR4prBxgbtE6uFlol 2vhBG/llgPeFr4tPgd355hGhP02FLx7hrDY96LTc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christian Loehle , Sumit Gupta , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.18 081/686] ACPI: CPPC: Accept requests to retain immutable autonomous selection Date: Fri, 13 Nov 2026 10:43:34 -0500 Message-ID: <20261113153823.629703667@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Loehle commit 4bcc60d326c5acaa28c5913259decb22a33a83a1 upstream. ACPI permits Autonomous Selection Enable to be Integer 1 when the platform always selects performance autonomously. cppc_get_auto_sel() returns that value, but cppc_set_auto_sel() rejects the Integer even when asked to keep autonomous selection enabled. AMD shared-memory initialization consequently fails in active or guided mode after successfully reading the capability. Accept a request to keep this immutable field enabled without issuing a register access. Expose the immutable encoding to callers, separately from the current value of a writable register. Before an AMD shared-memory transition to passive mode, reject immutable autonomous selection on any present CPU. Otherwise a guided-to-passive transition ignores the failed disable and reports the wrong mode, while active-to-passive unregisters the working driver before passive policy initialization fails. Check under the driver mode lock before invoking either transition, including known offline CPUs. Serialize this capability query with descriptor publication and removal. ACPI processor removal drops the descriptor before taking the CPU hotplug write lock, so the caller's cpus_read_lock() alone cannot protect the lookup. Unpublish under the same mutex before releasing a descriptor, including when adding its kobject fails. The cppc-cpufreq auto_select attribute can also request one while autonomous selection is already enabled. If the subsequent bounds update fails, its rollback requests zero and clears the cached mode regardless of the previous state. For an immutable field the disable request fails, leaving the cached mode wrong. Save and restore the previous mode instead. This also avoids disabling an already-enabled writable control on that error path. Fixes: c984f5d5d45b ("ACPI: CPPC: Add auto select register read/write support") Fixes: ea3db45ae476 ("cpufreq: cppc: Update MIN_PERF/MAX_PERF in target callbacks") Cc: All applicable Signed-off-by: Christian Loehle Tested-by: Sumit Gupta Link: https://patch.msgid.link/20260916162805.1039247-19-christian.loehle@arm.com Signed-off-by: Rafael J. Wysocki Signed-off-by: Christian Loehle Signed-off-by: Sasha Levin --- drivers/acpi/cppc_acpi.c | 48 ++++++++++++++++++++++++++++++++++-- drivers/cpufreq/amd-pstate.c | 25 +++++++++++++++---- include/acpi/cppc_acpi.h | 6 +++++ 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index a3984e061ce0c..2668004e89ec7 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -93,6 +94,16 @@ static DEFINE_PER_CPU(int, cpu_pcc_subspace_idx); */ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr); +/* Protect immutable capability queries against descriptor removal. */ +static DEFINE_MUTEX(cpc_desc_lock); + +static void cpc_set_desc(unsigned int cpu, struct cpc_desc *desc) +{ + mutex_lock(&cpc_desc_lock); + per_cpu(cpc_desc_ptr, cpu) = desc; + mutex_unlock(&cpc_desc_lock); +} + /* pcc mapped address + header size + offset within PCC subspace */ #define GET_PCC_VADDR(offs, pcc_ss_id) (pcc_data[pcc_ss_id]->pcc_channel->shmem + \ 0x8 + (offs)) @@ -899,12 +910,12 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) } /* Plug PSD data into this CPU's CPC descriptor. */ - per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr; + cpc_set_desc(pr->id, cpc_ptr); ret = kobject_init_and_add(&cpc_ptr->kobj, &cppc_ktype, &cpu_dev->kobj, "acpi_cppc"); if (ret) { - per_cpu(cpc_desc_ptr, pr->id) = NULL; + cpc_set_desc(pr->id, NULL); kobject_put(&cpc_ptr->kobj); goto out_free; } @@ -956,6 +967,8 @@ void acpi_cppc_processor_exit(struct acpi_processor *pr) if (!cpc_ptr) return; + cpc_set_desc(pr->id, NULL); + /* Free all the mapped sys mem areas for this CPU */ for (i = 2; i < cpc_ptr->num_entries; i++) { addr = cpc_ptr->cpc_regs[i-2].sys_mem_vaddr; @@ -1273,6 +1286,11 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val) reg = &cpc_desc->cpc_regs[reg_idx]; + /* Integer 1 describes autonomous selection that is always enabled. */ + if (reg_idx == AUTO_SEL_ENABLE && reg->type == ACPI_TYPE_INTEGER && + reg->cpc_entry.int_value == 1) + return val == 1 ? 0 : -EOPNOTSUPP; + /* if a register is writeable, it must be a buffer and not null */ if ((reg->type != ACPI_TYPE_BUFFER) || IS_NULL_REG(®->cpc_entry.reg)) { pr_debug("CPC register is not supported\n"); @@ -1722,6 +1740,32 @@ int cppc_get_auto_sel(int cpu, bool *enable) } EXPORT_SYMBOL_GPL(cppc_get_auto_sel); +/** + * cppc_auto_sel_is_immutable - Check for always-enabled autonomous selection. + * @cpu: CPU whose _CPC descriptor to check. + * + * Context: Process context. + * Return: true for Integer 1, false for a register or an absent descriptor. + */ +bool cppc_auto_sel_is_immutable(int cpu) +{ + struct cpc_desc *cpc_desc; + struct cpc_register_resource *reg; + bool immutable = false; + + mutex_lock(&cpc_desc_lock); + cpc_desc = per_cpu(cpc_desc_ptr, cpu); + if (cpc_desc) { + reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE]; + immutable = reg->type == ACPI_TYPE_INTEGER && + reg->cpc_entry.int_value == 1; + } + mutex_unlock(&cpc_desc_lock); + + return immutable; +} +EXPORT_SYMBOL_GPL(cppc_auto_sel_is_immutable); + /** * cppc_set_auto_sel - Write autonomous selection register. * @cpu : CPU to which to write register. diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 0b06bbd7215ff..c5047b56be50f 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1653,7 +1653,7 @@ EXPORT_SYMBOL_GPL(amd_pstate_get_status); int amd_pstate_update_status(const char *buf, size_t size) { - int mode_idx; + int cpu, mode_idx, ret = 0; if (size > strlen("passive") || size < strlen("active")) return -EINVAL; @@ -1663,12 +1663,27 @@ int amd_pstate_update_status(const char *buf, size_t size) if (mode_idx < 0 || mode_idx >= AMD_PSTATE_MAX) return -EINVAL; - if (mode_state_machine[cppc_state][mode_idx]) { - guard(mutex)(&amd_pstate_driver_lock); - return mode_state_machine[cppc_state][mode_idx](mode_idx); + guard(mutex)(&amd_pstate_driver_lock); + + if (!mode_state_machine[cppc_state][mode_idx]) + return 0; + + if (mode_idx == AMD_PSTATE_PASSIVE && + !cpu_feature_enabled(X86_FEATURE_CPPC)) { + cpus_read_lock(); + /* Check offline CPUs too, before changing or removing the driver. */ + for_each_present_cpu(cpu) { + if (cppc_auto_sel_is_immutable(cpu)) { + ret = -EOPNOTSUPP; + break; + } + } + cpus_read_unlock(); + if (ret) + return ret; } - return 0; + return mode_state_machine[cppc_state][mode_idx](mode_idx); } EXPORT_SYMBOL_GPL(amd_pstate_update_status); diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 13fa815048445..382a74430e748 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -171,6 +171,7 @@ extern int cppc_set_epp(int cpu, u64 epp_val); extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window); extern int cppc_set_auto_act_window(int cpu, u64 auto_act_window); extern int cppc_get_auto_sel(int cpu, bool *enable); +bool cppc_auto_sel_is_immutable(int cpu); extern int cppc_set_auto_sel(int cpu, bool enable); extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf); extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator); @@ -256,6 +257,11 @@ static inline int cppc_get_auto_sel(int cpu, bool *enable) { return -EOPNOTSUPP; } +static inline bool cppc_auto_sel_is_immutable(int cpu) +{ + return false; +} + static inline int cppc_set_auto_sel(int cpu, bool enable) { return -EOPNOTSUPP; -- 2.53.0