• Boqun Feng's avatar
    lockdep: Fix recursive read lock related safe->unsafe detection · f08e3888
    Boqun Feng authored
    Currently, in safe->unsafe detection, lockdep misses the fact that a
    LOCK_ENABLED_IRQ_*_READ usage and a LOCK_USED_IN_IRQ_*_READ usage may
    cause deadlock too, for example:
    
    	P1                          P2
    	<irq disabled>
    	write_lock(l1);             <irq enabled>
    				    read_lock(l2);
    	write_lock(l2);
    				    <in irq>
    				    read_lock(l1);
    
    Actually, all of the following cases may cause deadlocks:
    
    	LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*
    	LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*
    	LOCK_USED_IN_IRQ_* -> LOCK_ENABLED_IRQ_*_READ
    	LOCK_USED_IN_IRQ_*_READ -> LOCK_ENABLED_IRQ_*_READ
    
    To fix this, we need to 1) change the calculation of exclusive_mask() so
    that READ bits are not dropped and 2) always call usage() in
    mark_lock_irq() to check usage deadlocks, even when the new usage of the
    lock is READ.
    
    Besides, adjust usage_match() and usage_acculumate() to recursive read
    lock changes.
    Signed-off-by: default avatarBoqun Feng <boqun.feng@gmail.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/20200807074238.1632519-12-boqun.feng@gmail.com
    f08e3888
lockdep.c 159 KB