[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/cpufreq: allocate processor_pminfo[] dynamically


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 3 Nov 2026 13:53:55 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:Autocrypt:Subject:From:Cc:To:Content-Language:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Tue, 03 Nov 2026 12:54:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

There's no need to have a NR_CPUS-dimensioned static array there.

As ordering of pre-SMP initcalls isn't well-defined, allocate the array
from both cpufreq_presmp_init() and cpufreq_register_driver().

Alongside adding a few NULL checks, drop a redundant one from
get_cpufreq_para().

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/drivers/acpi/pm-op.c
+++ b/xen/drivers/acpi/pm-op.c
@@ -104,8 +104,7 @@ static int get_cpufreq_para(struct xen_s
     pmpt = processor_pminfo[op->cpuid];
     policy = per_cpu(cpufreq_cpu_policy, op->cpuid);
 
-    if ( !pmpt ||
-         ((pmpt->init & XEN_PX_INIT) && !pmpt->perf.states) ||
+    if ( ((pmpt->init & XEN_PX_INIT) && !pmpt->perf.states) ||
          /* Avoid NULL deref of pmpt->perf.states[] */
          ((pmpt->init & XEN_CPPC_INIT) && pmpt->perf.state_count) ||
          !policy || !policy->governor )
@@ -369,7 +368,7 @@ int do_pm_op(struct xen_sysctl_pm_op *op
 
     if ( op->cpuid >= nr_cpu_ids || !cpu_online(op->cpuid) )
         return -EINVAL;
-    pmpt = processor_pminfo[op->cpuid];
+    pmpt = processor_pminfo ? processor_pminfo[op->cpuid] : NULL;
 
     switch ( op->cmd & PM_PARA_CATEGORY_MASK )
     {
--- a/xen/drivers/acpi/pmstat.c
+++ b/xen/drivers/acpi/pmstat.c
@@ -227,7 +227,7 @@ int do_get_pm_info(struct xen_sysctl_get
 
     if ( !op || (op->cpuid >= nr_cpu_ids) || !cpu_online(op->cpuid) )
         return -EINVAL;
-    pmpt = processor_pminfo[op->cpuid];
+    pmpt = processor_pminfo ? processor_pminfo[op->cpuid] : NULL;
 
     switch ( op->type & PMSTAT_CATEGORY_MASK )
     {
--- a/xen/drivers/cpufreq/cpufreq.c
+++ b/xen/drivers/cpufreq/cpufreq.c
@@ -218,7 +218,7 @@ int cpufreq_limit_change(unsigned int cp
     struct cpufreq_policy policy;
 
     if (!cpu_online(cpu) || !(data = per_cpu(cpufreq_cpu_policy, cpu)) ||
-        !processor_pminfo[cpu])
+        !processor_pminfo || !processor_pminfo[cpu])
         return -ENODEV;
 
     perf = &processor_pminfo[cpu]->perf;
@@ -273,7 +273,7 @@ int cpufreq_add_cpu(unsigned int cpu)
     unsigned int shared_type;
 
     /* to protect the case when Px was not controlled by xen */
-    if ( !processor_pminfo[cpu] || !cpu_online(cpu) )
+    if ( !processor_pminfo || !processor_pminfo[cpu] || !cpu_online(cpu) )
         return -EINVAL;
 
     if ( !(processor_pminfo[cpu]->init & (XEN_PX_INIT | XEN_CPPC_INIT)) )
@@ -448,7 +448,7 @@ int cpufreq_del_cpu(unsigned int cpu)
     const struct xen_psd_package *domain_info;
 
     /* to protect the case when Px was not controlled by xen */
-    if ( !processor_pminfo[cpu] || !cpu_online(cpu) )
+    if ( !processor_pminfo || !processor_pminfo[cpu] || !cpu_online(cpu) )
         return -EINVAL;
 
     if ( !(processor_pminfo[cpu]->init & (XEN_PX_INIT | XEN_CPPC_INIT)) )
@@ -563,6 +563,9 @@ int set_px_pminfo(uint32_t acpi_id, stru
     struct processor_pminfo *pmpt;
     struct processor_performance *pxpt;
 
+    if ( !processor_pminfo )
+        return -ENOMEM;
+
     cpu = get_cpu_id(acpi_id);
     if ( cpu < 0 || !perf )
     {
@@ -726,6 +729,9 @@ int set_cppc_pminfo(unsigned int acpi_id
     int ret = 0, cpu_id;
     struct processor_pminfo *pm_info;
 
+    if ( !processor_pminfo )
+        return -ENOMEM;
+
     cpu_id = get_cpu_id(acpi_id);
     if ( cpu_id < 0 )
     {
@@ -947,6 +953,11 @@ static struct notifier_block cpu_nfb = {
 
 static int __init cf_check cpufreq_presmp_init(void)
 {
+    if ( !processor_pminfo )
+        processor_pminfo = xvzalloc_array(struct processor_pminfo *, 
nr_cpu_ids);
+    if ( !processor_pminfo )
+        return -ENOMEM;
+
     register_cpu_notifier(&cpu_nfb);
     return 0;
 }
@@ -954,6 +965,11 @@ presmp_initcall(cpufreq_presmp_init);
 
 int __init cpufreq_register_driver(const struct cpufreq_driver *driver_data)
 {
+    if ( !processor_pminfo )
+        processor_pminfo = xvzalloc_array(struct processor_pminfo *, 
nr_cpu_ids);
+    if ( !processor_pminfo )
+        return -ENOMEM;
+
    if ( !driver_data || !driver_data->init ||
         !driver_data->verify || !driver_data->exit ||
         (!driver_data->target == !driver_data->setpolicy) )
--- a/xen/drivers/cpufreq/utility.c
+++ b/xen/drivers/cpufreq/utility.c
@@ -32,7 +32,7 @@
 #include <public/sysctl.h>
 
 struct cpufreq_driver __read_mostly cpufreq_driver;
-struct processor_pminfo *__read_mostly processor_pminfo[NR_CPUS];
+struct processor_pminfo **__read_mostly processor_pminfo;
 DEFINE_PER_CPU_READ_MOSTLY(struct cpufreq_policy *, cpufreq_cpu_policy);
 
 /*********************************************************************
--- a/xen/include/acpi/cpufreq/processor_perf.h
+++ b/xen/include/acpi/cpufreq/processor_perf.h
@@ -59,7 +59,7 @@ struct processor_pminfo {
     uint32_t init;
 };
 
-extern struct processor_pminfo *processor_pminfo[NR_CPUS];
+extern struct processor_pminfo **processor_pminfo;
 
 struct px_stat {
     uint8_t total;        /* total Px states */



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.