[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230920125136.15504-1-pmladek@suse.com>
Date: Wed, 20 Sep 2023 14:51:36 +0200
From: Petr Mladek <pmladek@...e.com>
To: John Ogness <john.ogness@...utronix.de>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
Steven Rostedt <rostedt@...dmis.org>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-kernel@...r.kernel.org, Petr Mladek <pmladek@...e.com>
Subject: [PATCH] printk/nbcon: Add assert that CPU migration is disabled when calling nbcon_context_try_acquire()
The nbcon console is locked when the 'prio' and 'cpu' fields in
console->nbcon_state stay the same. The locking algorithm would
break when the locked context got migrated to another CPU.
Add assert into nbcon_context_try_acquire(). It would warn when
the function is called in a context where the CPU migration
is possible.
Signed-off-by: Petr Mladek <pmladek@...e.com>
---
I propose this patch on top of the patchset adding basic support
for nbcon consoles, see
https://lore.kernel.org/r/20230916192007.608398-1-john.ogness@linutronix.de
Or another way, it is on top of rework/nbcon-base branch in
printk/linux.git tree.
---
kernel/printk/nbcon.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index b96077152f49..2c2e98d61660 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -234,6 +234,19 @@ static void nbcon_seq_try_update(struct nbcon_context *ctxt, u64 new_seq)
}
}
+#ifdef CONFIG_PROVE_LOCKING
+static inline void nbcon_assert_cpu_migration_disabled(void)
+{
+ WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP) &&
+ __lockdep_enabled &&
+ this_cpu_read(hardirqs_enabled) &&
+ preempt_count() == 0 &&
+ !current->migration_disabled);
+}
+#else
+#define nbcon_assert_cpu_migration(void) {}
+#endif
+
/**
* nbcon_context_try_acquire_direct - Try to acquire directly
* @ctxt: The context of the caller
@@ -579,6 +592,8 @@ static bool nbcon_context_try_acquire(struct nbcon_context *ctxt)
struct nbcon_state cur;
int err;
+ nbcon_assert_cpu_migration_disabled();
+
nbcon_state_read(con, &cur);
try_again:
err = nbcon_context_try_acquire_direct(ctxt, &cur);
--
2.35.3
Powered by blists - more mailing lists