Skip to contentSkip to conversation

xen/sched: fix sched_move_domain() for domain without vcpus

PATCH In review Juergen Gross 3 participants 3 messages Sep 8, 2021 – Sep 15, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/sched: fix sched_move_domain() for domain without vcpus

In case a domain is created with a cpupool other than Pool-0 specified it will be moved to that cpupool before any vcpus are allocated.

This will lead to a NULL pointer dereference in sched_move_domain().

Fix that by tolerating vcpus not being allocated yet.

Fixes 70fadc41635b9b6 ("xen/cpupool: support moving domain between cpupools with different granularity")

---
V2:
- Only test for vcpu[0] not being present (Jan Beulich)

---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
index 8d178baf3d..8f4b1ca10d 100644
@@ -651,7 +651,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
     struct scheduler *old_ops = dom_scheduler(d);
     void *old_domdata;
     unsigned int gran = cpupool_get_granularity(c);
-    unsigned int n_units = DIV_ROUND_UP(d->max_vcpus, gran);
+    unsigned int n_units = d->vcpu[0] ? DIV_ROUND_UP(d->max_vcpus, gran) : 0;
     int ret = 0;
 
     for_each_vcpu ( d, v )
Signature · 1 line
2.26.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Juergen Gross

In case a domain is created with a cpupool other than Pool-0 specified
it will be moved to that cpupool before any vcpus are allocated.

Quoted 9 lines

This will lead to a NULL pointer dereference in sched_move_domain().

Fix that by tolerating vcpus not being allocated yet.

Fixes 70fadc41635b9b6 ("xen/cpupool: support moving domain between

cpupools with different granularity")

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Juergen Gross
Quoted 7 lines · Juergen Gross

In case a domain is created with a cpupool other than Pool-0 specified it will be moved to that cpupool before any vcpus are allocated.

Quoted 7 lines

This will lead to a NULL pointer dereference in sched_move_domain().

Fix that by tolerating vcpus not being allocated yet.

Fixes 70fadc41635b9b6 ("xen/cpupool: support moving domain between cpupools with different granularity")
Quoted 24 lines

---
V2:
- Only test for vcpu[0] not being present (Jan Beulich)
---
xen/common/sched/core.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
index 8d178baf3d..8f4b1ca10d 100644
@@ -651,7 +651,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
    struct scheduler *old_ops = dom_scheduler(d);
    void *old_domdata;
    unsigned int gran = cpupool_get_granularity(c);
-    unsigned int n_units = DIV_ROUND_UP(d->max_vcpus, gran);
+    unsigned int n_units = d->vcpu[0] ? DIV_ROUND_UP(d->max_vcpus, gran) : 0;
    int ret = 0;
 
    for_each_vcpu ( d, v )
Signature · 1 line
2.26.2