The patch titled Subject: seqlock: do the lockdep annotation before locking in do_write_seqcount_begin_nested() has been added to the -mm mm-unstable branch. Its filename is seqlock-do-the-lockdep-annotation-before-locking-in-do_write_seqcount_begin_nested.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/seqlock-do-the-lockdep-annotation-before-locking-in-do_write_seqcount_begin_nested.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> Subject: seqlock: do the lockdep annotation before locking in do_write_seqcount_begin_nested() Date: Fri, 23 Jun 2023 19:12:31 +0200 Patch series "seqlock,mm: lockdep annotation + write_seqlock_irqsave()", v2. This patch (of 2): 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). Link: https://lkml.kernel.org/r/20230623171232.892937-2-bigeasy@xxxxxxxxxxxxx Fixes: 1ca7d67cf5d5a ("seqcount: Add lockdep functionality to seqcount/seqlock structures") Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> Reported-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Link: https://lore.kernel.org/20230621130641.-5iueY1I@xxxxxxxxxxxxx Cc: Boqun Feng <boqun.feng@xxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: John Ogness <john.ogness@xxxxxxxxxxxxx> Cc: Luis Claudio R. Goncalves <lgoncalv@xxxxxxxxxx> Cc: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Cc: Petr Mladek <pmladek@xxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Waiman Long <longman@xxxxxxxxxx> Cc: Will Deacon <will@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/seqlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/include/linux/seqlock.h~seqlock-do-the-lockdep-annotation-before-locking-in-do_write_seqcount_begin_nested +++ a/include/linux/seqlock.h @@ -512,8 +512,8 @@ do { \ static inline void do_write_seqcount_begin_nested(seqcount_t *s, int subclass) { - do_raw_write_seqcount_begin(s); seqcount_acquire(&s->dep_map, subclass, 0, _RET_IP_); + do_raw_write_seqcount_begin(s); } /** _ Patches currently in -mm which might be from bigeasy@xxxxxxxxxxxxx are seqlock-do-the-lockdep-annotation-before-locking-in-do_write_seqcount_begin_nested.patch mm-page_alloc-use-write_seqlock_irqsave-instead-write_seqlock-local_irq_save.patch