@@ -472,6 +472,17 @@ static void __inode_add_lru(struct inode *inode, bool rotate)
472472 inode -> i_state |= I_REFERENCED ;
473473}
474474
475+ struct wait_queue_head * inode_bit_waitqueue (struct wait_bit_queue_entry * wqe ,
476+ struct inode * inode , u32 bit )
477+ {
478+ void * bit_address ;
479+
480+ bit_address = inode_state_wait_address (inode , bit );
481+ init_wait_var_entry (wqe , bit_address , 0 );
482+ return __var_waitqueue (bit_address );
483+ }
484+ EXPORT_SYMBOL (inode_bit_waitqueue );
485+
475486/*
476487 * Add inode to LRU if needed (inode is unused and clean).
477488 *
@@ -500,24 +511,35 @@ static void inode_unpin_lru_isolating(struct inode *inode)
500511 spin_lock (& inode -> i_lock );
501512 WARN_ON (!(inode -> i_state & I_LRU_ISOLATING ));
502513 inode -> i_state &= ~I_LRU_ISOLATING ;
503- smp_mb ();
504- wake_up_bit ( & inode -> i_state , __I_LRU_ISOLATING );
514+ /* Called with inode->i_lock which ensures memory ordering. */
515+ inode_wake_up_bit ( inode , __I_LRU_ISOLATING );
505516 spin_unlock (& inode -> i_lock );
506517}
507518
508519static void inode_wait_for_lru_isolating (struct inode * inode )
509520{
521+ struct wait_bit_queue_entry wqe ;
522+ struct wait_queue_head * wq_head ;
523+
510524 lockdep_assert_held (& inode -> i_lock );
511- if (inode -> i_state & I_LRU_ISOLATING ) {
512- DEFINE_WAIT_BIT (wq , & inode -> i_state , __I_LRU_ISOLATING );
513- wait_queue_head_t * wqh ;
525+ if (!(inode -> i_state & I_LRU_ISOLATING ))
526+ return ;
514527
515- wqh = bit_waitqueue (& inode -> i_state , __I_LRU_ISOLATING );
528+ wq_head = inode_bit_waitqueue (& wqe , inode , __I_LRU_ISOLATING );
529+ for (;;) {
530+ prepare_to_wait_event (wq_head , & wqe .wq_entry , TASK_UNINTERRUPTIBLE );
531+ /*
532+ * Checking I_LRU_ISOLATING with inode->i_lock guarantees
533+ * memory ordering.
534+ */
535+ if (!(inode -> i_state & I_LRU_ISOLATING ))
536+ break ;
516537 spin_unlock (& inode -> i_lock );
517- __wait_on_bit ( wqh , & wq , bit_wait , TASK_UNINTERRUPTIBLE );
538+ schedule ( );
518539 spin_lock (& inode -> i_lock );
519- WARN_ON (inode -> i_state & I_LRU_ISOLATING );
520540 }
541+ finish_wait (wq_head , & wqe .wq_entry );
542+ WARN_ON (inode -> i_state & I_LRU_ISOLATING );
521543}
522544
523545/**
@@ -723,7 +745,13 @@ static void evict(struct inode *inode)
723745 * used as an indicator whether blocking on it is safe.
724746 */
725747 spin_lock (& inode -> i_lock );
726- wake_up_bit (& inode -> i_state , __I_NEW );
748+ /*
749+ * Pairs with the barrier in prepare_to_wait_event() to make sure
750+ * ___wait_var_event() either sees the bit cleared or
751+ * waitqueue_active() check in wake_up_var() sees the waiter.
752+ */
753+ smp_mb ();
754+ inode_wake_up_bit (inode , __I_NEW );
727755 BUG_ON (inode -> i_state != (I_FREEING | I_CLEAR ));
728756 spin_unlock (& inode -> i_lock );
729757
@@ -1135,8 +1163,13 @@ void unlock_new_inode(struct inode *inode)
11351163 spin_lock (& inode -> i_lock );
11361164 WARN_ON (!(inode -> i_state & I_NEW ));
11371165 inode -> i_state &= ~I_NEW & ~I_CREATING ;
1166+ /*
1167+ * Pairs with the barrier in prepare_to_wait_event() to make sure
1168+ * ___wait_var_event() either sees the bit cleared or
1169+ * waitqueue_active() check in wake_up_var() sees the waiter.
1170+ */
11381171 smp_mb ();
1139- wake_up_bit ( & inode -> i_state , __I_NEW );
1172+ inode_wake_up_bit ( inode , __I_NEW );
11401173 spin_unlock (& inode -> i_lock );
11411174}
11421175EXPORT_SYMBOL (unlock_new_inode );
@@ -1147,8 +1180,13 @@ void discard_new_inode(struct inode *inode)
11471180 spin_lock (& inode -> i_lock );
11481181 WARN_ON (!(inode -> i_state & I_NEW ));
11491182 inode -> i_state &= ~I_NEW ;
1183+ /*
1184+ * Pairs with the barrier in prepare_to_wait_event() to make sure
1185+ * ___wait_var_event() either sees the bit cleared or
1186+ * waitqueue_active() check in wake_up_var() sees the waiter.
1187+ */
11501188 smp_mb ();
1151- wake_up_bit ( & inode -> i_state , __I_NEW );
1189+ inode_wake_up_bit ( inode , __I_NEW );
11521190 spin_unlock (& inode -> i_lock );
11531191 iput (inode );
11541192}
@@ -2337,8 +2375,8 @@ EXPORT_SYMBOL(inode_needs_sync);
23372375 */
23382376static void __wait_on_freeing_inode (struct inode * inode , bool is_inode_hash_locked )
23392377{
2340- wait_queue_head_t * wq ;
2341- DEFINE_WAIT_BIT ( wait , & inode -> i_state , __I_NEW ) ;
2378+ struct wait_bit_queue_entry wqe ;
2379+ struct wait_queue_head * wq_head ;
23422380
23432381 /*
23442382 * Handle racing against evict(), see that routine for more details.
@@ -2349,14 +2387,14 @@ static void __wait_on_freeing_inode(struct inode *inode, bool is_inode_hash_lock
23492387 return ;
23502388 }
23512389
2352- wq = bit_waitqueue ( & inode -> i_state , __I_NEW );
2353- prepare_to_wait ( wq , & wait .wq_entry , TASK_UNINTERRUPTIBLE );
2390+ wq_head = inode_bit_waitqueue ( & wqe , inode , __I_NEW );
2391+ prepare_to_wait_event ( wq_head , & wqe .wq_entry , TASK_UNINTERRUPTIBLE );
23542392 spin_unlock (& inode -> i_lock );
23552393 rcu_read_unlock ();
23562394 if (is_inode_hash_locked )
23572395 spin_unlock (& inode_hash_lock );
23582396 schedule ();
2359- finish_wait (wq , & wait .wq_entry );
2397+ finish_wait (wq_head , & wqe .wq_entry );
23602398 if (is_inode_hash_locked )
23612399 spin_lock (& inode_hash_lock );
23622400 rcu_read_lock ();
0 commit comments