• Boqun Feng's avatar
    locking/lockdep: Introduce lock_sync() · 2f1f043e
    Boqun Feng authored
    Currently, functions like synchronize_srcu() do not have lockdep
    annotations resembling those of other write-side locking primitives.
    Such annotations might look as follows:
    
    	lock_acquire();
    	lock_release();
    
    Such annotations would tell lockdep that synchronize_srcu() acts like
    an empty critical section that waits for other (read-side) critical
    sections to finish.  This would definitely catch some deadlock, but
    as pointed out by Paul Mckenney [1], this could also introduce false
    positives because of irq-safe/unsafe detection.  Of course, there are
    tricks could help with this:
    
    	might_sleep(); // Existing statement in __synchronize_srcu().
    	if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
    		local_irq_disable();
    		lock_acquire();
    		lock_release();
    		local_irq_enable();
    	}
    
    But it would be better for lockdep to provide a separate annonation for
    functions like synchronize_srcu(), so that people won't need to repeat
    the ugly tricks above.
    
    Therefore introduce lock_sync(), which is simply an lock+unlock
    pair with no irq safe/unsafe deadlock check.  This works because the
    to-be-annontated functions do not create real critical sections, and
    there is therefore no way that irq can create extra dependencies.
    
    [1]: https://lore.kernel.org/lkml/20180412021233.ewncg5jjuzjw3x62@tardis/Signed-off-by: default avatarBoqun Feng <boqun.feng@gmail.com>
    Acked-by: default avatarWaiman Long <longman@redhat.com>
    Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    [ boqun: Fix typos reported by Davidlohr Bueso and Paul E. Mckenney ]
    Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: default avatarBoqun Feng <boqun.feng@gmail.com>
    2f1f043e
lockdep.c 169 KB