[PATCH V2 03/15] power/acpi_cpufreq: validate lcore role in cpufreq API
Huisong Li
lihuisong at huawei.com
Thu May 7 04:42:18 CEST 2026
Currently, the acpi_cpufreq 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 at huawei.com>
---
drivers/power/acpi/acpi_cpufreq.c | 56 +++++++++++++++----------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index 81a5e3f6ea..155b30fcf7 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -242,9 +242,8 @@ power_acpi_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;
}
@@ -319,11 +318,11 @@ power_acpi_cpufreq_exit(unsigned int lcore_id)
struct acpi_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
@@ -373,8 +372,8 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
{
struct acpi_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;
}
@@ -396,8 +395,8 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
uint32_t
power_acpi_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;
}
@@ -407,8 +406,8 @@ power_acpi_cpufreq_get_freq(unsigned int lcore_id)
int
power_acpi_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;
}
@@ -420,8 +419,8 @@ power_acpi_cpufreq_freq_down(unsigned int lcore_id)
{
struct acpi_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;
}
@@ -438,8 +437,8 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
{
struct acpi_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;
}
@@ -455,8 +454,8 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
int
power_acpi_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;
}
@@ -479,8 +478,8 @@ power_acpi_cpufreq_freq_min(unsigned int lcore_id)
{
struct acpi_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;
}
@@ -496,8 +495,8 @@ power_acpi_turbo_status(unsigned int lcore_id)
{
struct acpi_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;
}
@@ -512,8 +511,8 @@ power_acpi_enable_turbo(unsigned int lcore_id)
{
struct acpi_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;
}
@@ -545,8 +544,8 @@ power_acpi_disable_turbo(unsigned int lcore_id)
{
struct acpi_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;
}
@@ -572,10 +571,11 @@ int power_acpi_get_capabilities(unsigned int lcore_id,
{
struct acpi_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
More information about the dev
mailing list