Skip to content

Commit 41b43b6

Browse files
Sebastian Andrzej SiewiorIngo Molnar
authored andcommitted
locking/seqlock: Do the lockdep annotation before locking in do_write_seqcount_begin_nested()
It was brought up by Tetsuo that the following sequence: write_seqlock_irqsave() printk_deferred_enter() could lead to a deadlock if the lockdep annotation within write_seqlock_irqsave() triggers. The problem is that the sequence counter is incremented before the lockdep annotation is performed. The lockdep splat would then attempt to invoke printk() but the reader side, of the same seqcount, could have a tty_port::lock acquired waiting for the sequence number to become even again. The other lockdep annotations come before the actual locking because "we want to see the locking error before it happens". There is no reason why seqcount should be different here. Do the lockdep annotation first then perform the locking operation (the sequence increment). Fixes: 1ca7d67 ("seqcount: Add lockdep functionality to seqcount/seqlock structures") Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20230920104627._DTHgPyA@linutronix.de Closes: https://lore.kernel.org/20230621130641.-5iueY1I@linutronix.de
1 parent 6d2779e commit 41b43b6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/linux/seqlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ do { \
512512

513513
static inline void do_write_seqcount_begin_nested(seqcount_t *s, int subclass)
514514
{
515-
do_raw_write_seqcount_begin(s);
516515
seqcount_acquire(&s->dep_map, subclass, 0, _RET_IP_);
516+
do_raw_write_seqcount_begin(s);
517517
}
518518

519519
/**

0 commit comments

Comments
 (0)