File credit2-vCPUs-pause_flags-must-be-accessed-atomically.patch of Package xen.23583

From 6fae055c111f11274b14b077e1e4d73ea0097048 Mon Sep 17 00:00:00 2001
From: Dario Faggioli <dfaggioli@suse.com>
Date: Mon, 2 Aug 2021 19:41:06 +0200
Subject: [PATCH 3/3] xen: credit2: vCPUs' pause_flags must be accessed
 atomically

The pause_flags field must always be modified atomically, as it is
manupulated (e.g., in schedule.c) without any lock held.

Credit2 code was not doing that, which causes races.

Specifically, we have see cases where the unprotected setting of the
_VPF_migrating flag in csched_credit2:migrate() was racing with the
resetting and testing of the _VPF_blocked flag in
schedule.c:vcpu_unblock() and schedule.c:vcpu_wake(). This caused the
vCPU that was being unblocked to not be put back in the Credit2
runqueue, which then causes other issue.

This unlocked accesses were introduced by ad4b3e1e9df ("xen: credit2:
implement utilization cap") and in 222234f2ad1 ("xen: credit2: use
non-atomic cpumask and bit operations").

Suggested-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
---
 xen/common/sched_credit2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c
index f2ef56395b..8134702e86 100644
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -1786,7 +1786,7 @@ static void park_vcpu(struct csched2_vcpu *svc)
      *
      * In both cases, we also add it to the list of parked vCPUs of the domain.
      */
-    __set_bit(_VPF_parked, &v->pause_flags);
+    set_bit(_VPF_parked, &v->pause_flags);
     if ( vcpu_on_runq(svc) )
     {
         runq_remove(svc);
@@ -1895,7 +1895,7 @@ unpark_parked_vcpus(const struct scheduler *ops, struct list_head *vcpus)
 
         lock = vcpu_schedule_lock_irqsave(svc->vcpu, &flags);
 
-        __clear_bit(_VPF_parked, &svc->vcpu->pause_flags);
+        clear_bit(_VPF_parked, &svc->vcpu->pause_flags);
         if ( unlikely(svc->flags & CSFLAG_scheduled) )
         {
             /*
@@ -2492,7 +2492,7 @@ static void migrate(const struct scheduler *ops,
     {
         /* It's running; mark it to migrate. */
         svc->migrate_rqd = trqd;
-        __set_bit(_VPF_migrating, &svc->vcpu->pause_flags);
+        set_bit(_VPF_migrating, &svc->vcpu->pause_flags);
         __set_bit(__CSFLAG_runq_migrate_request, &svc->flags);
         SCHED_STAT_CRANK(migrate_requested);
         tickle_cpu(cpu, svc->rqd);
-- 
2.32.0

openSUSE Build Service is sponsored by