135135 *
136136 * Where (A) orders the waiters increment and the futex value read through
137137 * atomic operations (see hb_waiters_inc) and where (B) orders the write
138- * to futex and the waiters read -- this is done by the barriers for both
139- * shared and private futexes in get_futex_key_refs().
138+ * to futex and the waiters read (see hb_waiters_pending()).
140139 *
141140 * This yields the following case (where X:=waiters, Y:=futex):
142141 *
@@ -359,6 +358,10 @@ static inline void hb_waiters_dec(struct futex_hash_bucket *hb)
359358static inline int hb_waiters_pending (struct futex_hash_bucket * hb )
360359{
361360#ifdef CONFIG_SMP
361+ /*
362+ * Full barrier (B), see the ordering comment above.
363+ */
364+ smp_mb ();
362365 return atomic_read (& hb -> waiters );
363366#else
364367 return 1 ;
@@ -396,68 +399,6 @@ static inline int match_futex(union futex_key *key1, union futex_key *key2)
396399 && key1 -> both .offset == key2 -> both .offset );
397400}
398401
399- /*
400- * Take a reference to the resource addressed by a key.
401- * Can be called while holding spinlocks.
402- *
403- */
404- static void get_futex_key_refs (union futex_key * key )
405- {
406- if (!key -> both .ptr )
407- return ;
408-
409- /*
410- * On MMU less systems futexes are always "private" as there is no per
411- * process address space. We need the smp wmb nevertheless - yes,
412- * arch/blackfin has MMU less SMP ...
413- */
414- if (!IS_ENABLED (CONFIG_MMU )) {
415- smp_mb (); /* explicit smp_mb(); (B) */
416- return ;
417- }
418-
419- switch (key -> both .offset & (FUT_OFF_INODE |FUT_OFF_MMSHARED )) {
420- case FUT_OFF_INODE :
421- smp_mb (); /* explicit smp_mb(); (B) */
422- break ;
423- case FUT_OFF_MMSHARED :
424- smp_mb (); /* explicit smp_mb(); (B) */
425- break ;
426- default :
427- /*
428- * Private futexes do not hold reference on an inode or
429- * mm, therefore the only purpose of calling get_futex_key_refs
430- * is because we need the barrier for the lockless waiter check.
431- */
432- smp_mb (); /* explicit smp_mb(); (B) */
433- }
434- }
435-
436- /*
437- * Drop a reference to the resource addressed by a key.
438- * The hash bucket spinlock must not be held. This is
439- * a no-op for private futexes, see comment in the get
440- * counterpart.
441- */
442- static void drop_futex_key_refs (union futex_key * key )
443- {
444- if (!key -> both .ptr ) {
445- /* If we're here then we tried to put a key we failed to get */
446- WARN_ON_ONCE (1 );
447- return ;
448- }
449-
450- if (!IS_ENABLED (CONFIG_MMU ))
451- return ;
452-
453- switch (key -> both .offset & (FUT_OFF_INODE |FUT_OFF_MMSHARED )) {
454- case FUT_OFF_INODE :
455- break ;
456- case FUT_OFF_MMSHARED :
457- break ;
458- }
459- }
460-
461402enum futex_access {
462403 FUTEX_READ ,
463404 FUTEX_WRITE
@@ -589,7 +530,6 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, enum futex_a
589530 if (!fshared ) {
590531 key -> private .mm = mm ;
591532 key -> private .address = address ;
592- get_futex_key_refs (key ); /* implies smp_mb(); (B) */
593533 return 0 ;
594534 }
595535
@@ -729,16 +669,13 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, enum futex_a
729669 rcu_read_unlock ();
730670 }
731671
732- get_futex_key_refs (key ); /* implies smp_mb(); (B) */
733-
734672out :
735673 put_page (page );
736674 return err ;
737675}
738676
739677static inline void put_futex_key (union futex_key * key )
740678{
741- drop_futex_key_refs (key );
742679}
743680
744681/**
@@ -1873,7 +1810,6 @@ void requeue_futex(struct futex_q *q, struct futex_hash_bucket *hb1,
18731810 plist_add (& q -> list , & hb2 -> chain );
18741811 q -> lock_ptr = & hb2 -> lock ;
18751812 }
1876- get_futex_key_refs (key2 );
18771813 q -> key = * key2 ;
18781814}
18791815
@@ -1895,7 +1831,6 @@ static inline
18951831void requeue_pi_wake_futex (struct futex_q * q , union futex_key * key ,
18961832 struct futex_hash_bucket * hb )
18971833{
1898- get_futex_key_refs (key );
18991834 q -> key = * key ;
19001835
19011836 __unqueue_futex (q );
@@ -2006,7 +1941,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
20061941 u32 * cmpval , int requeue_pi )
20071942{
20081943 union futex_key key1 = FUTEX_KEY_INIT , key2 = FUTEX_KEY_INIT ;
2009- int drop_count = 0 , task_count = 0 , ret ;
1944+ int task_count = 0 , ret ;
20101945 struct futex_pi_state * pi_state = NULL ;
20111946 struct futex_hash_bucket * hb1 , * hb2 ;
20121947 struct futex_q * this , * next ;
@@ -2127,7 +2062,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
21272062 */
21282063 if (ret > 0 ) {
21292064 WARN_ON (pi_state );
2130- drop_count ++ ;
21312065 task_count ++ ;
21322066 /*
21332067 * If we acquired the lock, then the user space value
@@ -2247,7 +2181,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
22472181 * doing so.
22482182 */
22492183 requeue_pi_wake_futex (this , & key2 , hb2 );
2250- drop_count ++ ;
22512184 continue ;
22522185 } else if (ret ) {
22532186 /*
@@ -2268,7 +2201,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
22682201 }
22692202 }
22702203 requeue_futex (this , hb1 , hb2 , & key2 );
2271- drop_count ++ ;
22722204 }
22732205
22742206 /*
@@ -2283,15 +2215,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
22832215 wake_up_q (& wake_q );
22842216 hb_waiters_dec (hb2 );
22852217
2286- /*
2287- * drop_futex_key_refs() must be called outside the spinlocks. During
2288- * the requeue we moved futex_q's from the hash bucket at key1 to the
2289- * one at key2 and updated their key pointer. We no longer need to
2290- * hold the references to key1.
2291- */
2292- while (-- drop_count >= 0 )
2293- drop_futex_key_refs (& key1 );
2294-
22952218out_put_keys :
22962219 put_futex_key (& key2 );
22972220out_put_key1 :
@@ -2421,7 +2344,6 @@ static int unqueue_me(struct futex_q *q)
24212344 ret = 1 ;
24222345 }
24232346
2424- drop_futex_key_refs (& q -> key );
24252347 return ret ;
24262348}
24272349
0 commit comments