Skip to contentSkip to conversation

xen/cpupool: limit number of cpupools

PATCH In review Juergen Gross 2 participants 2 messages May 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/cpupool: limit number of cpupools

Today the number of cpupools in a system is unlimited. This can lead to multiple problems (e.g. duplicate cpupool-id).

Limit the number of cpupools to twice the number of maximum possible cpus, allowing to have one cpupool per physical cpu plus some spare cpupools for special means (there are already existing use cases for such spare cpupools).

---
 xen/common/sched/cpupool.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
xen/common/sched/cpupool.c +12 -0
index f6e3d97e52..7cc25ee8b4 100644
@@ -30,6 +30,7 @@ struct cpupool *cpupool0;                /* Initial cpupool with Dom0 */
 cpumask_t cpupool_free_cpus;             /* cpus not in any cpupool */
 
 static LIST_HEAD(cpupool_list);          /* linked list, sorted by poolid */
+static unsigned int n_cpupools;
 
 static int cpupool_moving_cpu = -1;
 static struct cpupool *cpupool_cpu_moving = NULL;
@@ -276,6 +277,14 @@ static struct cpupool *cpupool_create(unsigned int poolid,
 
     spin_lock(&cpupool_lock);
 
+    /* Don't allow too many cpupools. */
+    if ( n_cpupools >= 2 * nr_cpu_ids )
+    {
+        ret = -ENOSPC;
+        goto unlock;
+    }
+    n_cpupools++;
+
     if ( poolid != CPUPOOLID_NONE )
     {
         q = __cpupool_find_by_id(poolid, false);
@@ -332,7 +341,9 @@ static struct cpupool *cpupool_create(unsigned int poolid,
 
  err:
     list_del(&c->list);
+    n_cpupools--;
 
+ unlock:
     spin_unlock(&cpupool_lock);
 
     free_cpupool_struct(c);
@@ -356,6 +367,7 @@ static int cpupool_destroy(struct cpupool *c)
         return -EBUSY;
     }
 
+    n_cpupools--;
     list_del(&c->list);
 
     spin_unlock(&cpupool_lock);
Signature · 1 line
2.35.3
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Juergen Gross

Today the number of cpupools in a system is unlimited. This can lead to multiple problems (e.g. duplicate cpupool-id).

Not to mention scalability issues.  Search by ID is O(n).

Quoted 5 lines

Limit the number of cpupools to twice the number of maximum possible cpus, allowing to have one cpupool per physical cpu plus some spare cpupools for special means (there are already existing use cases for such spare cpupools).

Probably one of Suggested-by/Reported-by/Requested-by :)  Dealers choice.

Quoted 1 line

Otherwise, LGTM.