From: Waiman Long <longman@redhat.com>
To: Guenter Roeck <linux@roeck-us.net>, linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>
Subject: Re: Nested calls to spin_lock_irq with different locks
Date: Sat, 19 Nov 2022 20:26:02 -0500 [thread overview]
Message-ID: <a40e4347-8497-48cc-f2ee-73072b2ab79c@redhat.com> (raw)
In-Reply-To: <20221119151737.GA702470@roeck-us.net>
On 11/19/22 10:17, Guenter Roeck wrote:
> Hi,
>
> recently I have seen various syzbot reports reporting inconsistent lock
> states. One example is
>
> ================================
> WARNING: inconsistent lock state
> 5.16.0-syzkaller #0 Not tainted
> --------------------------------
> inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
> syz-executor.2/18360 [HC0[0]:SC0[0]:HE0:SE1] takes:
> ffffffff8c712cf8 (sync_timeline_list_lock){?...}-{2:2}, at: spin_lock_irq include/linux/spinlock.h:374 [inline]
> ffffffff8c712cf8 (sync_timeline_list_lock){?...}-{2:2}, at: sync_info_debugfs_show+0x2d/0x200 drivers/dma-buf/sync_debug.c:147
> {IN-HARDIRQ-W} state was registered at:
> lock_acquire kernel/locking/lockdep.c:5639 [inline]
> lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5604
> __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
> _raw_spin_lock_irqsave+0x39/0x50 kernel/locking/spinlock.c:162
> sync_timeline_debug_remove+0x25/0x190 drivers/dma-buf/sync_debug.c:31
>
> ================================
> WARNING: inconsistent lock state
> 5.16.0-syzkaller #0 Not tainted
> --------------------------------
> inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
> syz-executor.2/18360 [HC0[0]:SC0[0]:HE0:SE1] takes:
> ffffffff8c712cf8 (sync_timeline_list_lock){?...}-{2:2}, at: spin_lock_irq include/linux/spinlock.h:374 [inline]
> ffffffff8c712cf8 (sync_timeline_list_lock){?...}-{2:2}, at: sync_info_debugfs_show+0x2d/0x200 drivers/dma-buf/sync_debug.c:147
>
> The log is from
> https://lore.kernel.org/lkml/000000000000d5b3af05edc9d445@google.com/T/.
>
> sync_info_debugfs_show() calls spin_lock_irq(&sync_timeline_list_lock).
> With the lock active, it calls sync_print_obj(), which calls
> spin_lock_irq(&obj->lock) and spin_unlock_irq(&obj->lock).
>
> spin_unlock_irq(), via __raw_spin_unlock_irq(), calls local_irq_enable(),
> presumably enabling hardware interrupts. If such a hardware interrupt
> calls sync_timeline_debug_remove(), the problem would be seen.
>
> Can this happen in practice ? In other words, does that mean that nested
> calls to spin_lock_irq() (with different locks) are not supported ?
> If that is indeed the case, is there a suggested remedy ?
That is what spin_lock_irqsave() and spin_unlock_irqrestore() are for.
If you are not certain if a function will be called with interrupt
enabled or disabled, you should always use the irqsave/irqrestore
variant to make sure the function will work in both cases.
Cheers,
Longman
prev parent reply other threads:[~2022-11-20 1:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-19 15:17 Guenter Roeck
2022-11-20 1:26 ` Waiman Long [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a40e4347-8497-48cc-f2ee-73072b2ab79c@redhat.com \
--to=longman@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®