From nobody Fri Feb 13 19:27:25 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3493BCE79CE for ; Wed, 20 Sep 2023 12:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235795AbjITMvz (ORCPT ); Wed, 20 Sep 2023 08:51:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235056AbjITMvx (ORCPT ); Wed, 20 Sep 2023 08:51:53 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8131583 for ; Wed, 20 Sep 2023 05:51:47 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 427AC21BE1; Wed, 20 Sep 2023 12:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695214306; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=07u4Q5pAxOrutNCPHuGqm79fyJmvNY+HPmPgd0ex2so=; b=FcDpi5m25Ust/F5P9vXeaMt5gXDitqy8owCtcQNUn3gM3H9+LJupun+aE3xkvm4IXdxEh9 cO064jkZaj6HUD2gaCckqXXLDAOLhZAGU2V7J7UfSvl3CNAwtt6iZIyWdQu3eTciynPnBH pMTa6PXNvseArhOrg3ayw1eqIIiC5I8= Received: from alley.suse.cz (pmladek.tcp.ovpn2.prg.suse.de [10.100.208.146]) by relay2.suse.de (Postfix) with ESMTP id 95AFB2C142; Wed, 20 Sep 2023 12:51:45 +0000 (UTC) From: Petr Mladek To: John Ogness , Sergey Senozhatsky , Steven Rostedt Cc: Thomas Gleixner , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH] printk/nbcon: Add assert that CPU migration is disabled when calling nbcon_context_try_acquire() Date: Wed, 20 Sep 2023 14:51:36 +0200 Message-Id: <20230920125136.15504-1-pmladek@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- I propose this patch on top of the patchset adding basic support=20 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) } } =20 +#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() =3D=3D 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_cont= ext *ctxt) struct nbcon_state cur; int err; =20 + nbcon_assert_cpu_migration_disabled(); + nbcon_state_read(con, &cur); try_again: err =3D nbcon_context_try_acquire_direct(ctxt, &cur); --=20 2.35.3