From nobody Wed Oct 1 21:23:19 2025 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 C46572FF16B for ; Tue, 30 Sep 2025 17:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252916; cv=none; b=ndBBjvVhLqsr9JtAAXYdqLSO/ZtOJFB+0R+sNIjDPbqkbe2Coxu6bFJTjSZYroIWTZtMISlmDKPIjDM1N41+2KhRJH9+Y/YsVNALwE6LNmiwMR7ImWW6DKXIP7UjfxIadzxl136nwJw0kNF2KR/9xGrWCbfty0QfxT1fGVcfAss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252916; c=relaxed/simple; bh=DLgwsYfhwZac7dA2TCtSOnyXfy8NPK0sFcv28xWn99c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c70Bkrzkky3fBFoangYulWcFfu/fxWW8LWAHPF/6aF+MJlQIhoA8nTGadQOgT/3RdeFq3zmuzkm6+bgVKF91Cn5FtaQMmzER1nEl7DtAjgPzcIV8WVPqbP1UYceddDmNBDbKErDAXlPg4/Jp60MpQUMEGc0Oqw5C1qjRm0kClHI= 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=attz8GDj; arc=none smtp.client-ip=209.85.128.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="attz8GDj" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-46e542196c7so755215e9.0 for ; Tue, 30 Sep 2025 10:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1759252912; x=1759857712; 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=Ftkf2tVv2xSCZP+ZYXEg9krsVQMLMgcivCtabJh2XjA=; b=attz8GDjJ2L3vZF1rd7VWcEi39IR4pI0Xu/mVNNGkKkgKlh1JgycXuW6BYclS1S0FZ 56pKsuIAp+3MZRpN5rgUOH8wH8wVimwhj4MPUUtdJVjST7EtgD5hBeEelRSBejoUtc2G N18j1wXHOxntUe9FB/vd/I9gfMXF+cqnMZD4y1wb8E+yjwK9hF79WR1a0YA2mJKlZ/4D 4qCfT6l9frhHNd9NLUuKpgGXHfmKXq65/PX+5rWR7bs34XXtx6SRVzh2tFgRMWWw2ePa ykxGsvCPM1ocOK+z21X+L9WsP8YqP6pNNpRB1rAAsoRGDXoHM4vhIGWSs1pEITJw0aWe 3qyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759252912; x=1759857712; 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=Ftkf2tVv2xSCZP+ZYXEg9krsVQMLMgcivCtabJh2XjA=; b=rBzTwZ39prW9pZ8wCvST0JrCPEJnxVwd0xfLVG6Q3VepsAtTN/em7HK54JgzLSnIuH i2iPH7m7U18GGfQ/zJ/jMwvd58tltaSXb5FvpI7FKjvF8uluh6yDDIVtDm41PtMz8kLp jtAjtT9pzQZHl5+T2dakgQ0kGzBQh47LeEtidn85/Gn4eNdjeV8WwlKE29N0JrUUs/eM H/6HwN4O0bn6Gw9w5VQnSexPYa+dqrRO7BaealheVinUQ1eQ9vgzOt1o9UmMcKoZ2IO8 lAmuZW7gYyFGhFAr88puVYCHIAJDCWyj11CtwOfcwS0tnZo6X+YJA10jwSKcYyacb0TG UCng== X-Gm-Message-State: AOJu0YwM14WKHMxiJxRpfpIDErREkpBZ6H+z6xITbIT3nWsQ0Bz45LIj lDsf2oTTdnkQm2g8lozHWLG7+YcvtcRVCB7PY1Sd+liuPRAcQGGaFw7hjmC8gL3jY04= X-Gm-Gg: ASbGncujxQo4zxUZbProCEur3FxISko1f8wFraItRRYPuaGvh5iDVzjGZfJ8ynX4EKW n+spZAU1Og9wg0JVdNciGecxKkvlxcQNXcYtR+KFLXQJs/jzB5auqYAAzUQMt7YYjx6891Uu2Sp +wnXRhcfINBWEtjwkbTV1mfv3WC1dkGFTFczwiQRD2UfPn/u/s17ax5Kz/Nq+NdpweghjfTBvuS 4Gl+cWtMtixlCTqq/d0lkrGMq5/yZDwAsldwOprIXI2G8gFUroS4vup7JNuaqIKqBUMeXXKY4xg 3pMLCYGOQt+HCsTIrP4ML6O/gwkVPg2uF6ijefmyzcVW9zamoBbJVPU86ij5XWrdI8q0KtbNU3n Kq1AQv61k0BmPhbqnWGVq9szFopOvx3kTy1Egwshx24lpUWMr2FrpHCvlPOCnfavOeiBJt3M7ur lzNwhF X-Google-Smtp-Source: AGHT+IGppjyvyPoYLUYqi5E/GBPLAWTf7DaTMD9ogcW+uXjdE6+YxQyMDm9UTCYl9oxXT/grHSsTeA== X-Received: by 2002:a05:6000:40dd:b0:401:8707:8a4b with SMTP id ffacd0b85a97d-4240fde589fmr4786131f8f.13.1759252911973; Tue, 30 Sep 2025 10:21:51 -0700 (PDT) Received: from [127.0.0.1] (88.36.160.45.gramnet.com.br. [45.160.36.88]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e61a17a0dsm2459465e9.17.2025.09.30.10.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 10:21:51 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 30 Sep 2025 14:21:07 -0300 Subject: [PATCH v5 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: <20250930-nbcon-kgdboc-v5-1-8125893cfb4f@suse.com> References: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@suse.com> In-Reply-To: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@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.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1759252905; l=4883; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=DLgwsYfhwZac7dA2TCtSOnyXfy8NPK0sFcv28xWn99c=; b=um2prxMnW/LVY0jlAgoPfFZ6Sf2tSDxxuIIBDv9lNxesBFlhm093g4RpNtMnYEUGRrT/0IC1u cEUkYouTNvGCIku7MRuNQRFfvTyfdf66Fl36hs1rVoU7llMoaaSGLQA 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 Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ kernel/printk/internal.h | 44 -------------------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 8f10d0a85bb4536e4b0dda4e8ccbdf87978bbb4a..67af483574727c00eea1d5a1eac= c994755c92607 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -605,6 +605,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 +654,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 f72bbfa266d6c9bbc533661c40386aa5f0df6c8f..7238da161ff9814fe8a22e48366= 24e50ee5b71d3 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -112,47 +112,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 +163,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 Wed Oct 1 21:23:19 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 E00F318A93F for ; Tue, 30 Sep 2025 17:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252919; cv=none; b=TExh8LRjDyRX/knxwVNc+cKW97alz2mg26Q0zKtY7ZM+t3zJpDp+SwRsPen3twfeEL5NvoemzOXO6sI23ULZfYnVPgwfMrbbBq6DbdKDggokRHmf7IgpNyL30VYuFYZQeD1LFGlUfbiQnezBEFdfDV+c0MtkkuIEQEKwkZsrYFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252919; c=relaxed/simple; bh=A3hmoRxz9+3hsHn91K5rMq+MYDBREGaN/U4eB2Zs/HQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oewV5lvPCxxQcgpsLzyKTgZUyLMhboxC+nauB3StpITkuey5p/phfmFslg9aiYFGfeIqtC777lq1rrwzTf5ywKCsOlYADi6DO8PphuJS4Nb03htKnPedvkuuqNTiVTj+5hhitS3HZoKi8wdbfo5atGRetqsCLfLpLPPlaDb5+U8= 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=TZ2CGv4D; arc=none smtp.client-ip=209.85.128.53 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="TZ2CGv4D" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-45b4d89217aso41065945e9.2 for ; Tue, 30 Sep 2025 10:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1759252915; x=1759857715; 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=HdnfcsEyqTgX9MfItj7Fuu94KdDUV1/v5idkdjyPpFo=; b=TZ2CGv4D5fua/InE9MeZdMgVW5GQZgQV3sFYTczEgmWL/rUnyZIjy6QWbFW+Ogsp7H U+XRgkhyyX832SZCbsXUTsOpAZEcTUpHUPhHToBP0Fc6nq3f6Z5GSfoAz0VaB1V9ROpA 2rEifQoprMlAgBWT441HD1X2BsOSJlQ1sgZ8TCwXIQ3YbKPP57352DmInVE18cmt9NhW DJ3i3YC5OjSsQdYeg2DWnmSCoULPi9NXk22o3vxOBBepKwEiXQ24oxIy3YTKmjgldVoE 6/CAhLQUxA2wF+4bnNGc7mJhVOALX/SGFkiQdh6za6/WXAkz7fi6SQzAe1SYm4zA7/I+ Dh2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759252915; x=1759857715; 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=HdnfcsEyqTgX9MfItj7Fuu94KdDUV1/v5idkdjyPpFo=; b=e9aToh7SKtNTkR3Cef+RIDO6NutpSaK/JVJhlI9k8dFS2ckKgfABVeTybi1q8tDiBM X5EBe9DCxLOXR+pxbOG2y0NmUty2WMcm8UvOgQiLpmelyNKquATm8xnUUK2SbFv0nLT/ VMZtrJE0OGumVr6i/PYudYzsO0AdWvQ4TVVnQNlSDZ6Ym5//cIbAkt5zQyLgXmpw3Wv2 xQOm4/4Ga7UZ5CDz0YF9ZhCmZgZ9gwUXbmPjUlS0K24Wk5HoVUcB0TqViGlVAKLSgbOu 0XYcF+IFSpHc+mGoaG90gD9cj4ZSIkflDqekU55vz0gAXxWId0E2BHJ6V/Bg7SqfZ5MZ o1iw== X-Gm-Message-State: AOJu0YyYYFefcoEkOK0F8kHOFSLAEsP2n0VRcpohUygWBsSw4cm8DTe3 CsA2o0fk0jvc5qk93/Y3hi3n7p47URTSD8xuSCy2gUxpZ6P9ZAe+MyEJQ+nOnJp9TIs= X-Gm-Gg: ASbGncuC/thUFWeat0FhmUbtVic2rmi6P/jYOynN+oXUK6g/Zmo7IFLlB+ZWEeorlHl ZQ7CjwzvsFZjPZqfvBzQXvmFHl1MTSdh96l+s7j089eNSV5VGvwgmGMDGzJJkWhGmm4QKfOgLhK NQ0LgePukOdf1EuIIorOXSITcVskPX/BiBvsJAGaYKvgjZN0n0u6YVw5kl4boFNjkCZywVVhHgd Vha3Y5CvvY2snS7NY2UQJacB/veiHy/QXDntmNPV2HLOX0Fmz3S4gYR3ZNBIrv0La6ciBcyImPn hEec3IbLc8nK+5Eep8EIQCBmYJ5qGqtGzmiegPrPBb/GQFbyfT4VBHnKn2KZ3FvLdaIjGBg2auL Wayda4HJ8lO/dnDlGOtrc2q2CLj8z7mab/CTD8NFG7mKPNyN622WLaoN5pU6tV0QyIvf4Og== X-Google-Smtp-Source: AGHT+IFmgBiS1UL82y6u6hi2zoH4rTC6RPOuQxMDlFHnY+ZoDGp5SEAvVOcgnGZeMsIqwwFjTxHosg== X-Received: by 2002:a05:600c:1912:b0:45d:d97c:236c with SMTP id 5b1f17b1804b1-46e6126a662mr5417495e9.21.1759252915275; Tue, 30 Sep 2025 10:21:55 -0700 (PDT) Received: from [127.0.0.1] (88.36.160.45.gramnet.com.br. [45.160.36.88]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e61a17a0dsm2459465e9.17.2025.09.30.10.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 10:21:55 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 30 Sep 2025 14:21:08 -0300 Subject: [PATCH v5 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: <20250930-nbcon-kgdboc-v5-2-8125893cfb4f@suse.com> References: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@suse.com> In-Reply-To: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@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.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1759252905; l=4882; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=A3hmoRxz9+3hsHn91K5rMq+MYDBREGaN/U4eB2Zs/HQ=; b=EKmxyrKT4OFERXGWQmYUzKh13DtHdD+KGhy3scNKnf2kqccu+uo4mzWOBRDW8MlE2VywGKf5h RJmXpHHrUv/C7d9KgoEkRZldKsrk1h3K67vEmBxREh10IJn9j6nyI9k 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 Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 6 +++++ kernel/printk/nbcon.c | 66 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 72 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 67af483574727c00eea1d5a1eacc994755c92607..b34c5a0b86303e2fb4583fa467d= 8be43761cf756 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -605,6 +605,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 @@ -654,6 +657,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 558ef31779760340ce42608294d91d5401239f1d..c23abed5933527cb7c6bcc42057= fadbb44a43446 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1855,3 +1855,69 @@ 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, enter unsafe + * section, and initialized nbcon write context + * @con: The nbcon console to acquire + * @wctxt: The nbcon write context to be used on success + * + * Context: Under console_srcu_read_lock() for emiting a single kdb message + * 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() + * + * Context: Under console_srcu_read_lock() for emiting a single kdb message + * using the given con->write_atomic() callback. Can be called + * only when the console is usable at the moment. + */ +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 Wed Oct 1 21:23:19 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.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 7FF332FBE16 for ; Tue, 30 Sep 2025 17:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252922; cv=none; b=f8jcMOAGkEtCAqFpOOjj2RvGE6YmKc8gDQPqR4I7vdJ9FQgp0SFoj+ZuZfvVwRI34nffTy4YFOGzloJ9rSRYNxB4jOjWLQ2J8lN9HtUW/2/6ECQ1nwOJlOiornaAXL9XnBTKFJnW2dnPkJ2foayC88RxCRL213hehDi4UOAmhG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252922; c=relaxed/simple; bh=ibgKtleGddQNNgCtzt0Ilfee0hjVtNcwD0tKiiu4HR8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Me26pfSPnJ+xVjdxU/w95PMFb12MurkEIVszzDtkd4IeAGRMNAI96gTAZilBMdPciYctYK68V9O3YI+T0SkNEUEei3gmzKoZi20uwjT3fauwUcnxz4BjaL5VfKq1hWIZMfPogtJTy/q9znob/hk+LHpzLImLs8A5+xJSrGSM4Pg= 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=bKjRUnX8; arc=none smtp.client-ip=209.85.128.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="bKjRUnX8" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-46e3af7889fso36747785e9.2 for ; Tue, 30 Sep 2025 10:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1759252919; x=1759857719; 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=q/JHX8hQ6J2JNvKJcwR9e7CWvf1mvN1dNFPy1HSjY60=; b=bKjRUnX8TV784Rh7C0MPBSEWW6p0oij/8pmH0Mx9T0gyvJWFcwNxGHWbCMRN8ey4VC an6gaAFT+uH2PNE1UWeRkyN1YioWN5H14X/VIpGOYbTxkkzNRAkVXo2LwH1qtXhVQpl6 4B8WyVBhlkEHaeGf1JLvKpL+lvHbtnmdxXzTjc0G/dF6t0xJXs2ogHAbPdASsY/vsIma xNHFqSN9LyApm/UWTT8rtO5XZYWUReVSET+FNgC1ipG3UaUoAgrmk0l62bnC7MHQyped aMLAYqGe3kRnBiMUvwmdUGtzgntHuwDdUyzYqsmvnRDQIw0ezgveqcM2BwTUFeb9EGTO fTXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759252919; x=1759857719; 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=q/JHX8hQ6J2JNvKJcwR9e7CWvf1mvN1dNFPy1HSjY60=; b=E1sXyeaFdJ8byICNNC8DbZem1Z1GZCxAD0aGG/ORxTnRJ43ZGsdyyjLGMNrqM7kog2 8k8RMEgyp5phsp+tTv8Ke0LL6L6pZpHbDEZbA3T68FHD35VoqNuj9WRk1ixyBkyeDl/6 oRgaIDEaopi4Qx+iaucJAMZkG4lTiucCkTfN66pRs5Wk8O2miObIP5Yr0jV0yHfC8EXM TsTAT9mBuWgXAQXD+tvexlww3g6wap+uGVfr67+ywxvE34H/V3VES8M69Kntb4irGAj6 QP6q6tzb2QfbYzoKZA5a/IZuak6FxNCLJ6dK9VD3xbVge6Vk18AuU8eGi+1oLi5dBfUm GHqA== X-Gm-Message-State: AOJu0YylCLIdPb6uGfNl4bCgkjxcGuvmtzeTu+Xo6O7kg0IFL5y018ak bz1NYJA+CiA0QkmICk/fXOko4CZ4JTR9o5MVi/cyQv81S5MIfipRMx5mdkDuyWfsfzU= X-Gm-Gg: ASbGncvPOt8hkuQi6naJ9QTayzy1vnIafudwbsG9Gg14p+xFxsLTe4o5kISvllSaFFu Fj++YKMqc5HW0SQR5T2J4uLqWopBzNhl+CH2J0qcQ0ZKGdzjFrmeKPwbfiY6nIRphgEOAQwNivv N/mKmZOtN7q1ahdxCtSYWjTQqzDTAMqifsvEC6zEVhVf2UpWeI538a2JmrqN8sAeHCZf+4wqXGe pl+54n4Oy16MXDe7R3Dpx2K+QVKRbP4kiex/j2g38DY5GiaQ2ySMehHteDfJyR7xFSmhea+GxQS gTmyDVVUN2+FqX6+BRanmBn0/ISadRSYJ3+nhvtHE1tPWLIlaOsHYJxT5kVFgkHdBRyZLuFiIxe M6QLx/BW2JE+xmj41CSR6asI3GSdVRJeIBIQelkjypK0KdHkrWedY65UM/FS9o7somGB+MZ6CqB d87zfS X-Google-Smtp-Source: AGHT+IEI//gAdpmdg72DS3miwlWKBIpxB/Jy0Pf275A937m8GRKUvUi6OGUpg+qdz7IkdcItagOvHw== X-Received: by 2002:a05:600c:8b8b:b0:46e:1c16:7f42 with SMTP id 5b1f17b1804b1-46e6127dc4emr4989045e9.11.1759252918851; Tue, 30 Sep 2025 10:21:58 -0700 (PDT) Received: from [127.0.0.1] (88.36.160.45.gramnet.com.br. [45.160.36.88]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e61a17a0dsm2459465e9.17.2025.09.30.10.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 10:21:58 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 30 Sep 2025 14:21:09 -0300 Subject: [PATCH v5 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: <20250930-nbcon-kgdboc-v5-3-8125893cfb4f@suse.com> References: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@suse.com> In-Reply-To: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@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.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1759252905; l=3158; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=ibgKtleGddQNNgCtzt0Ilfee0hjVtNcwD0tKiiu4HR8=; b=j+AGEj6TmAPGZVFRoAWgYOJ0dGmVgfloYMM7xrQSYUF7XplRNe9oRrGgmQTN0Z8UHKyO3E39z i64d6h9h5TpAEv6DpT+i01waCHMVDmmb7sdci1BV215+YlO0R+eL7Gh 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. Signed-off-by: Marcos Paulo de Souza --- include/linux/kdb.h | 15 +++++++++++++++ kernel/printk/nbcon.c | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/linux/kdb.h b/include/linux/kdb.h index ecbf819deeca118f27e98bf71bb37dd27a257ebb..36b46c85733fe1df28cde7760e5= c26e96de40c05 100644 --- a/include/linux/kdb.h +++ b/include/linux/kdb.h @@ -207,11 +207,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 c23abed5933527cb7c6bcc42057fadbb44a43446..6e4641350fe8985438f53bcd32f= 3adf72d9d6835 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 Wed Oct 1 21:23:19 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 E697630CDB8 for ; Tue, 30 Sep 2025 17:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252925; cv=none; b=L5FjrrrOXh7XdW5Six7kaqmIroY3IsFC1arnhOAtLLz0Sc6Ctw0mPD3eAxv+OCd16d/LSAwu21GIk1W9seSLslfxdEOygrRk3AE5Hqk2jW58xn5jUe8qfFVdZJ+Kd9HA+bSPYmaSr7lt7CnJznKCrw24yLlSMv9HYYfZDGw/fsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252925; c=relaxed/simple; bh=GFEUQIJUCkmPFCCykSE+SQS0O7PhGUwsWOftaDX6dYs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bmAp2BYCOEDqAqHMXOxYqJv3uS2N20UESuisuHJ5dmzgUfrsvMSyhaCyAOsy5jVuOlY/A021jyWajO0tGoNK5wg/BUJ4XOxdIpSqsMSgL5ePXXgbrrvBn7RnaQX93wMR2J6fqUof4gy3w1jJj2MH8bWAEDbmxR40PLfPHldQQKM= 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=B+dKGYhu; arc=none smtp.client-ip=209.85.128.47 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="B+dKGYhu" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-46e3cdc1a6aso808705e9.1 for ; Tue, 30 Sep 2025 10:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1759252922; x=1759857722; 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=h9dKhQXGovS1oeaED9pOXvi/m/Bjh7MbLIiNntfgxDU=; b=B+dKGYhuwsDe9mTLv3pd3s4es69ryfY9AbHk1N2vPrOia2kQ89hGqPLyggl5crrzgH CYjWvlUcok3v+1oV4hgxPOuloeJRIt1v2P/1Hign0qa4Q0d4NhCOWXnBTMMfx5KaSZC1 3oQB1K/To40bmMNi38HhAawT+mVozwrBufNO7GPwRvtmafLfnJzU/NOWieBe228reoqR eWHL1+VS2VTDwHcW/EvyiSvubo7rBQu0HrB7hvCR02san0VRGTDkJesRKd1cH/wx0FPv T+IOBWlVT0a1CZYlAX3eK+bt69TUvJAIU4ZZh7qatOC0zN2zau7d+pUHMAhG8qV7AA5l DRnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759252922; x=1759857722; 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=h9dKhQXGovS1oeaED9pOXvi/m/Bjh7MbLIiNntfgxDU=; b=MR1FRnquMKFaHzokx+lHvFObc9zorLBd0EcB+4CYnXNTuUT4R+7thQixAmwJYXNMQD MUc9vSDRS51/gQnxyzT50OpAK3eZAvXgsTm4BftQE9fkNwe6S3vwXS68Kr0GmfbPPL47 u439U18kH9/YnXySWLIktGmuA9XZzPyi/2kNzTLNqoecb2ygnFAqJnMgoFPw0zv1gLv8 SfncVXoVtSO+R/TqPvg1XLzIucpwqbNPC+s9uJiozKflrKpKtnFMkfzzQoXxzjAeNLOa jgFxxTUOiodUZdh8IhaoUoWQwdccE9l30melIJzyv+UldyHv9Iu05la9Pua6/9ujnXdA opow== X-Gm-Message-State: AOJu0YyUTZmao7hyvvxZ0PZXaLCogzJXfo6aMGuqpGO4s+43QDbafh+Q xg4jOLn0p+cWgPUKFWzaTQHwSrMKoDADHSBBILAaChLVGKlqGCvzW5R415fPMbfV1jc= X-Gm-Gg: ASbGnctZBloEq7rbwoB9oLJHP1DAb7WYGSEut4+hfpUMl3kDxHxEgMA1VtwpKRvk6C2 u7zpU9cuX3WGa90395glFOKZRR09ceoB5s1TERwbWSyfeJnwobKN754zaEZX1kl5a4hcAonyais jX2/X9q+ot/D+KHyn0dq4+Z+CVl7Gqw6tXwIiurVT7N20NBoXf0h1EdKWuPhUag2j2e9YbtVhg9 /vyrMm69EKyNJjY4RmnIaEMLN+OHqgQFKNOEuDkMJ/weS0L8ln67EBishwB/Vi737DEdkAC2tMJ 4gHfYKryIrOzfwVPUn7NHQFn1THPl5QhjgfN1pN3xdbpVHtm2Aa/iYqrrLqtNvDhS7w6DMgdKSZ haDRmymV/Ie/zl1Ro4E6i7A6LnDSGUSCzW0GuitssvCk8rm0sG3vy3kY5stM/EQuWLSOIFg== X-Google-Smtp-Source: AGHT+IGc/NKF26+LZgWofl7aRSsll1HM8ZP90q7bmD+iyDXEN3293SZ+SnTVd9LCf7IaiSBF0ffaJw== X-Received: by 2002:a05:600c:4815:b0:45f:2b0e:b835 with SMTP id 5b1f17b1804b1-46e58ce0e22mr30359725e9.10.1759252922138; Tue, 30 Sep 2025 10:22:02 -0700 (PDT) Received: from [127.0.0.1] (88.36.160.45.gramnet.com.br. [45.160.36.88]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e61a17a0dsm2459465e9.17.2025.09.30.10.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 10:22:01 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 30 Sep 2025 14:21:10 -0300 Subject: [PATCH v5 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: <20250930-nbcon-kgdboc-v5-4-8125893cfb4f@suse.com> References: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@suse.com> In-Reply-To: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@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.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1759252905; l=2672; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=GFEUQIJUCkmPFCCykSE+SQS0O7PhGUwsWOftaDX6dYs=; b=pWgf2sGREzN+vcWhVnIUx1xJEgLE/ERGoDb8uj5i/w203YIEwWIF4ZVYz2irbFcYn4GNXrx2S TOepELNeoVsDl2vpibyVqNPnrQAdW7wQwSeTdWSzgT0EkZSchA9RrPj 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 Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 4 ++++ kernel/printk/nbcon.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/console.h b/include/linux/console.h index b34c5a0b86303e2fb4583fa467d8be43761cf756..e0fc2608bd9d6a886f5ddc56d26= f19b21ae8663d 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -602,6 +602,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); @@ -654,6 +656,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 6e4641350fe8985438f53bcd32f3adf72d9d6835..2492b14bd272562378c4cdb465e= ea2269638e127 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -854,7 +854,7 @@ 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, +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); --=20 2.51.0 From nobody Wed Oct 1 21:23:19 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.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 4FCA330C600 for ; Tue, 30 Sep 2025 17:22:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252931; cv=none; b=kECLqFpVOPkqYNK0EA2nHFrIqfEL3BsxpUMHoCj1woBXNnmLG0/sETKtJJwa/gMb+ZTw1RgLJr4PuybOUGaoFLmP8vBxvbDcnzalBpSUIeXJhaNynmyhMELRt95Xr0HAvQmOOWHBmTHKSoUFbpkviINdNs3EoBmShgKjmmWb8o4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759252931; c=relaxed/simple; bh=ygwUX/1tQYNO8Z3SG4OQhTz6XDitcn9QQTD2XNDaWnM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cf8BVKZO841ObgSRJJJdVR5qAVDxe1uF/jXCLQjVWvMIiKwomZSXLg9S+dRhyzNVRjGNQWyB5GIyOd7Jj0YjZ294KE68JW6ltm7fzWpjNg4UM4hj7r32z4MBn9iH1pfgqJfeyS0nopRJZxWcKFwElysjUN5S/raH2TVvcPWqOUE= 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=Zvd+J7jT; arc=none smtp.client-ip=209.85.128.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="Zvd+J7jT" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-46e414f90ceso11384525e9.0 for ; Tue, 30 Sep 2025 10:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1759252925; x=1759857725; 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=aLcpX2pmqFVTyeyKqISxLvLObbz2xb7M6zZbF5c/M0w=; b=Zvd+J7jTQxIXBbFVBAYjBLCFyOuawf/75RRdvoywV6FFxNOpTq70QLkFn2KEevWFPg C7jK+MWyFwJSERSHEUNF/XUZMyMKk4hTRZIVUX92+BQ2BPsbY1mqQx3FPlVXyN7/YbCT soB7nDCACTI4Y8wI/A3vGcm7WLzMPm7SFltIqPipk2UPYu75d3CWB6Xt3kw7ekyejRKM W6pfT00VqT+Rrz+SFzwz1BGaYo15x1Sg5xqyQ3kx87oib2kJhb7EHwhPITgrnZm+8IWn xn8tIfBfjG6iJbkj/GkKcvygBB7YFoY0HzeHSMCtJ/Ybr1xvMrurnoFM/WYi14MW1bLL 5kwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759252925; x=1759857725; 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=aLcpX2pmqFVTyeyKqISxLvLObbz2xb7M6zZbF5c/M0w=; b=H2PNKoHPy784XHrj/4nGj9XT3GBrIkaH9iKBPfyDiLgxr52H33lLGDo7tl+MdZKDZa 4ut99Ncc1pR8/pPVHmgOI2u/Gy0grIfe3QwVsYAMzezyX7eO6PKo1tMmV9EBPhspO4wo Y7hU8U9s8yDfl3kbf4daRFQ9WKYhd0hFIjygclIAesUeC4LhT8unavK9Lev48dkcOSYw /CfRYmJ8VCSQn7RwePTknEAc4rvzSVU5TtylUGnoV1uzblcopuir/LGXuwZRI6kE+Jq9 R7aleDwTZTudiIzNwx9PtiUSRv+tEzJXN/lu8Rv3DDldgxqXAQOx5CC9JM0xBOvPlPzG D/hg== X-Gm-Message-State: AOJu0YzeWqQJCwzgT2eThljCwieKdahSdH3s4FFX5zRNeNMFqYC14KeZ ZRgUaKnNsfTH2mE1dwiIH6PH0GiqqoKXlsc0p3eBQ93/rY2htM9TnxnExOsZOO6K5Ys= X-Gm-Gg: ASbGnctnWqJppgNuF/qB3jcTUrGEszRiXiCiTYn74tlmjVswb1Qm/jrIT123ZApu6bt 4y0q/9GQB8VgiPVt6M8SEwrw296CG3qTmVkZNJDm4vMPl7pryogtraJtyb5v8yy+VMtCfWEBX6T Fh9JzfJZR6pTCsLuHeglCKztvuttgxEKG0pwQsUr62x4U7DPeRBStpIFYxEYflOTBGAs2p2t9qx 2IO/RADhzb4H2WWGVjOm2HlZVszi/UqoQgxrpwzYwJNLvIjuMrA7B8TvpLAiUTVsBRSuJUL0Zq/ RBEwnGqGAx5YwGZ3n75Yjr3vKmUYr2D6v0UCq3Gmaz22C2/W10nqueV221YEhKVwp6E5102rzVf TErCMcySVt2FYTqeuGYwMs0xrHO2fFkcRH9dITV9dG1oGOQ2d9d76gOITxfNmMUGn2f4tJA== X-Google-Smtp-Source: AGHT+IE6+GIKVcLHfdesBGw0a0n3RqOmAcVF/EI842DFmf+4JhKX+V5imSFpFavv7JiYyYzgPEqBMg== X-Received: by 2002:a05:600c:4e52:b0:45b:7b00:c129 with SMTP id 5b1f17b1804b1-46e612e6f9fmr4823605e9.35.1759252925439; Tue, 30 Sep 2025 10:22:05 -0700 (PDT) Received: from [127.0.0.1] (88.36.160.45.gramnet.com.br. [45.160.36.88]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e61a17a0dsm2459465e9.17.2025.09.30.10.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 10:22:05 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 30 Sep 2025 14:21:11 -0300 Subject: [PATCH v5 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: <20250930-nbcon-kgdboc-v5-5-8125893cfb4f@suse.com> References: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@suse.com> In-Reply-To: <20250930-nbcon-kgdboc-v5-0-8125893cfb4f@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.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1759252905; l=3161; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=ygwUX/1tQYNO8Z3SG4OQhTz6XDitcn9QQTD2XNDaWnM=; b=X3rMY7ZtKq4g6XYCM3D20/MmRpjrwKyQV7cX9mB1G+W2N1cnhvHvBaIRhWKRsckS7OO9hEphp b+DwAK11c96A2o+6UZA3SRCfN/cC4qpjDrRxOliSssscTx5Yl/AMnX2 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 Signed-off-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- 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 9b11b10b120cf07e451a7a4d92ce50f9a6c066b2..7f41ce5d1b4b2b9970f7c84d8df= 40d13c9e9a084 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