mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] printk/nbcon: Add assert that CPU migration is disabled when calling nbcon_context_try_acquire()
@ 2023-09-20 12:51 Petr Mladek
  2023-09-20 13:00 ` John Ogness
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Petr Mladek @ 2023-09-20 12:51 UTC (permalink / raw)
  To: John Ogness, Sergey Senozhatsky, Steven Rostedt
  Cc: Thomas Gleixner, Greg Kroah-Hartman, linux-kernel, Petr Mladek

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@suse.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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-20 18:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20 12:51 [PATCH] printk/nbcon: Add assert that CPU migration is disabled when calling nbcon_context_try_acquire() Petr Mladek
2023-09-20 13:00 ` John Ogness
2023-09-20 13:08   ` Petr Mladek
2023-09-20 15:57 ` kernel test robot
2023-09-20 18:24 ` kernel test robot

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®