Skip to contentSkip to conversation

xen/pvhsim: fix cpu onlining

PATCH Superseded Juergen Gross 3 participants 4 messages Oct 23, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/pvhsim: fix cpu onlining

Since commit 8d3c326f6756d1 ("xen: let vcpu_create() select processor") the initial processor for all pv-shim vcpus will be 0, as no other cpus are online when the vcpus are created. Before that commit the vcpus would have processors set not being online yet, which worked just by chance.

When the pv-shim vcpu becomes active it will have a hard affinity not matching its initial processor assignment leading to failing ASSERT()s or other problems depending on the selected scheduler.

Fix that by doing the affinity setting after onlining the cpu but before taking the vcpu up. For vcpu 0 this is still in sched_setup_dom0_vcpus(), for the other vcpus setting the affinity there can be dropped.

Fixes 8d3c326f6756d1 ("xen: let vcpu_create() select processor")
---
 xen/arch/x86/pv/shim.c |  2 ++
 xen/common/schedule.c  | 11 +++++------
 2 files changed, 7 insertions(+), 6 deletions(-)
xen/arch/x86/pv/shim.c +2 -0
index 5edbcd9ac5..4329eaaefe 100644
@@ -837,6 +837,8 @@ long pv_shim_cpu_up(void *data)
                     v->vcpu_id, rc);
             return rc;
         }
+
+        vcpu_set_hard_affinity(v, cpumask_of(v->vcpu_id));
     }
 
     wake = test_and_clear_bit(_VPF_down, &v->pause_flags);
xen/common/schedule.c +5 -6
index c327c40b92..326f4d3601 100644
@@ -3102,13 +3102,12 @@ void __init sched_setup_dom0_vcpus(struct domain *d)
     for ( i = 1; i < d->max_vcpus; i++ )
         vcpu_create(d, i);
 
-    for_each_sched_unit ( d, unit )
+    if ( pv_shim )
+        sched_set_affinity(d->vcpu[0]->sched_unit,
+                           cpumask_of(0), cpumask_of(0));
+    else
     {
-        unsigned int id = unit->unit_id;
-
-        if ( pv_shim )
-            sched_set_affinity(unit, cpumask_of(id), cpumask_of(id));
-        else
+        for_each_sched_unit ( d, unit )
         {
             if ( !opt_dom0_vcpus_pin && !dom0_affinity_relaxed )
                 sched_set_affinity(unit, &dom0_cpus, NULL);
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Juergen Gross

Since commit 8d3c326f6756d1 ("xen: let vcpu_create() select processor") the initial processor for all pv-shim vcpus will be 0, as no other cpus are online when the vcpus are created. Before that commit the vcpus would have processors set not being online yet, which worked just by chance.

When the pv-shim vcpu becomes active it will have a hard affinity not matching its initial processor assignment leading to failing ASSERT()s or other problems depending on the selected scheduler.

Fix that by doing the affinity setting after onlining the cpu but before taking the vcpu up. For vcpu 0 this is still in sched_setup_dom0_vcpus(), for the other vcpus setting the affinity there can be dropped.

Quoted 4 lines
Fixes 8d3c326f6756d1 ("xen: let vcpu_create() select processor")

Thanks.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 16 lines · Roger Pau Monné
Quoted 15 lines · Juergen Gross

Since commit 8d3c326f6756d1 ("xen: let vcpu_create() select processor") the initial processor for all pv-shim vcpus will be 0, as no other cpus are online when the vcpus are created. Before that commit the vcpus would have processors set not being online yet, which worked just by chance.

When the pv-shim vcpu becomes active it will have a hard affinity not matching its initial processor assignment leading to failing ASSERT()s or other problems depending on the selected scheduler.

Fix that by doing the affinity setting after onlining the cpu but before taking the vcpu up. For vcpu 0 this is still in sched_setup_dom0_vcpus(), for the other vcpus setting the affinity there can be dropped.

Quoted 6 lines
Quoted 4 lines
Fixes 8d3c326f6756d1 ("xen: let vcpu_create() select processor")

And just for the protocol:

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#3 lore raw
In reply to Roger Pau Monné
Quoted 16 lines · Roger Pau Monné
Quoted 15 lines · Juergen Gross

Since commit 8d3c326f6756d1 ("xen: let vcpu_create() select processor") the initial processor for all pv-shim vcpus will be 0, as no other cpus are online when the vcpus are created. Before that commit the vcpus would have processors set not being online yet, which worked just by chance.

When the pv-shim vcpu becomes active it will have a hard affinity not matching its initial processor assignment leading to failing ASSERT()s or other problems depending on the selected scheduler.

Fix that by doing the affinity setting after onlining the cpu but before taking the vcpu up. For vcpu 0 this is still in sched_setup_dom0_vcpus(), for the other vcpus setting the affinity there can be dropped.

Quoted 6 lines
Quoted 4 lines
Fixes 8d3c326f6756d1 ("xen: let vcpu_create() select processor")

I have to admit though that I miss a comment on the pv_shim conditional in schedule.c - such a special case shouldn't really be there, but since it's needed it should be explained. I realize though that the patch here only moves the special case, i.e. the lack of comment is pre-existing.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel