Skip to contentSkip to conversation

xen/sched: fix restore_vcpu_affinity() by removing it

PATCH-for-4.17 Juergen Gross 5 participants 7 messages Oct 21, 2022

lore
Share & tools
lore
#0 lore raw

When the system is coming up after having been suspended, restore_vcpu_affinity() is called for each domain in order to adjust the vcpu's affinity settings in case a cpu didn't come to live again.

The way restore_vcpu_affinity() is doing that is wrong, because the specific scheduler isn't being informed about a possible migration of the vcpu to another cpu. Additionally the migration is often even happening if all cpus are running again, as it is done without check whether it is really needed.

As cpupool management is already calling cpu_disable_scheduler() for cpus not having come up again, and cpu_disable_scheduler() is taking care of eventually needed vcpu migration in the proper way, there is simply no need for restore_vcpu_affinity().

So just remove restore_vcpu_affinity() completely.

Fixes 8a5d50dd0b04 ("xen: sched: simplify ACPI S3 resume path.")
---
 xen/arch/x86/acpi/power.c |  3 --
 xen/common/sched/core.c   | 70 ---------------------------------------
 xen/include/xen/sched.h   |  1 -
 3 files changed, 74 deletions(-)
xen/arch/x86/acpi/power.c +0 -3
index 1bb4d78392..b76f673acb 100644
@@ -159,10 +159,7 @@ static void thaw_domains(void)
 
     rcu_read_lock(&domlist_read_lock);
     for_each_domain ( d )
-    {
-        restore_vcpu_affinity(d);
         domain_unpause(d);
-    }
     rcu_read_unlock(&domlist_read_lock);
 }
 
xen/common/sched/core.c +0 -70

76 lines not on this page · raw message

xen/include/xen/sched.h +0 -1
index 557b3229f6..072e4846aa 100644
@@ -1019,7 +1019,6 @@ void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value);
 void sched_setup_dom0_vcpus(struct domain *d);
 int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reason);
 int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity);
-void restore_vcpu_affinity(struct domain *d);
 int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
                          struct xen_domctl_vcpuaffinity *vcpuaff);
 
Signature · 1 line
2.35.3
#1 lore raw
Quoted 10 lines · Juergen Gross

When the system is coming up after having been suspended, restore_vcpu_affinity() is called for each domain in order to adjust the vcpu's affinity settings in case a cpu didn't come to live again.

The way restore_vcpu_affinity() is doing that is wrong, because the specific scheduler isn't being informed about a possible migration of the vcpu to another cpu. Additionally the migration is often even happening if all cpus are running again, as it is done without check whether it is really needed.

Quoted 8 lines

As cpupool management is already calling cpu_disable_scheduler() for cpus not having come up again, and cpu_disable_scheduler() is taking care of eventually needed vcpu migration in the proper way, there is simply no need for restore_vcpu_affinity().

So just remove restore_vcpu_affinity() completely.

Fixes 8a5d50dd0b04 ("xen: sched: simplify ACPI S3 resume path.")

This Fixes: tag is wrong. It should be:

Fixes 8a04eaa8ea83 ("xen/sched: move some per-vcpu items to struct sched_unit")

Juergen

#2 lore raw
Quoted 23 lines · Juergen Gross
Quoted 22 lines · Juergen Gross

When the system is coming up after having been suspended, restore_vcpu_affinity() is called for each domain in order to adjust
the vcpu's affinity settings in case a cpu didn't come to live again.

The way restore_vcpu_affinity() is doing that is wrong, because the specific scheduler isn't being informed about a possible migration of
the vcpu to another cpu. Additionally the migration is often even happening if all cpus are running again, as it is done without check
whether it is really needed.

As cpupool management is already calling cpu_disable_scheduler() for
cpus not having come up again, and cpu_disable_scheduler() is taking
care of eventually needed vcpu migration in the proper way, there is
simply no need for restore_vcpu_affinity().

Quoted 9 lines
Quoted 3 lines

So just remove restore_vcpu_affinity() completely.

Fixes 8a5d50dd0b04 ("xen: sched: simplify ACPI S3 resume path.")

This Fixes: tag is wrong. It should be:

Fixes 8a04eaa8ea83 ("xen/sched: move some per-vcpu items to struct

sched_unit")

Thanks and 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)
#3 lore raw
In reply to Juergen Gross

Hi Juergen,

Quoted 20 lines

-----Original Message-----
From: Juergen Gross <[email protected]>
Subject: [PATCH-for-4.17] xen/sched: fix restore_vcpu_affinity() by removing it

When the system is coming up after having been suspended, restore_vcpu_affinity() is called for each domain in order to adjust the vcpu's affinity settings in case a cpu didn't come to live again.

The way restore_vcpu_affinity() is doing that is wrong, because the specific scheduler isn't being informed about a possible migration of the vcpu to another cpu. Additionally the migration is often even happening if all cpus are running again, as it is done without check whether it is really needed.

As cpupool management is already calling cpu_disable_scheduler() for cpus not having come up again, and cpu_disable_scheduler() is taking care of eventually needed vcpu migration in the proper way, there is simply no need for restore_vcpu_affinity().

Quoted 6 lines

So just remove restore_vcpu_affinity() completely.

Fixes 8a5d50dd0b04 ("xen: sched: simplify ACPI S3 resume path.")
Reported-by Marek Marczykowski-Górecki

<[email protected]>

Kind regards,
Henry

#4 lore raw
In reply to Juergen Gross

xen/common/sched/core.c static void sched_reset_affinity_broken(const struct sched_unit *unit) · line 1197

Quoted 5 lines · Juergen Gross
xen/common/sched/core.c +0 -0
@@ -1196,76 +1196,6 @@ static void sched_reset_affinity_broken(const struct sched_unit *unit)
         v->affinity_broken = false;
 }

My pre-push build test failed because the function above ...

