From: Huisong Li <lihuisong@huawei.com>
To: <anatoly.burakov@intel.com>, <sivaprasad.tummala@amd.com>,
<stephen@networkplumber.org>
Cc: <dev@dpdk.org>, <thomas@monjalon.net>, <fengchengwen@huawei.com>,
<yangxingui@huawei.com>, <zhanjie9@hisilicon.com>,
<lihuisong@huawei.com>
Subject: [PATCH V2 04/15] power/amd_pstate: validate lcore role in cpufreq API
Date: Thu, 7 May 2026 10:42:19 +0800 [thread overview]
Message-ID: <20260507024230.1198111-5-lihuisong@huawei.com> (raw)
In-Reply-To: <20260507024230.1198111-1-lihuisong@huawei.com>
Currently, the amd_pstate driver only checks if the lcore_id is
within the RTE_MAX_LCORE range, but fails to verify if the core
is actually active or managed by the application. This lacks
sufficient validation.
This patch add a lcore role check to the cpufreq-related APIs.
Although service cores do not typically invoke these APIs, they may
operate in polling states where power management is required.
To maintain compatibility with applications using service cores, the
validation logic now explicitly allows both ROLE_RTE and ROLE_SERVICE.
Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
drivers/power/amd_pstate/amd_pstate_cpufreq.c | 56 +++++++++----------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index 95495bff7d..bca148dc8d 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -360,9 +360,8 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
return -1;
}
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
- lcore_id, RTE_MAX_LCORE - 1U);
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -443,11 +442,11 @@ power_amd_pstate_cpufreq_exit(unsigned int lcore_id)
struct amd_pstate_power_info *pi;
uint32_t exp_state;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
- lcore_id, RTE_MAX_LCORE - 1U);
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
+
pi = &lcore_power_info[lcore_id];
exp_state = POWER_USED;
/* The power in use state works as a guard variable between
@@ -493,8 +492,8 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return 0;
}
@@ -516,8 +515,8 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
uint32_t
power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
{
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return RTE_POWER_INVALID_FREQ_INDEX;
}
@@ -527,8 +526,8 @@ power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
int
power_amd_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
{
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -540,8 +539,8 @@ power_amd_pstate_cpufreq_freq_down(unsigned int lcore_id)
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -558,8 +557,8 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -575,8 +574,8 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
int
power_amd_pstate_cpufreq_freq_max(unsigned int lcore_id)
{
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -600,8 +599,8 @@ power_amd_pstate_cpufreq_freq_min(unsigned int lcore_id)
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -616,8 +615,8 @@ power_amd_pstate_turbo_status(unsigned int lcore_id)
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -631,8 +630,8 @@ power_amd_pstate_enable_turbo(unsigned int lcore_id)
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -667,8 +666,8 @@ power_amd_pstate_disable_turbo(unsigned int lcore_id)
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
@@ -695,10 +694,11 @@ power_amd_pstate_get_capabilities(unsigned int lcore_id,
{
struct amd_pstate_power_info *pi;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Invalid lcore ID");
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
+
if (caps == NULL) {
POWER_LOG(ERR, "Invalid argument");
return -1;
--
2.33.0
next prev parent reply other threads:[~2026-05-07 2:43 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-16 3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
2026-04-16 3:05 ` [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check Huisong Li
2026-04-16 15:48 ` Stephen Hemminger
2026-04-17 2:51 ` lihuisong (C)
2026-04-21 11:07 ` lihuisong (C)
2026-04-21 14:23 ` Stephen Hemminger
2026-04-22 9:18 ` lihuisong (C)
2026-04-16 3:05 ` [PATCH v1 02/15] power/acpi_cpufreq: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 03/15] power/amd_pstate: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 04/15] power/cppc_cpufreq: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 05/15] power/intel_pstate: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 06/15] power: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 07/15] power: add a common macro to verify lcore ID Huisong Li
2026-04-16 3:06 ` [PATCH v1 08/15] power/pmd_mgmt: replace lcore ID verification with new macro Huisong Li
2026-04-16 3:06 ` [PATCH v1 09/15] power/qos: replace the " Huisong Li
2026-04-16 3:06 ` [PATCH v1 10/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
2026-04-16 3:06 ` [PATCH v1 11/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
2026-04-16 3:06 ` [PATCH v1 12/15] power/amd_pstate: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 13/15] power/cppc_cpufreq: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 14/15] power/intel_pstate: " Huisong Li
2026-04-16 3:06 ` [PATCH v1 15/15] power/kvm_vm: " Huisong Li
2026-04-16 15:51 ` [PATCH v1 00/15] power: unify and improve lcore ID verification Stephen Hemminger
2026-04-17 2:53 ` lihuisong (C)
2026-05-07 2:42 ` [PATCH V2 " Huisong Li
2026-05-07 2:42 ` [PATCH V2 01/15] eal: add interface to check if lcore is EAL managed Huisong Li
2026-05-07 2:42 ` [PATCH V2 02/15] power/kvm_vm: validate lcore role in cpufreq API Huisong Li
2026-05-07 2:42 ` [PATCH V2 03/15] power/acpi_cpufreq: " Huisong Li
2026-05-07 2:42 ` Huisong Li [this message]
2026-05-07 2:42 ` [PATCH V2 05/15] power/cppc_cpufreq: " Huisong Li
2026-05-07 2:42 ` [PATCH V2 06/15] power/intel_pstate: " Huisong Li
2026-05-07 2:42 ` [PATCH V2 07/15] power: add a common macro to verify lcore ID Huisong Li
2026-05-07 2:42 ` [PATCH V2 08/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
2026-05-07 2:42 ` [PATCH V2 09/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
2026-05-07 2:42 ` [PATCH V2 10/15] power/amd_pstate: " Huisong Li
2026-05-07 2:42 ` [PATCH V2 11/15] power/cppc_cpufreq: " Huisong Li
2026-05-07 2:42 ` [PATCH V2 12/15] power/intel_pstate: " Huisong Li
2026-05-07 2:42 ` [PATCH V2 13/15] power/kvm_vm: " Huisong Li
2026-05-07 2:42 ` [PATCH V2 14/15] power: allow the service core to config power QoS Huisong Li
2026-05-07 2:42 ` [PATCH V2 15/15] power: add lcore ID check for PMD mgmt Huisong Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260507024230.1198111-5-lihuisong@huawei.com \
--to=lihuisong@huawei.com \
--cc=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
--cc=sivaprasad.tummala@amd.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
--cc=yangxingui@huawei.com \
--cc=zhanjie9@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox