All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Daniil Tatianin <d-tatianin@yandex-team.ru>,
	linux-kernel@vger.kernel.org,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: Re: [PATCH v2 0/2] printk_ringbuffer: don't needlessly wrap data blocks around
Date: Mon, 15 Sep 2025 17:31:07 +0206	[thread overview]
Message-ID: <84tt137n70.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <aMgr0dId_UfBptzW@pathway.suse.cz>

On 2025-09-15, Petr Mladek <pmladek@suse.com> wrote:
> It might be possible to catch this in either in data_alloc().
> or in get_next_lpos(). They could ignore/yell about when
> the really occupied space would be bigger than DATA_SIZE(data_ring).
>
> Something like:
>
> diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
> index 17b741b2eccd..d7ba4c0d8c3b 100644
> --- a/kernel/printk/printk_ringbuffer.c
> +++ b/kernel/printk/printk_ringbuffer.c
> @@ -1056,8 +1056,16 @@ static char *data_alloc(struct printk_ringbuffer *rb, unsigned int size,
>  	do {
>  		next_lpos = get_next_lpos(data_ring, begin_lpos, size);
>  
> -		if (!data_push_tail(rb, next_lpos - DATA_SIZE(data_ring))) {
> -			/* Failed to allocate, specify a data-less block. */
> +		/*
> +		 * Double check that the really used space won't be bigger than
> +		 * the ring buffer. Wrapped messages need to reserve more space,
> +		 * see get_next_lpos.
> +		 *
> +		 * Specify a data-less block when the check or the allocation
> +		 * fails.
> +		 */
> +		if (WARN_ON_ONCE(next_lpos - begin_lpos > DATA_SIZE(data_ring)) ||
> +		    !data_push_tail(rb, next_lpos - DATA_SIZE(data_ring))) {
>  			blk_lpos->begin = FAILED_LPOS;
>  			blk_lpos->next = FAILED_LPOS;
>  			return NULL;
>
>
> Similar check would need to be done also in data_realloc().

I like this. It is an important sanity check and safe error handling in
case (for whatever reason) the data ring gets corrupted.

John

      reply	other threads:[~2025-09-15 15:25 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 14:41 [PATCH v2 0/2] printk_ringbuffer: don't needlessly wrap data blocks around Daniil Tatianin
2025-09-05 14:41 ` [PATCH v2 1/2] " Daniil Tatianin
2025-09-05 15:27   ` John Ogness
2025-09-05 15:29     ` Daniil Tatianin
2025-09-05 16:10       ` John Ogness
2025-09-11  8:34         ` Daniil Tatianin
2025-09-11 15:33           ` Petr Mladek
2025-09-05 15:30     ` John Ogness
2025-09-26 14:35   ` Daniil Tatianin
2025-09-26 14:44   ` Petr Mladek
2025-09-26 14:53     ` Daniil Tatianin
2025-10-22 12:46   ` Petr Mladek
2025-09-05 14:41 ` [PATCH v2 2/2] printk_ringbuffer: allow one data block to occupy the entire data ring Daniil Tatianin
2025-09-05 15:27   ` John Ogness
2025-09-11 15:30 ` [PATCH v2 0/2] printk_ringbuffer: don't needlessly wrap data blocks around Petr Mladek
2025-09-11 15:55   ` Petr Mladek
2025-09-11 16:11     ` Petr Mladek
2025-09-11 15:58   ` Petr Mladek
2025-09-11 16:12     ` John Ogness
2025-09-12  9:25       ` Petr Mladek
2025-09-12  9:54         ` Petr Mladek
2025-09-12 14:49           ` Petr Mladek
2025-09-12 15:15             ` Petr Mladek
2025-09-12 18:43             ` John Ogness
2025-09-13 17:38               ` Daniil Tatianin
2025-09-14  9:23                 ` John Ogness
2025-09-14  9:56                   ` Daniil Tatianin
2025-09-15 15:07                     ` John Ogness
2025-09-15 16:00                       ` Petr Mladek
2025-09-15 16:07                       ` Daniil Tatianin
2025-09-15 15:08               ` Petr Mladek
2025-09-15 15:25                 ` John Ogness [this message]

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=84tt137n70.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=d-tatianin@yandex-team.ru \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.