Quoted 25 lines
xen/common/sched/core.c +0 -25
-void restore_vcpu_affinity(struct domain *d)
-{
-    unsigned int cpu = smp_processor_id();
-    struct sched_unit *unit;
-
-    ASSERT(system_state == SYS_STATE_resume);
-
-    rcu_read_lock(&sched_res_rculock);
-
-    for_each_sched_unit ( d, unit )
-    {
-        spinlock_t *lock;
-        unsigned int old_cpu = sched_unit_master(unit);
-        struct sched_resource *res;
-
-        ASSERT(!unit_runnable(unit));
-
-        /*
-         * Re-assign the initial processor as after resume we have no
-         * guarantee the old processor has come back to life again.
-         *
-         * Therefore, here, before actually unpausing the domains, we should
-         * set v->processor of each of their vCPUs to something that will
-         * make sense for the scheduler of the cpupool in which they are in.
-         */

xen/common/sched/core.c static void sched_reset_affinity_broken(const struct sched_unit *unit) · line 1233

Quoted 10 lines
xen/common/sched/core.c +0 -10
-        lock = unit_schedule_lock_irq(unit);
-
-        cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
-                    cpupool_domain_master_cpumask(d));
-        if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
-        {
-            if ( sched_check_affinity_broken(unit) )
-            {
-                sched_set_affinity(unit, unit->cpu_hard_affinity_saved, NULL);
-                sched_reset_affinity_broken(unit);

... has its only use removed here. It didn't seem appropriate for me to go and silently remove that function as well.

Jan

Quoted 50 lines
xen/common/sched/core.c +0 -35
-                cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
-                            cpupool_domain_master_cpumask(d));
-            }
-
-            if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
-            {
-                /* Affinity settings of one vcpu are for the complete unit. */
-                printk(XENLOG_DEBUG "Breaking affinity for %pv\n",
-                       unit->vcpu_list);
-                sched_set_affinity(unit, &cpumask_all, NULL);
-                cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
-                            cpupool_domain_master_cpumask(d));
-            }
-        }
-
-        res = get_sched_res(cpumask_any(cpumask_scratch_cpu(cpu)));
-        sched_set_res(unit, res);
-
-        spin_unlock_irq(lock);
-
-        /* v->processor might have changed, so reacquire the lock. */
-        lock = unit_schedule_lock_irq(unit);
-        res = sched_pick_resource(unit_scheduler(unit), unit);
-        sched_set_res(unit, res);
-        spin_unlock_irq(lock);
-
-        if ( old_cpu != sched_unit_master(unit) )
-            sched_move_irqs(unit);
-    }
-
-    rcu_read_unlock(&sched_res_rculock);
-
-    domain_update_node_affinity(d);
-}
-
 /*
  * This function is used by cpu_hotplug code via cpu notifier chain
  * and from cpupools to switch schedulers on a cpu.
xen/include/xen/sched.h +0 -1
index 557b3229f6..072e4846aa 100644
@@ -1019,7 +1019,6 @@ void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value);
 void sched_setup_dom0_vcpus(struct domain *d);
 int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reason);
 int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity);
-void restore_vcpu_affinity(struct domain *d);
 int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
                          struct xen_domctl_vcpuaffinity *vcpuaff);
 
#5 lore raw
Quoted 39 lines · Jan Beulich

xen/common/sched/core.c static void sched_reset_affinity_broken(const struct sched_unit *unit) · line 1197

Quoted 5 lines · Juergen Gross
xen/common/sched/core.c +0 -0
@@ -1196,76 +1196,6 @@ static void sched_reset_affinity_broken(const struct sched_unit *unit)
          v->affinity_broken = false;
  }

My pre-push build test failed because the function above ...

Quoted 30 lines
xen/common/sched/core.c +0 -30
-void restore_vcpu_affinity(struct domain *d)
-{
-    unsigned int cpu = smp_processor_id();
-    struct sched_unit *unit;
-
-    ASSERT(system_state == SYS_STATE_resume);
-
-    rcu_read_lock(&sched_res_rculock);
-
-    for_each_sched_unit ( d, unit )
-    {
-        spinlock_t *lock;
-        unsigned int old_cpu = sched_unit_master(unit);
-        struct sched_resource *res;
-
-        ASSERT(!unit_runnable(unit));
-
-        /*
-         * Re-assign the initial processor as after resume we have no
-         * guarantee the old processor has come back to life again.
-         *
-         * Therefore, here, before actually unpausing the domains, we should
-         * set v->processor of each of their vCPUs to something that will
-         * make sense for the scheduler of the cpupool in which they are in.
-         */
-        lock = unit_schedule_lock_irq(unit);
-
-        cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
-                    cpupool_domain_master_cpumask(d));
-        if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
Quoted 8 lines

xen/common/sched/core.c static void sched_reset_affinity_broken(const struct sched_unit *unit) · line 1233

Quoted 5 lines
xen/common/sched/core.c +0 -5
-        {
-            if ( sched_check_affinity_broken(unit) )
-            {
-                sched_set_affinity(unit, unit->cpu_hard_affinity_saved, NULL);
-                sched_reset_affinity_broken(unit);

... has its only use removed here. It didn't seem appropriate for me to go and silently remove that function as well.

Weird I didn't spot that.

I'll update the patch.

Juergen

#6 lore raw
In reply to Juergen Gross
Quoted 15 lines · Juergen Gross

When the system is coming up after having been suspended, restore_vcpu_affinity() is called for each domain in order to adjust the vcpu's affinity settings in case a cpu didn't come to live again.

The way restore_vcpu_affinity() is doing that is wrong, because the specific scheduler isn't being informed about a possible migration of the vcpu to another cpu. Additionally the migration is often even happening if all cpus are running again, as it is done without check whether it is really needed.

As cpupool management is already calling cpu_disable_scheduler() for cpus not having come up again, and cpu_disable_scheduler() is taking care of eventually needed vcpu migration in the proper way, there is simply no need for restore_vcpu_affinity().

Quoted 5 lines

So just remove restore_vcpu_affinity() completely.

Fixes 8a5d50dd0b04 ("xen: sched: simplify ACPI S3 resume path.")

I can only test it on a different configuration right now, but I can confirm with this patch applied the system survives S3 (and it did crashed without it at least once on this config).

With the now-unused function (also noticed by Jan) dealt with, you can add my:

Quoted 117 lines
---
 xen/arch/x86/acpi/power.c |  3 --
 xen/common/sched/core.c   | 70 ---------------------------------------
 xen/include/xen/sched.h   |  1 -
 3 files changed, 74 deletions(-)
xen/arch/x86/acpi/power.c +0 -3
index 1bb4d78392..b76f673acb 100644
@@ -159,10 +159,7 @@ static void thaw_domains(void)
 
     rcu_read_lock(&domlist_read_lock);
     for_each_domain ( d )
-    {
-        restore_vcpu_affinity(d);
         domain_unpause(d);
-    }
     rcu_read_unlock(&domlist_read_lock);
 }
 
xen/common/sched/core.c +0 -70
index 83455fbde1..358fa077e3 100644
@@ -1196,76 +1196,6 @@ static void sched_reset_affinity_broken(const struct sched_unit *unit)
         v->affinity_broken = false;
 }
 
