public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH printk v3 6/7] printk: nbcon: Add emit function and callback function for atomic printing
Date: Thu, 7 Sep 2023 10:22:32 +0200	[thread overview]
Message-ID: <ZPmISE9olpOkPOM8@alley> (raw)
In-Reply-To: <20230903150539.245076-7-john.ogness@linutronix.de>

On Sun 2023-09-03 17:11:38, John Ogness wrote:
> From: Thomas Gleixner <tglx@linutronix.de>
> 
> Implement an emit function for nbcon consoles to output printk
> messages. It utilizes the lockless printk_get_next_message() and
> console_prepend_dropped() functions to retrieve/build the output
> message. The emit function includes the required safety points to
> check for handover/takeover and calls a new write_atomic callback
> of the console driver to output the message. It also includes
> proper handling for updating the nbcon console sequence number.
> 
> A new nbcon_write_context struct is introduced. This is provided
> to the write_atomic callback and includes only the information
> necessary for performing atomic writes.
> 
> Co-developed-by: John Ogness <john.ogness@linutronix.de>
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de>

Reviewed-by: Petr Mladek <pmladek@suse.com>

Well, I would prefer one small change, see below.

> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -732,6 +756,102 @@ static bool nbcon_context_update_unsafe(struct nbcon_context *ctxt, bool unsafe)
>  	return nbcon_context_can_proceed(ctxt, &cur);
>  }
>  
> +/**
> + * nbcon_emit_next_record - Emit a record in the acquired context
> + * @wctxt:	The write context that will be handed to the write function
> + *
> + * Return:	True if this context still owns the console. False if
> + *		ownership was handed over or taken.
> + *
> + * When this function returns false then the calling context no longer owns
> + * the console and is no longer allowed to go forward. In this case it must
> + * back out immediately and carefully. The buffer content is also no longer
> + * trusted since it no longer belongs to the calling context. If the caller
> + * wants to do more it must reacquire the console first.
> + *
> + * When true is returned, @wctxt->ctxt.backlog indicates whether there are
> + * still records pending in the ringbuffer,
> + */
> +__maybe_unused
> +static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt)
> +{
> +	struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
> +	struct console *con = ctxt->console;
> +	bool is_extended = console_srcu_read_flags(con) & CON_EXTENDED;
> +	struct printk_message pmsg = {
> +		.pbufs = ctxt->pbufs,
> +	};
> +	unsigned long con_dropped;
> +	struct nbcon_state cur;
> +	unsigned long dropped;
> +	bool done;
[...]
> +update_con:
> +	/*
> +	 * The dropped count and the sequence number are updated within an
> +	 * unsafe section. This limits update races to the panic context and
> +	 * allows the panic context to win.
> +	 */
> +
> +	if (!nbcon_context_update_unsafe(ctxt, true))
> +		return false;

I would prefer to use nbcon_enter_unsafe(). It is more self-explaining.
And it will make it easier to see the "all" enter/exit points using cscope.

> +
> +	if (dropped != con_dropped) {
> +		/* Counterpart to the READ_ONCE() above. */
> +		WRITE_ONCE(con->dropped, dropped);
> +	}
> +
> +	nbcon_seq_try_update(ctxt, pmsg.seq + 1);
> +
> +	return nbcon_context_update_unsafe(ctxt, false);
> +}

Best Regards,
Petr

  reply	other threads:[~2023-09-07 15:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-03 15:05 [PATCH printk v3 0/7] provide nbcon base John Ogness
2023-09-03 15:05 ` [PATCH printk v3 1/7] printk: Add non-BKL (nbcon) console basic infrastructure John Ogness
2023-09-05 11:45   ` Petr Mladek
2023-09-03 15:05 ` [PATCH printk v3 2/7] printk: nbcon: Add acquire/release logic John Ogness
2023-09-03 16:32   ` kernel test robot
2023-09-05  9:07     ` John Ogness
2023-09-03 16:43   ` kernel test robot
2023-09-06 13:01   ` Petr Mladek
2023-09-03 15:05 ` [PATCH printk v3 3/7] printk: nbcon: Add buffer management John Ogness
2023-09-06 13:26   ` Petr Mladek
2023-09-08 13:03     ` John Ogness
2023-09-03 15:05 ` [PATCH printk v3 4/7] printk: nbcon: Add ownership state functions John Ogness
2023-09-06 13:57   ` Petr Mladek
2023-09-08 13:20     ` John Ogness
2023-09-03 15:05 ` [PATCH printk v3 5/7] printk: nbcon: Add sequence handling John Ogness
2023-09-07  7:45   ` Petr Mladek
2023-09-03 15:05 ` [PATCH printk v3 6/7] printk: nbcon: Add emit function and callback function for atomic printing John Ogness
2023-09-07  8:22   ` Petr Mladek [this message]
2023-09-03 15:05 ` [PATCH printk v3 7/7] printk: nbcon: Add functions for drivers to mark unsafe regions John Ogness
2023-09-07  8:24   ` Petr Mladek

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=ZPmISE9olpOkPOM8@alley \
    --to=pmladek@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=tglx@linutronix.de \
    /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