xen/locking: harmonize spinlocks and rwlocks regarding preemption
authorJuergen Gross <jgross@suse.com>
Fri, 6 Nov 2020 09:47:09 +0000 (10:47 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 6 Nov 2020 09:47:09 +0000 (10:47 +0100)
Spinlocks and rwlocks behave differently in the try variants regarding
preemption: rwlocks are switching preemption off before testing the
lock, while spinlocks do so only after the first check.

Modify _spin_trylock() to disable preemption before testing the lock
to be held in order to be preemption-ready.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
xen/common/spinlock.c

index b4aaf6bce6e33b5056f21b49a38b27eb9b0b97e0..f4eb50f030088ed8c8677aa723029371820b84f1 100644 (file)
@@ -240,13 +240,16 @@ int _spin_trylock(spinlock_t *lock)
 {
     spinlock_tickets_t old, new;
 
+    preempt_disable();
     check_lock(&lock->debug, true);
     old = observe_lock(&lock->tickets);
     if ( old.head != old.tail )
+    {
+        preempt_enable();
         return 0;
+    }
     new = old;
     new.tail++;
-    preempt_disable();
     if ( cmpxchg(&lock->tickets.head_tail,
                  old.head_tail, new.head_tail) != old.head_tail )
     {