kernel/printk/printk.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
printk_legacy_map is used to hide lock nesting violations caused by
legacy drivers and is using the wrong override type. LD_WAIT_SLEEP is
for always sleeping lock types such as mutex_t. LD_WAIT_CONFIG is for
lock type which are sleeping while spinning on PREEMPT_RT such as
spinlock_t.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/printk/printk.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 5aee9ffb16b9..e9e65228f1ac 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3002,21 +3002,18 @@ bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
}
/*
- * Legacy console printing from printk() caller context does not respect
- * raw_spinlock/spinlock nesting. For !PREEMPT_RT the lockdep warning is a
- * false positive. For PREEMPT_RT the false positive condition does not
- * occur.
- *
- * This map is used to temporarily establish LD_WAIT_SLEEP context for the
- * console write() callback when legacy printing to avoid false positive
- * lockdep complaints, thus allowing lockdep to continue to function for
- * real issues.
- */
+ * The legacy console always acquires a spinlock_t from its printing
+ * callback. This violates lock nesting if the caller acquired an always
+ * spinning lock (raw_spinlock_t) while invoking printk(). This is not a
+ * problem on PREEMPT_RT because legacy consoles print always from a
+ * dedicated thread and never from within printk(). Therefore we tell
+ * lockdep that a sleeping spin lock (spinlock_t) is valid here.
+*/
#ifdef CONFIG_PREEMPT_RT
static inline void printk_legacy_allow_spinlock_enter(void) { }
static inline void printk_legacy_allow_spinlock_exit(void) { }
#else
-static DEFINE_WAIT_OVERRIDE_MAP(printk_legacy_map, LD_WAIT_SLEEP);
+static DEFINE_WAIT_OVERRIDE_MAP(printk_legacy_map, LD_WAIT_CONFIG);
static inline void printk_legacy_allow_spinlock_enter(void)
{
--
2.25.1.362.g51ebf55
On Sun 2025-10-26 16:07:26, Oleg Nesterov wrote: > printk_legacy_map is used to hide lock nesting violations caused by > legacy drivers and is using the wrong override type. LD_WAIT_SLEEP is > for always sleeping lock types such as mutex_t. LD_WAIT_CONFIG is for > lock type which are sleeping while spinning on PREEMPT_RT such as > spinlock_t. > > Signed-off-by: Oleg Nesterov <oleg@redhat.com> JFYI, the patch has been comitted into printk/linux.git, branch rework/threaded-printk. It is queued for 6.19 merge window. Best Regards, Petr
On Sun 2025-10-26 16:07:26, Oleg Nesterov wrote: > printk_legacy_map is used to hide lock nesting violations caused by > legacy drivers and is using the wrong override type. LD_WAIT_SLEEP is > for always sleeping lock types such as mutex_t. LD_WAIT_CONFIG is for > lock type which are sleeping while spinning on PREEMPT_RT such as > spinlock_t. > > Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Best Regards, Petr
On 2025-10-26, Oleg Nesterov <oleg@redhat.com> wrote: > printk_legacy_map is used to hide lock nesting violations caused by > legacy drivers and is using the wrong override type. LD_WAIT_SLEEP is > for always sleeping lock types such as mutex_t. LD_WAIT_CONFIG is for > lock type which are sleeping while spinning on PREEMPT_RT such as > spinlock_t. > > Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reviewed-by: John Ogness <john.ogness@linutronix.de>
On 2025-10-26 16:07:26 [+0100], Oleg Nesterov wrote: > printk_legacy_map is used to hide lock nesting violations caused by > legacy drivers and is using the wrong override type. LD_WAIT_SLEEP is > for always sleeping lock types such as mutex_t. LD_WAIT_CONFIG is for > lock type which are sleeping while spinning on PREEMPT_RT such as > spinlock_t. > > Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Sebastian
© 2016 - 2026 Red Hat, Inc.