• Boqun Feng's avatar
    lockdep: Take read/write status in consideration when generate chainkey · f611e8cf
    Boqun Feng authored
    Currently, the chainkey of a lock chain is a hash sum of the class_idx
    of all the held locks, the read/write status are not taken in to
    consideration while generating the chainkey. This could result into a
    problem, if we have:
    
    	P1()
    	{
    		read_lock(B);
    		lock(A);
    	}
    
    	P2()
    	{
    		lock(A);
    		read_lock(B);
    	}
    
    	P3()
    	{
    		lock(A);
    		write_lock(B);
    	}
    
    , and P1(), P2(), P3() run one by one. And when running P2(), lockdep
    detects such a lock chain A -> B is not a deadlock, then it's added in
    the chain cache, and then when running P3(), even if it's a deadlock, we
    could miss it because of the hit of chain cache. This could be confirmed
    by self testcase "chain cached mixed R-L/L-W ".
    
    To resolve this, we use concept "hlock_id" to generate the chainkey, the
    hlock_id is a tuple (hlock->class_idx, hlock->read), which fits in a u16
    type. With this, the chainkeys are different is the lock sequences have
    the same locks but different read/write status.
    
    Besides, since we use "hlock_id" to generate chainkeys, the chain_hlocks
    array now store the "hlock_id"s rather than lock_class indexes.
    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-15-boqun.feng@gmail.com
    f611e8cf
lockdep.c 158 KB