[PATCH V2 02/15] power/kvm_vm: validate lcore role in cpufreq API
Huisong Li
lihuisong at huawei.com
Thu May 7 04:42:17 CEST 2026
Currently, the kvm_vm 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/kvm_vm/kvm_vm.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/power/kvm_vm/kvm_vm.c b/drivers/power/kvm_vm/kvm_vm.c
index 5754a441cd..133d1f0882 100644
--- a/drivers/power/kvm_vm/kvm_vm.c
+++ b/drivers/power/kvm_vm/kvm_vm.c
@@ -24,11 +24,11 @@ power_kvm_vm_check_supported(void)
int
power_kvm_vm_init(unsigned int lcore_id)
{
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Core(%u) is out of range 0...%d",
- lcore_id, RTE_MAX_LCORE-1);
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
+
pkt[lcore_id].command = RTE_POWER_CPU_POWER;
pkt[lcore_id].resource_id = lcore_id;
return guest_channel_host_connect(FD_PATH, lcore_id);
@@ -73,11 +73,11 @@ send_msg(unsigned int lcore_id, uint32_t scale_direction)
{
int ret;
- if (lcore_id >= RTE_MAX_LCORE) {
- POWER_LOG(ERR, "Core(%u) is out of range 0...%d",
- lcore_id, RTE_MAX_LCORE-1);
+ if (!rte_lcore_is_eal_managed(lcore_id)) {
+ POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
return -1;
}
+
pkt[lcore_id].unit = scale_direction;
ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
if (ret == 0)
--
2.33.0
More information about the dev
mailing list