[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <xdfm634qqtchbaqfnnnmwqwmto5bllkspfixescyxltvjb4y2c@l4uiiarg5kjs>
Date: Fri, 26 Sep 2025 11:18:34 +0200
From: Joel Granados <joel.granados@...nel.org>
To: Pavel Tikhomirov <ptikhomirov@...tuozzo.com>
Cc: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Will Deacon <will@...nel.org>, Boqun Feng <boqun.feng@...il.com>,
Waiman Long <longman@...hat.com>, Kees Cook <kees@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>, Konstantin Khorenko <khorenko@...tuozzo.com>,
Denis Lunev <den@...tuozzo.com>, Aleksandr Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org, kernel@...nvz.org
Subject: Re: [PATCH] locking: detect spin_lock_irq() call with disabled
interrupts
On Fri, Jun 06, 2025 at 05:57:23PM +0800, Pavel Tikhomirov wrote:
> This is intended to easily detect irq spinlock self-deadlocks like:
>
> spin_lock_irq(A);
> spin_lock_irq(B);
> spin_unlock_irq(B);
> IRQ {
> spin_lock(A); <- deadlocks
> spin_unlock(A);
> }
> spin_unlock_irq(A);
...
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 9b4f0cff76ea..1e3cca2e3c8f 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -50,6 +50,7 @@
> #include <linux/sched/sysctl.h>
> #include <linux/mount.h>
> #include <linux/pid.h>
> +#include <linux/spinlock.h>
>
> #include "../lib/kstrtox.h"
>
> @@ -1758,6 +1759,14 @@ static const struct ctl_table kern_table[] = {
> .extra2 = SYSCTL_INT_MAX,
> },
> #endif
> +#ifdef CONFIG_DEBUG_SPINLOCK
> + {
> + .procname = "debug_spin_lock_irq_with_disabled_interrupts",
> + .data = &debug_spin_lock_irq_with_disabled_interrupts,
> + .mode = 0644,
> + .proc_handler = proc_do_static_key,
> + },
> +#endif
Patchwork reminded me about this one and I see now that I missed a
comment. In case you are working on a V2, do *NOT* add more ctl_table
elements to the kern_table. If you need to add a sysctl file for
locking, do it under kernel/locking. You can take inspiration from how
rtmutex_sysctl_table and "max_lock_depth" is handled.
best
> };
>
> int __init sysctl_init_bases(void)
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index ebe33181b6e6..c4834f4c9d51 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -1465,6 +1465,18 @@ config DEBUG_SPINLOCK
> best used in conjunction with the NMI watchdog so that spinlock
> deadlocks are also debuggable.
>
> +config DEBUG_SPINLOCK_IRQ_WITH_DISABLED_INTERRUPTS_BY_DEFAULT
> + bool "Detect spin_(un)lock_irq() call with disabled(enabled) interrupts"
> + depends on DEBUG_SPINLOCK
> + help
> + Say Y here to detect spin_lock_irq() and spin_unlock_irq() calls
> + with disabled (enabled) interrupts. This helps detecting bugs
> + where the code is not using the right locking primitives. E.g.
> + using spin_lock_irq() twice in a row (on different locks). And thus
> + code can reenable interrupts where they should be disabled and lead
> + to deadlock.
> + Say N if you are unsure.
> +
> config DEBUG_MUTEXES
> bool "Mutex debugging: basic checks"
> depends on DEBUG_KERNEL && !PREEMPT_RT
> --
> 2.49.0
>
--
Joel Granados
Download attachment "signature.asc" of type "application/pgp-signature" (660 bytes)
Powered by blists - more mailing lists