AB-BA deadlock between uidhash_lock and tasklist_lock.
PATCH 1/1 AB-BA deadlock between uidhash_lock and tasklist_lock.
We have uncovered a very difficult to trip AB-BA deadlock between the uidhash_lock and tasklist_lock.
reparent_to_init() does write_lock_irq(&tasklist_lock) then calls switch_uid() which calls free_uid() which grabs the uidhash_lock.
Independent of that, we have seen a different cpu call free_uid as a result of sys_wait4 and, immediately after acquiring the uidhash_lock, receive a timer interrupt which eventually leads to an attempt to grab the tasklist_lock.
kernel/user.c +12 -6
@@ -90,6 +90,9 @@void free_uid (struct user_struct *up) { +unsigned long flags; + +local_irq_save (flags);if (up &&atomic_dec_and_lock (&up->__count, &uidhash_lock)) {uid_hash_remove (up);key_put (up->uid_keyring);
@@ -97,16 +100,18 @@kmem_cache_free (uid_cachep, up);spin_unlock (&uidhash_lock); } +local_irq_restore (flags); }struct user_struct *alloc_uid (uid_t uid) {struct list_head *hashent =uidhashentry (uid);struct user_struct *up; +unsigned long flags; -spin_lock (&uidhash_lock); +spin_lock_irqsave (&uidhash_lock, flags); up =uid_hash_find (uid, hashent); -spin_unlock (&uidhash_lock); +spin_unlock_irqrestore (&uidhash_lock, flags);if (!up) {struct user_struct *new;
@@ -132,7 +137,7 @@* Before adding this, check whether we raced * on adding the same user already.. */ -spin_lock (&uidhash_lock); +spin_lock_irqsave (&uidhash_lock, flags); up =uid_hash_find (uid, hashent);if (up) {key_put (new->uid_keyring);
@@ -142,7 +147,7 @@uid_hash_insert (new, hashent); up = new; } -spin_unlock (&uidhash_lock); +spin_unlock_irqrestore (&uidhash_lock, flags); }return up;
@@ -170,6 +175,7 @@static int __init uid_cache_init (void ) {int n; +unsigned long flags; uid_cachep =kmem_cache_create ("uid_cache" ,sizeof (struct user_struct ),0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ,NULL );
@@ -178,9 +184,9 @@INIT_LIST_HEAD (uidhash_table + n);/* Insert the root user immediately (init already runs as root) */ -spin_lock (&uidhash_lock); +spin_lock_irqsave (&uidhash_lock, flags);uid_hash_insert (&root_user,uidhashentry (0 )); -spin_unlock (&uidhash_lock); +spin_unlock_irqrestore (&uidhash_lock, flags);return 0 ; }
Quoted 8 lines · Robin Holt
reparent_to_init()doeswrite_lock_irq(&tasklist_lock)then callsswitch_uid()which callsfree_uid()which grabs theuidhash_lock.Independent of that, we have seen a different cpu call
free_uidas a result ofsys_wait4and, immediately after acquiring theuidhash_lock, receive a timer interrupt which eventually leads to an attempt to grab thetasklist_lock.
Hmm.. We fixed this already, and the current tree doesn't have this problem (and the fix was much simpler: just move "switch_uid()" to outside the tasklist_lock.
That fix was done late december last year (current BK revision:
1.1938.446.38), and I really think your patch is stale. Please double-check,
Linus