From nobody Thu Oct 2 15:34:38 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 664E12FD1BC for ; Mon, 15 Sep 2025 11:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935247; cv=none; b=Wk04pJcExJ1yizKh9av/dmk5oZyCErO6hNK4beQPfETQr2ml7xrJ0l27zrDwyw76Gjp9iduSeDhjL+QVuSgdwxgKcAl9hAXYD4GjZvoIoJ/g/Sl9fiJVCGNfo1Od9u4tGCyJc7F6tNneY1/BSm4uuLkWWCOCWh1Dimj2Zrh2GBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935247; c=relaxed/simple; bh=uSwsVcx9vRLURJakPGQPHCsZ1IwrO5LIgYvBgpZcp6s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TK8NO6/ZU8SOqKqZ0MIilZHpGTgKqg4Fg218zSriXgOsBQfOkhnDlhI+4qsr1G6XAFBphb3v5+j1I6lQDLUeAEoRxf0XwUnfqzLm2TohnCxR4Feuv2bHxnXROOjnTsFOcIJ4dZwycRSnF5RzLfJhWdAs06YtjI2HZ8jqXzBhSJ8= 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=f/Kc0t9R; arc=none smtp.client-ip=209.85.128.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="f/Kc0t9R" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-45f2f10502fso3718225e9.0 for ; Mon, 15 Sep 2025 04:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757935244; x=1758540044; 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=IMeqCqBAZa7/mzPAEgv5VH6k7D/J9H6aV4yDqPBtdaU=; b=f/Kc0t9RtrGWB+wldfHHoDETcgJTBwIxJ9Xqea4vcFdd+//JRDXNo1Fp9p6QEBw4fN CxsRWO13OrZ8jd3qZxTKqmMsGxKGrpU4qaTCLGqoz9iQD5KlW7lttKMAEbgP6aLuaYSD jaduGV9QSv6xefUrDFR77qXnx/LLrofrm+pC5oNyBNY+5lqLBiCEUCnm1Mm/JIVYZAqM 0Cwb6Z7rUAYCjZVE3and1G6tZtb7bqm0lgKat0ZZkbAGTzKMdobgovJQdS5XL7vRhgGr g46XlfpmFuXAEmQN91A8FmBVsNtRT6piPoYCFqNE6MQF+tlnJMqed/8POOph+xOj98ft gRIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757935244; x=1758540044; 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=IMeqCqBAZa7/mzPAEgv5VH6k7D/J9H6aV4yDqPBtdaU=; b=wzP0yRG0wJ+NHHJlBtye5vot4EIcX7cLpXRDc1wdLn/SnzsrVviPj40ZNafaIpikIf pphe30RmKLqX7UavfRz2/CkBsAs3ni44mJb1/qA7E9J5njM1BHmJ0lNgI8q0zsx8Mely 7W0lRu29kFhKXZou4HDaazEUHssJ8iCgRcjZ2EYsyJsVCLKVg8gY7yzM/rPp3QJ7qF85 XOn5TwvLspap9xxFPMUvpsh1A6t4nE1KFU4Xwl0g2qiHWXZMTrZF0PlCjcxjEW2DTzTl knEyZpnDVWkOAeRdmdqyJJ510dBxDb4pZfuY6zR0jzr/YZqcxmqOpljnhoMjuP0ZUyDI tIKg== X-Gm-Message-State: AOJu0YxkUpkt8SUFqzAwjJibFHnB27H58RIQF/c8TI5UvdQqfEwCxIla CEUgnXqKc6arqxyahninTwDYCsaiV7sq60IUItTk8BfnsYrKtE4QrtojxUaDY3NES08= X-Gm-Gg: ASbGncuIe4ppOcxDwemGK7gkJW+3spdo2x65VVgQlDWwiXkGpOWRULrWfWaGn6owrD9 XM20I9D4P0Xt9p4mWn/zOy+LKgXDlSMXFgQDPa5GU/PNv8d+QYi0L90QRiJT9sohfdmnr0RgdJj f3ckSmGntbZ7jh97sLBugscB8MOz7C03ZPO+19QHkYBLkKVm7EVzTPP5BMH0gQAXY7Vb6hWwhjK ossZ6CRStfCBU57DE4+QE4EO0puqLdOKcy97sR6wmBrT1EndL5KFS8FsyQZOJoVTOUfta/BMvS+ Z7qxbgtUyzK1M1RbNcNgtkrzbBk09TS0pUJmEnys7eACn5j+3LMqJMgVxS4iJMOpYk9+Viun/b2 KIpBHEPJO8+WnyfH0asRpX70eZ8/glzM+jBtUb39KQkaMfEc8 X-Google-Smtp-Source: AGHT+IEHWi7WL8OdfYfER15vRP6YDLTZUO0QyXbTtSufDMqi88cUTTjWU1lz1sk+b7vDTZ57C7XvuA== X-Received: by 2002:a05:600c:3505:b0:45f:2843:e76d with SMTP id 5b1f17b1804b1-45f2843e9dfmr63919985e9.4.1757935243486; Mon, 15 Sep 2025 04:20:43 -0700 (PDT) Received: from [127.0.0.1] (210.37.160.45.gramnet.com.br. [45.160.37.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e01519f67sm91903345e9.1.2025.09.15.04.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:20:43 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 15 Sep 2025 08:20:30 -0300 Subject: [PATCH v4 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: <20250915-nbcon-kgdboc-v4-1-e2b6753bb566@suse.com> References: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@suse.com> In-Reply-To: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@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=1757935236; l=4883; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=uSwsVcx9vRLURJakPGQPHCsZ1IwrO5LIgYvBgpZcp6s=; b=U5xyRJxQBfGyahplGiQO7IoISUiyX6VzLKgFWc0DdbIrRpOz+NpCynDJNnwu/zK7PCjym10bz scSEh52H1VWD32nfHu+2z4RSz9xajDKi1FZW0YKAmBvtJuc7PZIHk6l 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 ef282001f200fdbbacae3171932bf9f049037a85..bef97f2d11793191280bfb46f7f= 8b13bf2560351 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 Thu Oct 2 15:34:38 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 ABB072FE587 for ; Mon, 15 Sep 2025 11:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935250; cv=none; b=Jrmm28r6TcuQlHkSqxx8r9Y9f/uEZ7iF0VX52ruJ/42hcnAD5QBBMgcgAaMCLIa8Db/gF7YXhiJWmhKNZBc9CJGqKrLpK8/VtSmSmx7HgyIWTEgpRio/TxTrx94ckQa1yULSQFiLO1wvzC8H7oMyb2hfzGy+Xr48UnfAomIrHgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935250; c=relaxed/simple; bh=wjvht/yPMwra8hwA29QVWh/qPUkmI/5GG7pvtVwux7M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XKm/nq4aCXXoFLBJdvJKXbaCxhLGMiYya4utFcelt//BwaxWCcXrhzt+Od02TqFGf06A9LiJYyy0+RVsERBsq1X1Js2bkIRjSmfyXTb3XU/Tk9hDlfXfxBb2LFSbC9uW28tZTgAzkseMbgeCAkvwmprFmJ62dxmA9JGgt8XbGME= 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=XumsmAzt; arc=none smtp.client-ip=209.85.221.49 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="XumsmAzt" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3eb0a50a60aso573195f8f.3 for ; Mon, 15 Sep 2025 04:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757935247; x=1758540047; 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=x1PJALyJ3qcEXL7gRw/k9T/2UVdjMGD0bdFK5ZSQn5U=; b=XumsmAztYIAjv0MMawedgTkIrSCQ6gQkSob5YlAGyBBdx8YmluQwBOZlJEwFtErwUB 7PPRJpK+cUkPGP6vkbFCO1qLlRAxTGcMoazM6h681j0mmtU40jHWIz4rDagQ7CLLp+Nr ai8O4dY3PwQsEkFIC1Ud3ptViP4JvDC5/23vCYOJ/E+HkYEpaO3cNIKK7JQhpyMD2Pj4 jhU073cUM2z/5GYgdh+EtKb325ZznY9Ov5W3qCrvFUKeV1bCwGijgoBZYLeVu9GB3YCT gIuN+4MTKQizX2DzGCcJ6tyZOhM5fWdLsEv8Nao0tQEOfarLKXSx5750PbHvkhe4Ul5I TicA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757935247; x=1758540047; 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=x1PJALyJ3qcEXL7gRw/k9T/2UVdjMGD0bdFK5ZSQn5U=; b=k92qNJejeQV6QKsjN9uXq0i1FeqLspoZzkpDmJjj9Z8FzZrUPWShyA0PBbCv9dhEdx OLDgk+J4b5ajuVDUOnVf/IHtoI4r1/QFpQURkX12kXomN6DOoTvCz4VAjdV2bkxC2RZl 7X13ppMDhmsVHyBbUdYUX+OISP+cDMLbTHUqrLvQrG3SEvrVL/0MjP2ZuPCiXc6tx2Dv U+b2bS9C9Cjki/pLHE6PV+qlMG+BmdLjvVPg87E1ShNIWCh5XShMd4IrnQdLvOkMsBqW cs6+sjuz+bLFt7TBG4FgX4aWTNUka/QD4LbLhox6aB+9bb16RudJAeFQw5FhP7v4rw2j RPHw== X-Gm-Message-State: AOJu0YzEbeW3P5ZcPaV0wbWGPk3y1IZa0UUQIZzkMqYzbpwq7jDeuWHa yg01DQHIqLHfPDVanp3pb5754FpXhEeyZKlpCxTiIxKSLqRd8qs/d9XvF5jC86yCsQA= X-Gm-Gg: ASbGncsDlAfxI8DDmu/FZZ+xSpVwhTNUlZkbPU3/9zqy/sEmpoZ5ABuw26efLNko2sX m4Ie/NLcZpSov+db97dXUJdypQcUWCLud+kAV8VKWA+8zhlkFutqMlLlGf6kkQGIqqTR1mJESx2 s4S3lHl3ZEUd5+ax4owfeEZlESh3cF3vxjuojMcO8gAIdd+IcsJjuknjOAR7Hju3N+uLGq/DkGL kQlgp+9tPPp03blfgULV4CpPOJKIlRozjWuJl4KtDNiSXi5Swh81vmXdPpip++GQGI8e+vPKfh6 RZVYN4Y6N8sJGf5tYC32RE+KX7XOlbN0yTIZy9ZyE4bRboxnFFqA7jrUwhptMLzIthgFSTaYgzH QEeMxzpDHyL0hRcsqg/S7cJrp8jA8YwiD/G9P+TN1DUQdhdNvJPjddh0IsAk= X-Google-Smtp-Source: AGHT+IFtpARcVg8vrxstM4b9k81RNhg6aJgqNSrrhWUa8dkwLRcJgVAqZ42reySIf4i/YnsCfavAbQ== X-Received: by 2002:a05:6000:2313:b0:3ea:6680:8fa1 with SMTP id ffacd0b85a97d-3ea66809518mr3588229f8f.12.1757935246882; Mon, 15 Sep 2025 04:20:46 -0700 (PDT) Received: from [127.0.0.1] (210.37.160.45.gramnet.com.br. [45.160.37.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e01519f67sm91903345e9.1.2025.09.15.04.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:20:46 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 15 Sep 2025 08:20:31 -0300 Subject: [PATCH v4 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: <20250915-nbcon-kgdboc-v4-2-e2b6753bb566@suse.com> References: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@suse.com> In-Reply-To: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@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=1757935236; l=4837; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=wjvht/yPMwra8hwA29QVWh/qPUkmI/5GG7pvtVwux7M=; b=S+4E1bP7oQwnkigM23tacsltmvI9jBIlJ++NpBZzlgtJahwBU9G9d2aoD8lRC5nalPqz4bRax 33oc3OYd24bDoiBUxw+q1oXIqpvIfk8yY/Ns/cVoJ6Bx8sE63yiQYUn 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. Signed-off-by: Marcos Paulo de Souza Reviewed-by: Petr Mladek --- 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 646801813415f0abe40cabf2f28ca9e30664f028..ff218e95a505fd10521c2c4dfb0= 0ad5ec5773953 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 Thu Oct 2 15:34:38 2025 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 F1C802FD1A6 for ; Mon, 15 Sep 2025 11:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935254; cv=none; b=VfAEH3sO7O14qJ2JuuPWWJJQ7ZzEZqTTYnBi+oHoYbNzlztqqFmp90/uo/H+qyzTfxozgYaoDGO+Zph0V6evXCYCRul4H+zmm5jJ/juYs+h5MJMobJ78myDXgBqjz9eQr91Nn7ZUA1cAluj1ctDeBj2bpyASr6fb04Hfk7U3XHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935254; c=relaxed/simple; bh=1ZJkclrLq0L8xExl+pZv7kQNadVFoXUXwGQ6z2d35qc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KNAHHvLpxHxZ/qL+jtMxOhmGEh6TwLH33zncMwXUEQFwGzUoMHJ98m9xtQZ6gJ+DaTd1I630Gx0iFyzM1oVHJNtSqInyqiKtSw+cNKheyhscZYnOFa1cTSWf/BrdRkEsZpmOrtECHb15QpY3gHnjiijBtJuZKvpswXevDglLeMs= 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=Hx51oz+b; arc=none smtp.client-ip=209.85.128.45 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="Hx51oz+b" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-45f2cf99bbbso5718645e9.0 for ; Mon, 15 Sep 2025 04:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757935250; x=1758540050; 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=PmY1cJvfVrvlF04JWQNfoehkYVLSZXxvwYISJVXZfyc=; b=Hx51oz+by3OU93t6hDDUHSQ8ybKvZhUgoIHhLTcMOMZZSuvEuwb9zJf4gf5jHUjAZq wh8k+nHmjaNeYf2vW5uy6tE552dFCDlJcpzn3LUkbIWQjFgvLZJahcpssJuXg2ZSHI9r YIEbtRsmf3ghpeVsDcW6zFBXsNQxOWjdrykY/iWX8EPIW0U1HHWjvwACjQJ1ByEUtQ9h l8BEdVSSn9QcFUdB/3iKPlsSPzJE81h21cBvyMELgP+Vi2cL6Kv67sD8gmf1PdxH28u3 TEHKdB6j7URoFArgtENOwRy92/NUcwzkKIk+reVVOBRncYR1sjGr+SwyH99WvfUcv0Ae ZIlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757935250; x=1758540050; 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=PmY1cJvfVrvlF04JWQNfoehkYVLSZXxvwYISJVXZfyc=; b=skRq6DjexMc4PiYO5ptuVU7JA1YC+b6GSKxwDPA2ZCAIP6CprGPjymXlYT2MyRgwni R8+FIMGFPSdm/iK38SdPXOp+BQssMzI9jNpfNSagSwSMpwBiw374hWUUEZlv3goytwI+ VO/mL6d3aK9CuVLEtayTQVw4w6FHt/JSIUrp3MZEjVEhCd0h9XCy0pGVB6KIWIVaAWmd 7tLVVl6ztrMqqk57YPEz91KtglcyKFAkNQotRBNV5pDPc7m4/Q7230Tn4obRm6G5fFU0 i92cqqKXEvG+8ufXbaDRJ18U+/jsAapWW4otR0Zkv8JtebrQ7kRtwNGv1tXdnqDFBnPh xkxA== X-Gm-Message-State: AOJu0Yy+FZMyOwHMaDSL6WPaCnVbqP1XJZEiFI0XP8rtUaVuE+M0SMmE gjIGQHEoRJADnm3g1SHHYDVPkkI4TO53oikZFRhg2Ho8RWty8NPJrQBnfSCVbNa3SIY= X-Gm-Gg: ASbGncu4YXE039kWNGD6ITWVpBPGP1r80l1GmQMruXq8UZ4yJ33CEdeRBJF+JSCvL9k 09ZwWw1bgIV0AeoUFTsru5ZDVy/i4Qkd/kox3qSJ5xM5HIOwIe7R/KBliHOCr3ajWeRElEWjk/V TdwuBkugMaW4hF4Il/deO/wP4xRDSGZ/g4A4A3xxYACdZ0cUhQeH8h2JqsEd0h1k6oI8GgfN5Pm cHWVglEWnJl2RUjj5GOxJWNqwkSdZQj4m4oJa4TfhPHiDtwhV7U7iPvRoXyiaZ9kCWug1520c58 qD1UT4F9GLG/KVwFO+7B4YtaguEs29gET5VSCdtosHxKK7Bkhy4WyUOV0W2fViE2oio1JXvdRgd TePj3tD6DDR0tFGphRwsK2gjolffr43MvmOYzQeSluc0DZPuZSJZRID151ZU= X-Google-Smtp-Source: AGHT+IGlWfRECteUeqWG19Me150i9rjMnbdx7/D23+rW9fFbCBguFXR8IRgiSVYJDjYgD0CsbLEDZw== X-Received: by 2002:a7b:c84e:0:b0:45d:f7cb:70f4 with SMTP id 5b1f17b1804b1-45f211d642amr78363415e9.13.1757935250199; Mon, 15 Sep 2025 04:20:50 -0700 (PDT) Received: from [127.0.0.1] (210.37.160.45.gramnet.com.br. [45.160.37.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e01519f67sm91903345e9.1.2025.09.15.04.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:20:49 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 15 Sep 2025 08:20:32 -0300 Subject: [PATCH v4 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: <20250915-nbcon-kgdboc-v4-3-e2b6753bb566@suse.com> References: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@suse.com> In-Reply-To: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@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=1757935236; l=2856; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=1ZJkclrLq0L8xExl+pZv7kQNadVFoXUXwGQ6z2d35qc=; b=0pb5pcuu6eardkQEXwleqAFJum0KV7L9rVB4tEQHX+nWTaDNXo1rQ6Ap19NFW3sCW1QkqS88C r7lP/vpvhcOCLzoBGv+HqqOlqTpWGw3iPr0BDz6SYarl5io3Z83ZUrc 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 | 6 ++++++ kernel/printk/nbcon.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/kdb.h b/include/linux/kdb.h index ecbf819deeca118f27e98bf71bb37dd27a257ebb..9417ad7f124e95987caced07bc8= 684a1a6c04df4 100644 --- a/include/linux/kdb.h +++ b/include/linux/kdb.h @@ -207,11 +207,17 @@ 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); + +#define KDB_IS_ACTIVE() (READ_ONCE(kdb_printf_cpu) !=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) {} + +#define KDB_IS_ACTIVE() false + #endif /* CONFIG_KGDB_KDB */ enum { KDB_NOT_INITIALIZED, diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index ff218e95a505fd10521c2c4dfb00ad5ec5773953..8644e019e2391797e623fcc124d= 37ed4d460ccd9 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -248,13 +249,17 @@ 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 if kdb is active, which may print + * from multiple CPUs during a panic. + * + * 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 (other_cpu_in_panic() && + !KDB_IS_ACTIVE() && (!is_reacquire || cur->unsafe_takeover)) { return -EPERM; } --=20 2.51.0 From nobody Thu Oct 2 15:34:38 2025 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.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 58E1A2FFDF1 for ; Mon, 15 Sep 2025 11:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935257; cv=none; b=E5yvLdAni+Q6vR3lUPR6UB/96nr6g5H/liDkm7zuvYEcQROd1JuWDTFUZ7S1XDNuU0DUyaBuSzd3P6Sm2Nw3aFbmk9H0NWHQfgvbj0plA8gI8HOqjAp7xPkc/WiHSTLNLDu847IF1Cu3sS/n+h9HFW9xiWho9P17VSqSXLY2Mq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935257; c=relaxed/simple; bh=J3F10zRnpKnuAj4S2pqmjyaRJP49KEWPXhlxJOPQC9M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AtcdMWp4bWCXkQKArHY5WrrkGixUcOzHII9vDJzelvx0HLg2HIylFxIPp+vFiYn4g+fHX2/44mLeG5A3Dy19ijSUcEADXXRRon621bZ2eqL6LepKjSpg1iC7f79NthgM1o848/uzKd1r4i16uzAEL1dEItlzdynnoLGRRUrdy2A= 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=b4IBQ8fL; arc=none smtp.client-ip=209.85.221.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="b4IBQ8fL" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3c46686d1e6so2866478f8f.3 for ; Mon, 15 Sep 2025 04:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757935253; x=1758540053; 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=TJf/ucgzRUxUaxAWwmWGqmQ3ACFUoR+52kqOB9OiXaE=; b=b4IBQ8fLTevdx395G4Bl/w+nQK1sUY1hjLK1Sc4Unn460eQrhQvmZWWCfCocJ4QVN9 7mOgezKf6aDsTOdCCIOqktxoKbKYIbevSjXtxpkV8EFEzBbv723puLxyS5W4NIqWwNGN xXAyO1+AXAU6XfgV2RYRyXOCbvhc4jALdDovNbeJ1y9YAAALbK2lBT227C1tzBROZU24 J+38BxXg26LkkiQCx1eR55diq1SCNkyuDUbrPc3S+Fw3LHZIKiBGA1ZERfDACws5rjuu weJsZBc5c7K8/LoWt0OJF2I5M0DDrgDhyepLW183BoBBWPObbHg0M1ZM0ny9ZZh/vcs+ esJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757935253; x=1758540053; 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=TJf/ucgzRUxUaxAWwmWGqmQ3ACFUoR+52kqOB9OiXaE=; b=SO/F1Q7vuTc9HsR8erVrbgPrKfhMdwDPxVoygAv92QQantjFWnNnPw85289HT3M04o 37slc5UmVK3km6KM6C9+kZAhbDV05TYplMFUlyob8bjBBPvqEDaHO3u1QzyP7QOhueZ9 R5ytjSCBri6FYAgyNvrXejHo2xNIbwvNVN2bRyweMUVfjy4P/qJ5YimzhslpWM7pVpwF 7leN7gkte1Le/o+k1UegNILn2cIGrotoK/hP92vkA+j6dfL+5Qo58hFlWY42vSuuXnZS ZOU7WeRxmDWrmIsJrq+gUXJYMgBYGrHxlWUN1t5nTvRSOOp/NBx87OcJ7HLl82ZdaQDt u5lQ== X-Gm-Message-State: AOJu0YxHU9in5TFFhDtV+0LwJmktya6C0Y2fyFwJzkajbZlQKbGl/Kyg F7Nwg9FfNE95EBuupnpRWrYxEQ9hfzjJaUJ9OJKv4T24PTBd34umGvGWuxRv5aC67eniQQCM0mx C5nFW X-Gm-Gg: ASbGncusHINmD3TJZdVqHPZwwp1K/S6NTRGJ5hh+SfNFUGAKon4gtcaGJ5rPeei/8+4 38szRthYfKdgOaCofP2fnRwJe1BDMoTIcWOgpUCpdcWUKXIywN5FRaYoOyYQmzynj7ni7Ly42/x PjbnDtNphnVdinb1bP4OK46w/L0SKttjYYRyb2ejGIKrPdBphLGxjB3bnRiFWSb5a4Pa2HZzm5l 3qe0toNiTdXIyYZnPBlQEQheamFwp0WZPNMLnEcgUIokqoWTNpnzYtOecZUr9vLPgw8mopHUYQZ NvCiOWwZ5/H3ZXyT6kZmVnoApIUWzGF04brQGgpxCQcxSH4xtttyaexxgsEnK/VcqTRYCrbpkj3 TfuV8ejMglG1za2Pov8Dh21PrFPEQPIVEv7gqbH89pyEfYfildByfWN5HZjU= X-Google-Smtp-Source: AGHT+IGGrtsi1YVwelrA5TAFrGZsAy3Is90xfeOq5sIBAIGcA+737MLpFmKndZrCR2zuam0h1ScWlA== X-Received: by 2002:a05:6000:420a:b0:3e7:5f26:f1f0 with SMTP id ffacd0b85a97d-3e765a13179mr11188457f8f.40.1757935253584; Mon, 15 Sep 2025 04:20:53 -0700 (PDT) Received: from [127.0.0.1] (210.37.160.45.gramnet.com.br. [45.160.37.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e01519f67sm91903345e9.1.2025.09.15.04.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:20:53 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 15 Sep 2025 08:20:33 -0300 Subject: [PATCH v4 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: <20250915-nbcon-kgdboc-v4-4-e2b6753bb566@suse.com> References: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@suse.com> In-Reply-To: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@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=1757935236; l=2627; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=J3F10zRnpKnuAj4S2pqmjyaRJP49KEWPXhlxJOPQC9M=; b=h/diGfwcFJ0Z1Zp3VAuIdCk1s9ZDkC5qvQHws1jl44XvahkMmsGdMsm6U51P5yy6l2g/KBhTw uwDePS7EdyZChWYAcgdIWStX2/3kzv6e5ZmE7kymWZo3riTgqf0Yo4z 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. Signed-off-by: Marcos Paulo de Souza Reviewed-by: Petr Mladek --- 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 8644e019e2391797e623fcc124d37ed4d460ccd9..085930386d4c4accf69214d341c= 950aafb5d0b32 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -855,7 +855,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 Thu Oct 2 15:34:38 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 9C7242FE570 for ; Mon, 15 Sep 2025 11:20:58 +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=1757935260; cv=none; b=KpRZHZPzs6RhlBnujnu3cGOj/ZYXyNXPZH+v3UZgTaXpn+U5ZD9t4KdpR0Vu6ymyiYhbqwAU/a7kjw07c1SwO/yGi4ZmhD9mZVxMzpweeBacQA6/2DM4OrF/245GpQPMRUpMHtNaa/LMUHc5LMrIyIMzb9Ce5IJua2bOIVqnpPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757935260; c=relaxed/simple; bh=cU4lCiNjMiiGMfFUXRrB/KF33np8MWM4waFxZIq2SMc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O+hyNl/dAwt+UgTi7jfARLLBtoc6lcRPJvkEWhaEcYUIGfHd+3y3C9EABjsMIJcXevuzk6TCsj5e5SCKyIUUzcUoRoz027ikAN3HZ+aoRpcuPhjOM5ExT8zQfoVeywzC9VocgKCIkvHlmWkRGgr+DPNR7US8PwXSRr6kEghPKK8= 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=LhDKdEG7; 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="LhDKdEG7" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-45f2fbdacd2so2803335e9.3 for ; Mon, 15 Sep 2025 04:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1757935257; x=1758540057; 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=yI3qfrLV7ruXbzRrQGdU3KTH5BlrLsrFDw7oSvmhleo=; b=LhDKdEG72yOIGdIG327Ck/Mg6XcTINpJacFm8oS7359+fhmjdZ5uJz5djb4C2iEwaq fWnrLztfmdriccCmCW3XaJmDqVWWZrhSB0C3sS51yhiUJped1QnghOYHP/SwCEhDYI85 Cr/DqQ5D8LcircXnZgeh3P5lA2g71AsHzFon0smnhCPV/xRAh0GCrOH8vgLiseEhvacm iVJN1tX6GTfXu7QH4sZRqUJOeD1WpwSzVl3vbP0NurlkaSLkLnG7+FRbA92GYTgO8dbs r3UNMtGcA2d94ZNQD6xFdYbl33SqKdRWRexu7LY4pF26UlWOWF61fM9cUsa+HiPu7Nhz lweA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757935257; x=1758540057; 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=yI3qfrLV7ruXbzRrQGdU3KTH5BlrLsrFDw7oSvmhleo=; b=AcBtWtT50dI9e/bcBRdI/pLqZ8LgFqJwebi4laR/TFNTJnJlH9n0Sz8ouRtUV3daHP hB08lG70ySr4qtdW3hOsfnATkqcaXAoHDcNBEVtG8A/3LW7LbHm3VEZVubbWqsSh+vPN j1qmYjQV3bgMKzfAjE9eBY6i3WDbzgoROa0GiAMoBgHL/Hfp6NbiW6iXYV98vF2+Oas9 vXKPGdiDanljqRWwhO4irOVlyivvH3v3GfVK1nM5Yb82aQwhftk9tVCoUGbJsVggYn4/ tpWZSdG9jaeq3/OTqcTCUHWwMzTy6KB6HOiybRnBsRkinKqeuI8XspDAUU4JDDZDmGYE EDTA== X-Gm-Message-State: AOJu0YwaPSApGVaFBvJnRN0fUwkNuuMETFXskMf7x6JMuZWAbE4H+DNo MmhsgECArC6itZ7KG/ClQZOeiwcMVsdw535F2KsJyoS4YlYFn8EpbXNW0Ym3zzsjNPk= X-Gm-Gg: ASbGncuvSjnPDU4KlmzPeOFq1J3gLiOYLm6J6XFlpUKyr/HkrciCRm5t3UAqMBJ6Un5 fgc/XcRsjN1X3X0cB6BOJ+S0xGdQIiMRPbL/bRJ0FihB17vBNNQ7+hMDjqviAj9UXCQondSFqXw SL/mGI/f2gllUBbt6Bl7cOnqMfSdQqysLj9wQkBdS1VPIbVAW5ftEq+UEDsrShQzvpz/wg3Q6fd F93lbX0BOgJBhvgscoqqC0dxg3awdoQKuwsqUXAZCVmNZLL3tCwCyHiymYUxQQqZQSsscYIbXfm 9yds3Pmx1faFNBBgqS+TR19OgrEtfjkDmVnSYEp7/CBNCfEjoxWJe5ENwHdnV/IcS9Wf0tl2W7a SERo+WU0f+2uRdZ+KEH16L0sQU8wio9yRpax1X39VPPXIjiDsrw9KIelBg1M= X-Google-Smtp-Source: AGHT+IHlepwn2YUclkQra47gSbaQH2Winx4dfN2i2Z3eBSGGpIvoXWKQb1B+Sku0IkdxX83AyB66GQ== X-Received: by 2002:a7b:ca5a:0:b0:45d:e0cf:41c9 with SMTP id 5b1f17b1804b1-45f211f89d6mr77517385e9.22.1757935256907; Mon, 15 Sep 2025 04:20:56 -0700 (PDT) Received: from [127.0.0.1] (210.37.160.45.gramnet.com.br. [45.160.37.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e01519f67sm91903345e9.1.2025.09.15.04.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Sep 2025 04:20:56 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 15 Sep 2025 08:20:34 -0300 Subject: [PATCH v4 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: <20250915-nbcon-kgdboc-v4-5-e2b6753bb566@suse.com> References: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@suse.com> In-Reply-To: <20250915-nbcon-kgdboc-v4-0-e2b6753bb566@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=1757935236; l=3116; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=cU4lCiNjMiiGMfFUXRrB/KF33np8MWM4waFxZIq2SMc=; b=Y6lbO/KCBWxTvMSGO2TK/tbcPJ/aQUu4DL2ZUtimx/DkNPqLGVp7o3w+v848Ecp7GpIfU+SdW ZDXDMvsJD+JDoakfaepCtR5in9rzdM7olYGxHid+YWm/6wImVedpqii 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 Signed-off-by: Marcos Paulo de Souza Reviewed-by: Petr Mladek --- 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