From nobody Mon Dec 15 22:07:54 2025 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80153451C7 for ; Thu, 16 Oct 2025 14:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626095; cv=none; b=qPhzDJMJlFRqEVeU9JddVumQYKelfu9EYJL6ffQmd4c41GQtUXG3F7M8J8XTFeS4HaNjc05AdmJWdRuhA0yrCeHCwotRqL+8sZtI12zsPegSIwpXviNXFLJsUrvkuV2AXDMDCLYzGT6BLXi2Qg6la5vY0g/B/vY5LJgDbeg5opw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626095; c=relaxed/simple; bh=QMt0fN+cb78tcvpLQc3o5RloIrix2FlLCC1yGpt3I4I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J+qQqVoxPFe+ETc9RimPvFfOx4o2ngbBYJFutpUc6d04ff+tL/jNGTvZ0WXrnGhIl8xspKxDBEQRL9yqSDXU4gYvxk3JKpNQwhjqANJKZikmHI4WnAdNuyoiyjovQIExu4ecE+SByRTU5MTQA87fa7wBuRO9CZmQ94+tF4T2Bd4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=YEVIoOSw; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="YEVIoOSw" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-426fc536b5dso459889f8f.3 for ; Thu, 16 Oct 2025 07:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1760626090; x=1761230890; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8wcV2sJmeqXTy6AVfxXd8m5VMPoWxqFn+yRK4QT9DBU=; b=YEVIoOSwdmOf4HzINT/ZPVemGLZ5uy6Xulz61IVKUClzLlvPoMurjhfNh/UufXWRqj /foCidh1xvXTvWJzTGSa+lW5MP5vawjt0ZrKyUB1qiOD633vl0visDLxKH2OQ5QlsD5R zGRGrasvYhu4emSK2GAKrK14WXfnHdVjfE9h0L8/gzrNqGDJcAk7NTP581CLUMhykEBc 2ookVOGYyRpRc7dY3O3mTemZPtj5UsPkAirmYHX28EZHMyyt5F9IVfJDfXtJA6843h3b qDnHRDV/rtctCPXGVG6Dvr0Rb5DI7fUtODv637D+GR+VOjuwDsfbv3eh8q4/nx+TW1mh UW3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760626090; x=1761230890; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8wcV2sJmeqXTy6AVfxXd8m5VMPoWxqFn+yRK4QT9DBU=; b=ukmcERB0U/QFMGrx0M6L48TrTD3+/mbUlp0SZGi3YrJtshbOBU+SnSIihKF1bQ9daC EKv+EZv9olgymay+Ew9X+1nH+I2BKo3Tn/GBmICSIkG+eunPITVR9mLWLJ+D2yNIVXDo hROr7IHI5/jrCOEClJgf6U/clDQ7DEjkfG+wmn88vhptryrNLFuVXyZMKHlMRqSAh2Iu boS+qjUcrHQeonE1qQ9d4xDLJWzk7Y4Vprjq6lLD5HFkoUrYL3yyV9bY29RcXt0vnwW2 pSYcqzHolA7JtTU0kZI8vhEIGGPxEkKvqk/6Nce3pK0n4mZq/b8JiURaEnPI4YjfZTxe 9tPw== X-Gm-Message-State: AOJu0YzMamOehia2JcXp+prkMaw5ZoWRYSkofsA0XMJdPSJPtP9DE3Ay NmkDgZhwfLr97pxd4gc+6ByYCQw7n2v4npUiiAUffgwbtEx8EFhUyEUbRlBrzW/jP6o= X-Gm-Gg: ASbGncu7fWig+NL2lBTwnlhj40s2zKLagOrB7U/54yKCsUV8Q0CKsDAAGE1NqJaRglY FMYxuQzBvDYvY+KUxcrP8A11z7Rl8zWis6QECb3PEzxy6FU1cGw65yPLzD4lRZki+tjltKO7/IM AhsdVGFZku7OgZtOTOTs727yKD+QVJ+YB1kiXGzlS/7uP5nBoKmTJi+YGCDW/7k5LT4gRwEUNBA parENA7pnuEfWXOGHBQyEe3bjMZWcIp088REt0095dCqtGURgeHIoh3FDPCba1kzL11NzTGHoyR Bu/VdWdR+AHauPZTS83wyQsYKs7ickgreSLR34Q9G56D//XOo/kb6qIoJ/p90mxLi7rlGxjarCf Bc2LqumP+cku7aXA0DqNzi5yvXdbyUzolsAyZUhVdOk3Bpai3Jk3YYxRUlMtlUJPHSQIv7hfqKv 5uny3cMCk= X-Google-Smtp-Source: AGHT+IGmVbScEjUkbk7rVxfi9X+8tUQmzKUJdFfxZApqqKWe9ssd5y7AOOE1nx1NPTqPnECLrcgBcQ== X-Received: by 2002:a05:6000:2383:b0:426:d5ba:878d with SMTP id ffacd0b85a97d-42704dc76d6mr302678f8f.42.1760626090010; Thu, 16 Oct 2025 07:48:10 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:81f:9200:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29099afe03bsm32947795ad.107.2025.10.16.07.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Oct 2025 07:48:09 -0700 (PDT) From: Marcos Paulo de Souza Date: Thu, 16 Oct 2025 11:47:54 -0300 Subject: [PATCH v6 1/5] printk: nbcon: Export console_is_usable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251016-nbcon-kgdboc-v6-1-866aac60a80e@suse.com> References: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> In-Reply-To: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1760626083; l=5226; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=QMt0fN+cb78tcvpLQc3o5RloIrix2FlLCC1yGpt3I4I=; b=NRQ7aPWDBXwgjWf8kzj6nWwUxPP/cun+PmQb9kihr/58YAw811WRbq5jWYgnmdqN+0xE+2fSf jV3VU8HjDYFD55ddbpW2JtPq6PAqIMM5a7s++d5UtcibNsHmo+ZcDlr X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= The helper will be used on KDB code in the next commits. Reviewed-by: Petr Mladek Reviewed-by: John Ogness Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ kernel/printk/internal.h | 45 --------------------------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 031a58dc2b91..1fda485ec2fa 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include =20 @@ -605,6 +606,48 @@ extern bool nbcon_can_proceed(struct nbcon_write_conte= xt *wctxt); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); extern void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt); + +/* + * Check if the given console is currently capable and allowed to print + * records. Note that this function does not consider the current context, + * which can also play a role in deciding if @con can be used to print + * records. + */ +static inline bool console_is_usable(struct console *con, short flags, boo= l use_atomic) +{ + if (!(flags & CON_ENABLED)) + return false; + + if ((flags & CON_SUSPENDED)) + return false; + + if (flags & CON_NBCON) { + /* The write_atomic() callback is optional. */ + if (use_atomic && !con->write_atomic) + return false; + + /* + * For the !use_atomic case, @printk_kthreads_running is not + * checked because the write_thread() callback is also used + * via the legacy loop when the printer threads are not + * available. + */ + } else { + if (!con->write) + return false; + } + + /* + * Console drivers may assume that per-cpu resources have been + * allocated. So unless they're explicitly marked as being able to + * cope (CON_ANYTIME) don't call them until this CPU is officially up. + */ + if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) + return false; + + return true; +} + #else static inline void nbcon_cpu_emergency_enter(void) { } static inline void nbcon_cpu_emergency_exit(void) { } @@ -612,6 +655,8 @@ static inline bool nbcon_can_proceed(struct nbcon_write= _context *wctxt) { return static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) {= return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { = return false; } static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt= ) { } +static inline bool console_is_usable(struct console *con, short flags, + bool use_atomic) { return false; } #endif =20 extern int console_set_on_cmdline; diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index f72bbfa266d6..7e3128ec9336 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -3,7 +3,6 @@ * internal.h - printk internal definitions */ #include -#include #include =20 #if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL) @@ -112,47 +111,6 @@ bool nbcon_kthread_create(struct console *con); void nbcon_kthread_stop(struct console *con); void nbcon_kthreads_wake(void); =20 -/* - * Check if the given console is currently capable and allowed to print - * records. Note that this function does not consider the current context, - * which can also play a role in deciding if @con can be used to print - * records. - */ -static inline bool console_is_usable(struct console *con, short flags, boo= l use_atomic) -{ - if (!(flags & CON_ENABLED)) - return false; - - if ((flags & CON_SUSPENDED)) - return false; - - if (flags & CON_NBCON) { - /* The write_atomic() callback is optional. */ - if (use_atomic && !con->write_atomic) - return false; - - /* - * For the !use_atomic case, @printk_kthreads_running is not - * checked because the write_thread() callback is also used - * via the legacy loop when the printer threads are not - * available. - */ - } else { - if (!con->write) - return false; - } - - /* - * Console drivers may assume that per-cpu resources have been - * allocated. So unless they're explicitly marked as being able to - * cope (CON_ANYTIME) don't call them until this CPU is officially up. - */ - if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) - return false; - - return true; -} - /** * nbcon_kthread_wake - Wake up a console printing thread * @con: Console to operate on @@ -204,9 +162,6 @@ static inline bool nbcon_legacy_emit_next_record(struct= console *con, bool *hand static inline void nbcon_kthread_wake(struct console *con) { } static inline void nbcon_kthreads_wake(void) { } =20 -static inline bool console_is_usable(struct console *con, short flags, - bool use_atomic) { return false; } - #endif /* CONFIG_PRINTK */ =20 extern bool have_boot_console; --=20 2.51.0 From nobody Mon Dec 15 22:07:54 2025 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83353343D9C for ; Thu, 16 Oct 2025 14:48:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626097; cv=none; b=JsqslvQDLivRefHnz6bz8KhCRVaWYfApKgzxKs40jqaO0UkMLTclW6Yly8XzQromHABI+dmVp0RRhUor2rSE/DreB2+6UBkbYMUBxJwc419z45D/TkFdymMAJ3AXMv8j5aLYpx+7qXID6rFBUZ3B4NQ9z+KGt9kaiwfOV/z5AGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626097; c=relaxed/simple; bh=4W7ciJQ7V9RRE3FTBU3fr2wHSfQFLn6hAcKzHmMsRsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QOtp2hQO+ego2aX8YIBT7YeAZjFJ+n2r7WyTYqlVgzFMCYnQZXPtXQE/KDYW+nVI0C1mymJOy96yh1G2IJKPPUR8yuCx3xM5JGGvd5uBLjeCRd3YFGlhQ4fr3stkyln8BYe21PUnTh01H0nc+ac8WjlcUGrv2V9BwBieeF23yaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Z+TKrbBl; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Z+TKrbBl" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3ece1102998so669254f8f.2 for ; Thu, 16 Oct 2025 07:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1760626093; x=1761230893; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2ZwrAXHCP96cs4Mc+0ImiEPD2/MYmM0p4dOdWtxHtqc=; b=Z+TKrbBlNu8Caj2X7kgeS864fLg54N0kVSG+JJ1ao5x/5P+SpwI4DStQ/eG1tp2uLX JDozA2HFFDQjn+SlH83GHmTyUFgk66akIxbQy3v1pqx5C57+L7UeVWAsydEWWTwMs3Qb Ax1t8OW1HBF18uJtumsTcrWbn0ROxH6Sop7XoqWi+n1bNn8rLVzSfIQMxGjJrVzpH/3K 3UzKdAFrXft9VZmBvQn7SKtFvm5pov3zd/CDdIzBWzhqoK3B/aMp17dqz5rSolDxUXqR hiLkwLW5/Bw5BJJGmxx+RUZO36cmQ62pXhxge4W7k7oFKJ8eykD3vh5QabHAF6q51lyP DQEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760626093; x=1761230893; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ZwrAXHCP96cs4Mc+0ImiEPD2/MYmM0p4dOdWtxHtqc=; b=FLFpVeyyuhucxd+wkC45SAUyCFrfdHO96maMPMKsZIHoLypO/gwNq08xR2hCJWZCQd wgKHO0blriigS7j9S6KWVmJqvcC9+MIDb8i1t4Y9gfXpG+bpzu+16SLqKHcEdCeizm5f M15elbEGeASub8w2V+EAM63qSetSHbnPihhDPJEg3YontRvfdHyJ9MeVQhxuMMn3MhXU vLfhy9joj+hBY8AnW32m4m7H92TwI8CtxbT7ZvnldZ505uXvjidp4GQdhOP1Qb9tH1r/ R7k6/IRhGABgTpfViU5gNhliakQwpqv6UiU1QMdNj15aCYa2WaHeSzmU9KwR1psk/tiK O80g== X-Gm-Message-State: AOJu0Yz4eeYOLzxwdIJUE1Vr0NC/vLpSjsopd2lBl5wKO50pPIjkC5Rc 7DxXwB/PLDhHvGnL4y78OOJ5d9+btz/p/bCcFl8QGXNyKMxmwzZRtbiR0U5eNTnbG2A= X-Gm-Gg: ASbGncshXpNVrYq5AbPo+sG00YziigXhLXmw0j0Uzv/sIvjAq4avnxltjMQYLDR/NrC TfHxdd9njUJpTshAY5A0NSTWjS2dgAxuV/eNT0VrK+5iYXL1jhVf/VhrirAZH0uCLdzalsKcjoA lk8f2bITyCQLtDY5POJTFcTkQJ1XoShdXWaihAjHcFFnhtj07+ToO5QlME8RnjYnYcEwrL6fAaX RIrwFkT2gFttNsGrWww1zgM+ZIaYX6LranopUgYwhOdO45C5h910oUxhf1CFngeIajHavM+PvBz Cs9hTD/kqrYB693AIOdvW1Sxtsh8tSumcTTKa52YA+SMEck8THXNabGAfaCE+MSW8hSm6bqLEU6 EFmsrjss/zye6k8RVbcr6W/oziWqmfPCLOsuKcbcpKVQJuLMHkwdO7nFu2BfuSVwUxtbe1zQHpH bgYxnCFPY= X-Google-Smtp-Source: AGHT+IEYgAP06AR1dJxuLPdg471qQhscygkPBcFY+U2P5o7ClVB8NBTl8D/larHzQrhIzIteTE+Krg== X-Received: by 2002:a5d:588f:0:b0:3f9:6657:cdd with SMTP id ffacd0b85a97d-42704db5d5bmr324975f8f.38.1760626093557; Thu, 16 Oct 2025 07:48:13 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:81f:9200:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29099afe03bsm32947795ad.107.2025.10.16.07.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Oct 2025 07:48:13 -0700 (PDT) From: Marcos Paulo de Souza Date: Thu, 16 Oct 2025 11:47:55 -0300 Subject: [PATCH v6 2/5] printk: nbcon: Introduce KDB helpers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251016-nbcon-kgdboc-v6-2-866aac60a80e@suse.com> References: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> In-Reply-To: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1760626083; l=4583; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=4W7ciJQ7V9RRE3FTBU3fr2wHSfQFLn6hAcKzHmMsRsU=; b=dbU3IXzO8IodGPdGQIFZpS2KWubTjTk6Jond439VVVIUyV/f1QWWbZZX09u0lnjT5MPdvkCWW kUJ209h252aC58122EUsBo2D6HRqQCjHbyjTxn6gIMCbuhTkCGOPzUW X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= These helpers will be used when calling console->write_atomic on KDB code in the next patch. It's basically the same implementation as nbcon_device_try_acquire, but using NBCON_PRIO_EMERGENCY when acquiring the context. If the acquire succeeds, the message and message length are assigned to nbcon_write_context so ->write_atomic can print the message. After release try to flush the console since there may be a backlog of messages in the ringbuffer. The kthread console printers do not get a chance to run while kdb is active. Reviewed-by: Petr Mladek Reviewed-by: John Ogness Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 6 +++++ kernel/printk/nbcon.c | 61 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 67 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 1fda485ec2fa..0d589a933b6b 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -606,6 +606,9 @@ extern bool nbcon_can_proceed(struct nbcon_write_contex= t *wctxt); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); extern void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt); +extern bool nbcon_kdb_try_acquire(struct console *con, + struct nbcon_write_context *wctxt); +extern void nbcon_kdb_release(struct nbcon_write_context *wctxt); =20 /* * Check if the given console is currently capable and allowed to print @@ -655,6 +658,9 @@ static inline bool nbcon_can_proceed(struct nbcon_write= _context *wctxt) { return static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) {= return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { = return false; } static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt= ) { } +static inline bool nbcon_kdb_try_acquire(struct console *con, + struct nbcon_write_context *wctxt) { return false; } +static inline void nbcon_kdb_release(struct console *con) { } static inline bool console_is_usable(struct console *con, short flags, bool use_atomic) { return false; } #endif diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 558ef3177976..e1bf5409cb6b 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1855,3 +1855,64 @@ void nbcon_device_release(struct console *con) console_srcu_read_unlock(cookie); } EXPORT_SYMBOL_GPL(nbcon_device_release); + +/** + * nbcon_kdb_try_acquire - Try to acquire nbcon console and enter unsafe + * section + * @con: The nbcon console to acquire + * @wctxt: The nbcon write context to be used on success + * + * Context: Under console_srcu_read_lock() for emitting a single kdb messa= ge + * using the given con->write_atomic() callback. Can be called + * only when the console is usable at the moment. + * + * Return: True if the console was acquired. False otherwise. + * + * kdb emits messages on consoles registered for printk() without + * storing them into the ring buffer. It has to acquire the console + * ownerhip so that it could call con->write_atomic() callback a safe way. + * + * This function acquires the nbcon console using priority NBCON_PRIO_EMER= GENCY + * and marks it unsafe for handover/takeover. + */ +bool nbcon_kdb_try_acquire(struct console *con, + struct nbcon_write_context *wctxt) +{ + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); + + memset(ctxt, 0, sizeof(*ctxt)); + ctxt->console =3D con; + ctxt->prio =3D NBCON_PRIO_EMERGENCY; + + if (!nbcon_context_try_acquire(ctxt, false)) + return false; + + if (!nbcon_context_enter_unsafe(ctxt)) + return false; + + return true; +} + +/** + * nbcon_kdb_release - Exit unsafe section and release the nbcon console + * + * @wctxt: The nbcon write context initialized by a successful + * nbcon_kdb_try_acquire() + */ +void nbcon_kdb_release(struct nbcon_write_context *wctxt) +{ + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); + + if (!nbcon_context_exit_unsafe(ctxt)) + return; + + nbcon_context_release(ctxt); + + /* + * Flush any new printk() messages added when the console was blocked. + * Only the console used by the given write context was blocked. + * The console was locked only when the write_atomic() callback + * was usable. + */ + __nbcon_atomic_flush_pending_con(ctxt->console, prb_next_reserve_seq(prb)= , false); +} --=20 2.51.0 From nobody Mon Dec 15 22:07:54 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F9B334575D for ; Thu, 16 Oct 2025 14:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626102; cv=none; b=RWUrmpmbH6RpECrrs20fJhxdYntPPs56YICl15dzMjor2300d5AS49RZcMyclr1S+zosD+yNhACWth23v/hL7ajv+Slpt6ErpNgtVuG2OdzFA+cqXpItsBWT6xGPwSu0jN4CRAs+DxIe21l1bcthvftPbi6XMCNgKjV2A2PcIZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626102; c=relaxed/simple; bh=1gtg55A6q6fYqQYhYt7iNdCwJ9yE+ZwzkgpLqb9S7w8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U1hUo5Vry8vKPuyuK0LWp2mwYaoSJYSZUPDDfxsXVa+3iLITUdW/0WgIyDB/dd+1PSb8pmGUELY0wi6l7wJyBhViThOBt5xZvtJ5smhYk9zaj4tZ/jRC5cdo+ZUw41k21HU5zFVLvQxnSbB2pdyCqczBtGxoulNjYzvMQTdk5mk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=OFsfHcKs; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="OFsfHcKs" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3ee15b5435bso583572f8f.0 for ; Thu, 16 Oct 2025 07:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1760626097; x=1761230897; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CIxAIlLH2WkPghxJtQLJXYy+AU+xIAHCNA8pGfVE8Mc=; b=OFsfHcKs5aedb1LOrZ97tlCLh6WK6hJclGgt79HQ3zkeRYX82BPAjLYlUzYtzWV9cv jyFqIvlUetaz+hEsJQ6YUYHTYMPDrUdnG4/YmKfCRCwA/132OvUPluX/k8VfMQdv0qdP oUbClOIvyE+m2Lq9Lzmr/dLkSBwg+GlPNyTRU8Z3PGf7glHZyh+s3OPudMq6wy6zp3pp oV8lHEPFlabE7sZGDOf1VlqMaxnLYRHQidLZX0FDzE/4NRuDB9nTuS8hCS2GaJXN4NO4 x2hTcLH6zcc93hQrL6g2EXKn+B+/eVJwMKJtzfLfKZ7kJhbwM+GJsXmzVxAKoFGmXfLZ L08w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760626097; x=1761230897; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CIxAIlLH2WkPghxJtQLJXYy+AU+xIAHCNA8pGfVE8Mc=; b=SZFYPLlTQQTxQBvqH2uWquU4HkzdUUiCHzWuKzuY7DLTVjRzsgCAeGCxx4TmrpjC3O at3Dmc8+combeQyHKj5iLWPo3uuyKBKs/dmAjY5mrSrGvm9Txbws8Kr0IFUakD0jIvNc uWJn+j+ntFBtFpxUcgUhQK3H15a2qgVjZsRkNgg0ei1yfMu+xTnfE/sy4DUnGHjkxx79 RjXnRknv+mWzwD9VsloNCotwo1Oafmuygz3uQ9eONAYdyE8Xgn0HgkpuaOVtJ4MZBLlx khOr8p2RdStniRWsDWkTFzmOXEfojSFfenxRh+6fHxiUJ/wdK+wbtVrUe0zy7EHLeMTx P+DQ== X-Gm-Message-State: AOJu0YyMuSZ23w2YyC8AGHmzlxd3085dMzWLo+g0/ZcJdEClx2xr9H8u 1g8Olhq0zsiZCh0OhQLSBPpSZQFuYs/Bq6f7IuWoVhSk2PRUb9JMh44quHA5IOTgN/c= X-Gm-Gg: ASbGnct4vEndpL8MqwBgMz6elaAcorhsfiEiYkv7cDn7uel0xT0grQgMwWnhDoqblWj F4PGhsW1WVpN5RmOcQ+2HQyhy30xYjDybn3sqHGtaftgDA83XF6zp36a4yHsUtUzzPcQEUdVRfd d03nAlSW4x4IBHKeUJgrlFKgOqA7wHvJzLewMWyuMstgy/mVm0HHGalXtkJDmGtEvlwzWXK0oAI OCBQvy4ouCuwhJmpJsl7xjeVhsoCp6WCpNQ2/CdrL2KuwaDWyOoUJhzCKK4rS88wlJ4c+gdFkmm goGMGIgWAoMC/YpzeVT/3eB19+xzKPwLnF7HZXEFpBqrKoUopRXp4+jYZgDjja9LvFEzHWr4sJX Oex+UQ+tPKBENyTJPq/YLP5RmIZO/QXa0wVFnNR+RHqI2xamqxjEZIvaqOwDGhxiTVVjC+gSebn slPy+/0TQ= X-Google-Smtp-Source: AGHT+IHmHSHNF3BYV3Uo2Nk3NIqyIqeAqZq5Krmm0v974TtwQGifmJ3M/YmEZCuGc9CDlunbtedN4g== X-Received: by 2002:a05:6000:25c6:b0:3ee:1294:4784 with SMTP id ffacd0b85a97d-42704db5d28mr275699f8f.37.1760626097125; Thu, 16 Oct 2025 07:48:17 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:81f:9200:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29099afe03bsm32947795ad.107.2025.10.16.07.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Oct 2025 07:48:16 -0700 (PDT) From: Marcos Paulo de Souza Date: Thu, 16 Oct 2025 11:47:56 -0300 Subject: [PATCH v6 3/5] printk: nbcon: Allow KDB to acquire the NBCON context Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251016-nbcon-kgdboc-v6-3-866aac60a80e@suse.com> References: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> In-Reply-To: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1760626083; l=3334; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=1gtg55A6q6fYqQYhYt7iNdCwJ9yE+ZwzkgpLqb9S7w8=; b=U2KpRJninMM0ae+wZQYBQS8JB7rjKsTHHbZ1MKu2cGffKSTkFIJ743yBfsDhNEBZf3gcp+7L6 +0UZqm/BOG7DHC0H+CFX2whaOTmoRwyuezaGhSsDrwcgNxsfVE8filK X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= KDB can interrupt any console to execute the "mirrored printing" at any time, so add an exception to nbcon_context_try_acquire_direct to allow to get the context if the current CPU is the same as kdb_printf_cpu. This change will be necessary for the next patch, which fixes kdb_msg_write to work with NBCON consoles by calling ->write_atomic on such consoles. But to print it first needs to acquire the ownership of the console, so nbcon_context_try_acquire_direct is fixed here. Reviewed-by: John Ogness Signed-off-by: Marcos Paulo de Souza Reviewed-by: Petr Mladek --- include/linux/kdb.h | 16 ++++++++++++++++ kernel/printk/nbcon.c | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/linux/kdb.h b/include/linux/kdb.h index ecbf819deeca..db9d73b12a1a 100644 --- a/include/linux/kdb.h +++ b/include/linux/kdb.h @@ -14,6 +14,7 @@ */ =20 #include +#include =20 /* Shifted versions of the command enable bits are be used if the command * has no arguments (see kdb_check_flags). This allows commands, such as @@ -207,11 +208,26 @@ static inline const char *kdb_walk_kallsyms(loff_t *p= os) /* Dynamic kdb shell command registration */ extern int kdb_register(kdbtab_t *cmd); extern void kdb_unregister(kdbtab_t *cmd); + +/* Return true when KDB as locked for printing a message on this CPU. */ +static inline +bool kdb_printf_on_this_cpu(void) +{ + /* + * We can use raw_smp_processor_id() here because the task could + * not get migrated when KDB has locked for printing on this CPU. + */ + return unlikely(READ_ONCE(kdb_printf_cpu) =3D=3D raw_smp_processor_id()); +} + #else /* ! CONFIG_KGDB_KDB */ static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return= 0; } static inline void kdb_init(int level) {} static inline int kdb_register(kdbtab_t *cmd) { return 0; } static inline void kdb_unregister(kdbtab_t *cmd) {} + +static inline bool kdb_printf_on_this_cpu(void) { return false }; + #endif /* CONFIG_KGDB_KDB */ enum { KDB_NOT_INITIALIZED, diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index e1bf5409cb6b..5be018493909 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -249,13 +250,16 @@ static int nbcon_context_try_acquire_direct(struct nb= con_context *ctxt, * since all non-panic CPUs are stopped during panic(), it * is safer to have them avoid gaining console ownership. * - * If this acquire is a reacquire (and an unsafe takeover + * One exception is when kdb has locked for printing on this CPU. + * + * Second exception is a reacquire (and an unsafe takeover * has not previously occurred) then it is allowed to attempt * a direct acquire in panic. This gives console drivers an * opportunity to perform any necessary cleanup if they were * interrupted by the panic CPU while printing. */ if (panic_on_other_cpu() && + !kdb_printf_on_this_cpu() && (!is_reacquire || cur->unsafe_takeover)) { return -EPERM; } --=20 2.51.0 From nobody Mon Dec 15 22:07:54 2025 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B82F34575E for ; Thu, 16 Oct 2025 14:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626106; cv=none; b=QiFnlLWecvX/t7pQ3zkj2tMIq7Gg5SE/kLcOWSR2E2nTETATNVIXRKOcGMn9MAZjDUFidPF9mXFskyHurNfllhCjwK5S6ZA86CGoVOIkbN9jYviOgJXuRdPthCckFBNibfWa5DvhsNffpB+AbIPJeI7uQXer6HOtwda5IJzd68E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626106; c=relaxed/simple; bh=w4gD0M3Q/XSOw/nngXbwWx9bgWlfGjxJRzd3ChPyNCU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oUmq1tCVFzfnR9RQUY0IRf2O2jWxyly4bhedxKyu06+VvksIjNihNsO687wKT9nE5kwR8Hw71iHYzZQWqG02nQegn5jgfwwgUqd4q1OeE9CjlsO7ms2EyzbE+r/b/qowNjga3klAUDvjrrFWNulY4KhvIzOYth39v6HIGj0nEFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=HGx/OlzI; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="HGx/OlzI" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-426ed6f4db5so1210375f8f.0 for ; Thu, 16 Oct 2025 07:48:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1760626101; x=1761230901; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jfCWX5L/45fJp2sEG2KyRgkMyFNZ66dpS278Lbw0JYI=; b=HGx/OlzI8H4s5U1eXOYO0zrPIVdFz39liwCH7qLxcd2Cu0uqJdPvBtUzLjhNc++qNe SmlEM38CWCm38BfxGVAvKh0/25BPF+T8AEsmJzWLsb+MjBJckFAJMQZDs8feuMR4txqU 3EtP3Fpm/FHpcMliBI3Jw+qTAd6I/nERum9Cszd9UYplgQv7rVGqoYvf45ytCsA/6FVo 0yvaNUcU5AE/TTbMLbhZuudfhjcsOTBb/iwrH6CazCh4qZYYRN+0D1y/I9aIg2y3Hv7d LZAIMM+Pn5oVUq3E65g4gJ4XJs7/NtBRQI/+3PCh/75DXSvxx/gIwVlS+mrz1A9+6Fu8 eEdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760626101; x=1761230901; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jfCWX5L/45fJp2sEG2KyRgkMyFNZ66dpS278Lbw0JYI=; b=ROlDYHAvbIerYnoRmKTWSPshAecb1sUC2KdttmUqHx/x+mtJYZlB06PYWHdn3P6NMr c1Txkp+3uEXZqVDa7l1JRYsYcu+ZgtdK6W64Lx8dVEk+/XHHfpaBfBP6HQxLDgXE81rS VQj/gS5rAmV085SqqElmpN/hHn8TckCHQhGsdVxj/WMaIsbcu20YWCiK5cpDhMHmluFO Bqq3R70riSVdq2iQzH2Q/L5kh7FtzoEpVEgnRViUusBpOikilIgHQgc1a+lv/g5wTte2 RhAKRiM/njMkZI3Y7uFyfmMaFuo79RTT3gdOFYWgknpcl1oA8VrqCDe6QGBgPjxPvlzK oAOw== X-Gm-Message-State: AOJu0YyZ7PzdiA7ar4Pb1/xz3ZyZtssMooHL7FesFeOC3eu73UlSE1w2 4LRO3PMnG6rzdOYR5S1mtlPnM2LXLqMyhQ6ZfXDsLo+aU1Bm9OykAzzVRTXbgxHXvdU= X-Gm-Gg: ASbGnctM5wrcM+tRf56PFUnriAhICJ6W0uptfeV/IggzpFUfwBUpwiH9rgKm3e8b9f6 M7idgFSTRQcru7EhMWduFuQ496FCYFyUfjzEtL4s5izWea4+3HvNVI10N1B95f7N2ecHZxtly+L tdaLFghlkDNbllt2zbO2sD6NnsebkrlN9Fcqzp4yHmAEZlvokzst6PtY0KbnoLYtcEPO3T6kn6y dyDoGbP2jBkDLcO+2QA4pHAMSOjeKZWnNr6bMBxwRpWz7WRIg1TDzfSlQ9J0N5fRpSFy4W97Y+r A3TXrCeT/3Uo+e35tYLgbaouq6Nv4ksmsCnRzb9VBev3//4sRNEVBVcwxvRvI0ROLhVVKfmWJnt z0ebo3TgsuOFjTK2Xw5NsrVS/jokpGV9lpfWgdeoBbwPgNrumQuFVaOJqIEKkqwx9DwLer18z X-Google-Smtp-Source: AGHT+IGo4Cc39I4nG0TJafwo9a7Xh0M7RgPDDdK38+wx36MPX6UKlkPJY4aUzlKdaIdl7azK5RZkUA== X-Received: by 2002:a05:6000:2089:b0:427:521:134c with SMTP id ffacd0b85a97d-42705211378mr179936f8f.6.1760626100623; Thu, 16 Oct 2025 07:48:20 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:81f:9200:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29099afe03bsm32947795ad.107.2025.10.16.07.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Oct 2025 07:48:20 -0700 (PDT) From: Marcos Paulo de Souza Date: Thu, 16 Oct 2025 11:47:57 -0300 Subject: [PATCH v6 4/5] printk: nbcon: Export nbcon_write_context_set_buf Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251016-nbcon-kgdboc-v6-4-866aac60a80e@suse.com> References: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> In-Reply-To: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1760626083; l=2693; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=w4gD0M3Q/XSOw/nngXbwWx9bgWlfGjxJRzd3ChPyNCU=; b=dZo7itqbk12g83O1fhCyQdj0pIWugmoj09SChDZC69yIlg7d6dpLBkG10GOymxcJOcVZ8wmZe FWgFREMMqR2CxzMWI075Chogqro1oX6YKizm7mW2YL0RNJAInC3OWh6 X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= This function will be used in the next patch to allow a driver to set both the message and message length of a nbcon_write_context. This is necessary because the function also initializes the ->unsafe_takeover struct member. By using this helper we ensure that the struct is initialized correctly. Reviewed-by: Petr Mladek Reviewed-by: John Ogness Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 4 ++++ kernel/printk/nbcon.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 0d589a933b6b..81d2c247c01f 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -603,6 +603,8 @@ static inline bool console_is_registered(const struct c= onsole *con) extern void nbcon_cpu_emergency_enter(void); extern void nbcon_cpu_emergency_exit(void); extern bool nbcon_can_proceed(struct nbcon_write_context *wctxt); +extern void nbcon_write_context_set_buf(struct nbcon_write_context *wctxt, + char *buf, unsigned int len); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); extern void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt); @@ -655,6 +657,8 @@ static inline bool console_is_usable(struct console *co= n, short flags, bool use_ static inline void nbcon_cpu_emergency_enter(void) { } static inline void nbcon_cpu_emergency_exit(void) { } static inline bool nbcon_can_proceed(struct nbcon_write_context *wctxt) { = return false; } +static inline void nbcon_write_context_set_buf(struct nbcon_write_context = *wctxt, + char *buf, unsigned int len) { } static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) {= return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { = return false; } static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt= ) { } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 5be018493909..fdd1cbebe77d 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -854,8 +854,8 @@ static bool __nbcon_context_update_unsafe(struct nbcon_= context *ctxt, bool unsaf return nbcon_context_can_proceed(ctxt, &cur); } =20 -static void nbcon_write_context_set_buf(struct nbcon_write_context *wctxt, - char *buf, unsigned int len) +void nbcon_write_context_set_buf(struct nbcon_write_context *wctxt, + char *buf, unsigned int len) { struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); struct console *con =3D ctxt->console; --=20 2.51.0 From nobody Mon Dec 15 22:07:54 2025 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B799534BA4E for ; Thu, 16 Oct 2025 14:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626112; cv=none; b=OfCFplgutomL6vbSX3tVTsIKe8+XN70jD5Mt1LrKRl790p3KqwJpuULQeiYpfg96y9W/84Jo6nwoqEINuyNrz7+zFt5de0HoSlsxk851RwpH4yWmd3Qbfr7ew/VNlL/N6zfRvCORO2MFbs3cczPYcyp74XxVm8RQ+Tc/nBQq+P4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760626112; c=relaxed/simple; bh=Z9P5xcvbpTnJxeGz7KZPPikGSxpPD+xoc+k6to82yJA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eWO1F7otmdZYs1IdDKNCscf6pMZ6xI0gvcK+WHXR5/fDX0NRQ19G5jV5XYQ1pjlHBALgYSE8eceXZc12HDBnOY1D8UW+yDlMi27vUZA/j2RIcTB2Amn3TRqwjqZK6EvbqzTP3dt79AEN6vBppSrseTmhAwask5bOSTBuKvnApsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=G1FVdEjE; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="G1FVdEjE" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-421851bcb25so485249f8f.2 for ; Thu, 16 Oct 2025 07:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1760626104; x=1761230904; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=I0sO08yiEnLurERgKve9iMIdfZXEHm1ICclZZWjRlKY=; b=G1FVdEjEkDhixX2aMbwxR+YvoYYJZqanzS8Z6RQBzO+tNoKo5RUdR+sg0FINXe2AuS Y9llKXE9Vfz+MXVRxIM5rNkGHNyZ7/anS4t7VUMkh00+YAsaio9+qf+5lz79lf7FV1m6 D37aCJU+YAnXFLnZV39COrtHvP6K6hXZMWevxurwo8041lyzsvQ71LU35Y3imGvDuyOK bvB8UbVfJx7vqqotphqfhZ3wVxgi1T+ygyDjdO6mQXLI1nnXiMI4LUaRP/XF+iOj2UrO p3lll3cl3vzwQ0qtSh0Vd7XyIZusO60qQBV4buDpaXWHP/BzW7R5HlkSNVTWkYDrwhrA yESg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760626104; x=1761230904; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I0sO08yiEnLurERgKve9iMIdfZXEHm1ICclZZWjRlKY=; b=TWYjoxEGeW+LJy9oam0PSZnAtJZ6Ca87nhhRqgcHJdXCWoGE/zVX2iaMklfBCAKkgO ABbq6DXa0f1T8KnI6PZ9e6+imRJim/1qE0Zc8ZS2r6H4Qn0HPw8squDVITRpntz9QD4v 0xU5us/+L98f1v8pepRhXANWRyUcaGna8+TY3VJqmRw7OuUbT1FPM2jtIGbpTUGK8EF3 Wr99AT+l5nh6RBN2pc9UG8AJcFfByWnFqtVQnhgGrJF78qN2NqHBo2rBtEDd1boj6Ncc qxWbmnVEU4q46IM1D0oSyoZrHlquVQUtGE/Gz5sowRwCAmD/Nd1e7szAMskku2oJoS8H mAVA== X-Gm-Message-State: AOJu0Yx784tVpWGImAUA4PFLDFsrB2AQVp213De3lgYAPkIc2DmSG9mw sYUk7xvJFPxUbFermf4QY6scD+GUMdgrWg6jZaODH0KNDmS5Xlr8EEHfR3hw7ZM7Q1w= X-Gm-Gg: ASbGncugMRYwDrvtKSFlBMjNvAJGTa9bAp0sJXMRveXeNxZNk/5Oa4xzhyXFZjoIeWK 7yFBeAWd4CjmrlRGxss4VgHa6hte9rh14mwLLwIq4CShOcXHDvhLKdUhJT0ywprAtsdVo+RR8jo sa9ZLSanV8UKh3axm1gxn7f7xKDxqFl7upwl4PJ+t/Rzunu7iHOP/lFNlASI6MQ/wfccDIzQztX OvLubJ/eEHT9FuUHYR6XrAUQAdd1BwUjt7HU2rmiNAHejjxldadPldXfahLvAl2HiJ9RHSkghZl UmCdzBz9DsYjpi2wegcfmiZIdyppEg1LtEksP3U5I/yABLeA8UuyBNERlwCilKGu5wls6cn1oRT zxO6cs2tlouyqQ/xvKIAkh+QOKthI3pLF3paWxNnVhbFVX0kW+1+BpMMMoPMrhIQ+c0FN3H0C X-Google-Smtp-Source: AGHT+IHnk9pbg0pNj+5jfkNWDhm3iigyZ6RX54/ZD/vVzsGzmPA9YsRX1KZ8+fyQCNEFMvNTW6Es3A== X-Received: by 2002:a05:6000:2512:b0:426:d589:2633 with SMTP id ffacd0b85a97d-42704d993d3mr355598f8f.44.1760626104177; Thu, 16 Oct 2025 07:48:24 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:81f:9200:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29099afe03bsm32947795ad.107.2025.10.16.07.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Oct 2025 07:48:23 -0700 (PDT) From: Marcos Paulo de Souza Date: Thu, 16 Oct 2025 11:47:58 -0300 Subject: [PATCH v6 5/5] kdb: Adapt kdb_msg_write to work with NBCON consoles Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251016-nbcon-kgdboc-v6-5-866aac60a80e@suse.com> References: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> In-Reply-To: <20251016-nbcon-kgdboc-v6-0-866aac60a80e@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1760626083; l=3159; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=Z9P5xcvbpTnJxeGz7KZPPikGSxpPD+xoc+k6to82yJA=; b=G+geV9gPFaBstxo8zAKrM3CPumHZxftSTfFf6nrMv2jIIVrkq40CdwCb7XDVxLyZBZjxpWsBA /p1tBh8FTePD0M0mbDBQxhq72eVE+C0Bcx9Hxc8Zt14Vluzjzwnss0K X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= Function kdb_msg_write was calling con->write for any found console, but it won't work on NBCON consoles. In this case we should acquire the ownership of the console using NBCON_PRIO_EMERGENCY, since printing kdb messages should only be interrupted by a panic. At this point, the console is required to use the atomic callback. The console is skipped if the write_atomic callback is not set or if the context could not be acquired. The validation of NBCON is done by the console_is_usable helper. The context is released right after write_atomic finishes. The oops_in_progress handling is only needed in the legacy consoles, so it was moved around the con->write callback. Suggested-by: Petr Mladek Reviewed-by: Petr Mladek Reviewed-by: John Ogness Signed-off-by: Marcos Paulo de Souza --- kernel/debug/kdb/kdb_io.c | 47 ++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index b12b9db75c1d..61c1690058ed 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -589,24 +589,41 @@ static void kdb_msg_write(const char *msg, int msg_le= n) */ cookie =3D console_srcu_read_lock(); for_each_console_srcu(c) { - if (!(console_srcu_read_flags(c) & CON_ENABLED)) + short flags =3D console_srcu_read_flags(c); + + if (!console_is_usable(c, flags, true)) continue; if (c =3D=3D dbg_io_ops->cons) continue; - if (!c->write) - continue; - /* - * Set oops_in_progress to encourage the console drivers to - * disregard their internal spin locks: in the current calling - * context the risk of deadlock is a bigger problem than risks - * due to re-entering the console driver. We operate directly on - * oops_in_progress rather than using bust_spinlocks() because - * the calls bust_spinlocks() makes on exit are not appropriate - * for this calling context. - */ - ++oops_in_progress; - c->write(c, msg, msg_len); - --oops_in_progress; + + if (flags & CON_NBCON) { + struct nbcon_write_context wctxt =3D { }; + + /* + * Do not continue if the console is NBCON and the context + * can't be acquired. + */ + if (!nbcon_kdb_try_acquire(c, &wctxt)) + continue; + + nbcon_write_context_set_buf(&wctxt, (char *)msg, msg_len); + + c->write_atomic(c, &wctxt); + nbcon_kdb_release(&wctxt); + } else { + /* + * Set oops_in_progress to encourage the console drivers to + * disregard their internal spin locks: in the current calling + * context the risk of deadlock is a bigger problem than risks + * due to re-entering the console driver. We operate directly on + * oops_in_progress rather than using bust_spinlocks() because + * the calls bust_spinlocks() makes on exit are not appropriate + * for this calling context. + */ + ++oops_in_progress; + c->write(c, msg, msg_len); + --oops_in_progress; + } touch_nmi_watchdog(); } console_srcu_read_unlock(cookie); --=20 2.51.0