mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Marcos Paulo de Souza <mpdesouza@suse.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Petr Mladek <pmladek@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Jason Wessel <jason.wessel@windriver.com>,
	Daniel Thompson <danielt@kernel.org>,
	Douglas Anderson <dianders@chromium.org>
Cc: linux-kernel@vger.kernel.org,
	kgdb-bugreport@lists.sourceforge.net,
	Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: Re: [PATCH 2/2] kdb: Adapt kdb_msg_write to work with NBCON consoles
Date: Sun, 13 Jul 2025 22:42:17 +0206	[thread overview]
Message-ID: <84ldorx1z2.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20250713-nbcon-kgdboc-v1-2-51eccd9247a8@suse.com>

On 2025-07-13, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
> index 9b11b10b120cf07e451a7a4d92ce50f9a6c066b2..3b7365c11d06b01d487767fd89f1081da10dd2ed 100644
> --- a/kernel/debug/kdb/kdb_io.c
> +++ b/kernel/debug/kdb/kdb_io.c
> @@ -558,6 +558,25 @@ static int kdb_search_string(char *searched, char *searchfor)
>  	return 0;
>  }
>  
> +static struct nbcon_context *nbcon_acquire_ctxt(struct console *con,
> +					struct nbcon_write_context *wctxt,
> +					char *msg, int msg_len)
> +{
> +	struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
> +
> +	ctxt->console		    = con;
> +	ctxt->spinwait_max_us	    = 0;
> +	ctxt->prio		    = NBCON_PRIO_EMERGENCY;
> +	ctxt->allow_unsafe_takeover = false;
> +	wctxt->outbuf		    = msg;
> +	wctxt->len		    = msg_len;
> +
> +	if (!nbcon_context_try_acquire(ctxt))
> +		return NULL;
> +
> +	return ctxt;

This function is grabbing a reference to a private member and returning
it, thus exposing internals. Can we instead create a proper API in
kernel/printk/nbcon.c for kdb?

For example, take a look at:

nbcon_device_try_acquire() and nbcon_device_release()

We could have something similar for kdb, such as:

bool *nbcon_kdb_try_acquire(struct nbcon_write_context *wctxt,
			    struct console *con, char *msg, int msg_len);

void nbcon_kdb_release(struct nbcon_write_context *wctxt);

> +}
> +
>  static void kdb_msg_write(const char *msg, int msg_len)
>  {
>  	struct console *c;
> @@ -589,12 +608,26 @@ static void kdb_msg_write(const char *msg, int msg_len)
>  	 */
>  	cookie = console_srcu_read_lock();
>  	for_each_console_srcu(c) {
> -		if (!(console_srcu_read_flags(c) & CON_ENABLED))
> +		struct nbcon_write_context wctxt = { };
> +		struct nbcon_context *ctxt;

With the above suggestion we do not need @ctxt.

> +		short flags = console_srcu_read_flags(c);
> +
> +		if (!console_is_usable(c, flags, true))
>  			continue;
>  		if (c == dbg_io_ops->cons)
>  			continue;
> -		if (!c->write)
> -			continue;
> +
> +		/*
> +		 * Do not continue if the console is NBCON and the context
> +		 * can't be acquired.
> +		 */
> +		if (flags & CON_NBCON) {
> +			ctxt = nbcon_acquire_ctxt(c, &wctxt, (char *)msg,
> +						  msg_len);
> +			if (!ctxt)
> +				continue;

And this becomes:

			if (!nbcon_kdb_try_acquire(&wctxt, c, (char *)msg, msg_len))
				continue;
> +		}
> +
>  		/*
>  		 * Set oops_in_progress to encourage the console drivers to
>  		 * disregard their internal spin locks: in the current calling
> @@ -605,7 +638,12 @@ static void kdb_msg_write(const char *msg, int msg_len)
>  		 * for this calling context.
>  		 */
>  		++oops_in_progress;
> -		c->write(c, msg, msg_len);
> +		if (flags & CON_NBCON) {
> +			c->write_atomic(c, &wctxt);
> +			nbcon_context_release(ctxt);

And this becomes:

			nbcon_kdb_release(&wctxt);

> +		} else {
> +			c->write(c, msg, msg_len);
> +		}
>  		--oops_in_progress;
>  		touch_nmi_watchdog();
>  	}

John Ogness

  reply	other threads:[~2025-07-13 20:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-13  5:09 [PATCH 0/2] Handle NBCON consoles on KDB Marcos Paulo de Souza
2025-07-13  5:09 ` [PATCH 1/2] printk: nbcon: Export console_is_usage and other nbcon symbols Marcos Paulo de Souza
2025-07-13  6:43   ` kernel test robot
2025-07-13  7:04   ` kernel test robot
2025-07-13 20:16   ` John Ogness
2025-07-13  5:09 ` [PATCH 2/2] kdb: Adapt kdb_msg_write to work with NBCON consoles Marcos Paulo de Souza
2025-07-13 20:36   ` John Ogness [this message]
2025-07-14  2:04     ` Marcos Paulo de Souza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84ldorx1z2.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=danielt@kernel.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jason.wessel@windriver.com \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpdesouza@suse.com \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®