-void restore_vcpu_affinity(struct domain *d)
-{
-    unsigned int cpu = smp_processor_id();
-    struct sched_unit *unit;
-
-    ASSERT(system_state == SYS_STATE_resume);
-
-    rcu_read_lock(&sched_res_rculock);
-
-    for_each_sched_unit ( d, unit )
-    {
-        spinlock_t *lock;
-        unsigned int old_cpu = sched_unit_master(unit);
-        struct sched_resource *res;
-
-        ASSERT(!unit_runnable(unit));
-
-        /*
-         * Re-assign the initial processor as after resume we have no
-         * guarantee the old processor has come back to life again.
-         *
-         * Therefore, here, before actually unpausing the domains, we should
-         * set v->processor of each of their vCPUs to something that will
-         * make sense for the scheduler of the cpupool in which they are in.
-         */
-        lock = unit_schedule_lock_irq(unit);
-
-        cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
-                    cpupool_domain_master_cpumask(d));
-        if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
-        {
-            if ( sched_check_affinity_broken(unit) )
-            {
-                sched_set_affinity(unit, unit->cpu_hard_affinity_saved, NULL);
-                sched_reset_affinity_broken(unit);
-                cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
-                            cpupool_domain_master_cpumask(d));
-            }
-
-            if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
-            {
-                /* Affinity settings of one vcpu are for the complete unit. */
-                printk(XENLOG_DEBUG "Breaking affinity for %pv\n",
-                       unit->vcpu_list);
-                sched_set_affinity(unit, &cpumask_all, NULL);
-                cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
-                            cpupool_domain_master_cpumask(d));
-            }
-        }
-
-        res = get_sched_res(cpumask_any(cpumask_scratch_cpu(cpu)));
-        sched_set_res(unit, res);
-
-        spin_unlock_irq(lock);
-
-        /* v->processor might have changed, so reacquire the lock. */
-        lock = unit_schedule_lock_irq(unit);
-        res = sched_pick_resource(unit_scheduler(unit), unit);
-        sched_set_res(unit, res);
-        spin_unlock_irq(lock);
-
-        if ( old_cpu != sched_unit_master(unit) )
-            sched_move_irqs(unit);
-    }
-
-    rcu_read_unlock(&sched_res_rculock);
-
-    domain_update_node_affinity(d);
-}
-
 /*
  * This function is used by cpu_hotplug code via cpu notifier chain
  * and from cpupools to switch schedulers on a cpu.
xen/include/xen/sched.h +0 -1
index 557b3229f6..072e4846aa 100644
@@ -1019,7 +1019,6 @@ void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value);
 void sched_setup_dom0_vcpus(struct domain *d);
 int vcpu_temporary_affinity(struct vcpu *v, unsigned int cpu, uint8_t reason);
 int vcpu_set_hard_affinity(struct vcpu *v, const cpumask_t *affinity);
-void restore_vcpu_affinity(struct domain *d);
 int vcpu_affinity_domctl(struct domain *d, uint32_t cmd,
                          struct xen_domctl_vcpuaffinity *vcpuaff);
 
Signature · 1 line
2.35.3
Signature · 3 lines
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab