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 v1] printk_ringbuffer: don't needlessly wrap data blocks around
Date: Fri, 05 Sep 2025 11:19:02 +0206	[thread overview]
Message-ID: <84ikhxfejl.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <aLm_SpmQP3UwzkqQ@pathway>

On 2025-09-04, Petr Mladek <pmladek@suse.com> wrote:
> On Thu 2025-09-04 16:04:30, John Ogness wrote:
>> > +static bool same_lpos_wraps(struct prb_data_ring *data_ring,
>> > +			     unsigned long begin_lpos, unsigned long next_lpos)
>> 
>> We need a better name here since it is not actually using the value of
>> @next_lpos to check the wrap count. Perhaps inverting the return value
>> and naming it blk_lpos_wraps(). So it would be identifying if the given
>> blk_lpos values lead to a wrapping data block.
>
> Or a combination of my and this proposal: is_blk_wrapped().

Sounds good to me.

>> The rest looked fine to me and also passed various private
>> tests. However, we should also update data_check_size(), since now data
>> blocks are allowed to occupy the entire data ring. Something like this:
>> 
>> diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
>> index d9fb053cff67d..e6bdfb8237a3d 100644
>> --- a/kernel/printk/printk_ringbuffer.c
>> +++ b/kernel/printk/printk_ringbuffer.c
>> @@ -397,21 +397,14 @@ static unsigned int to_blk_size(unsigned int size)
>>   */
>>  static bool data_check_size(struct prb_data_ring *data_ring, unsigned int size)
>>  {
>> -	struct prb_data_block *db = NULL;
>> -
>>  	if (size == 0)
>>  		return true;
>>  
>>  	/*
>>  	 * Ensure the alignment padded size could possibly fit in the data
>> -	 * array. The largest possible data block must still leave room for
>> -	 * at least the ID of the next block.
>> +	 * array.
>>  	 */
>> -	size = to_blk_size(size);
>> -	if (size > DATA_SIZE(data_ring) - sizeof(db->id))
>> -		return false;
>> -
>> -	return true;
>> +	return (to_blk_size(size) <= DATA_SIZE(data_ring));
>>  }
>
> I hope that we would never reach this limit. A buffer for one
> message does not look practical. I originally suggested to avoid
> messages bigger than 1/4 of the buffer size ;-)
>
> That said, strictly speaking, the above change looks correct.
> I would just do it in a separate patch. The use of the full
> buffer and the limit of the maximal message are related
> but they are not the same things. Also separate patch might
> help with bisection in case of problems.

FWIW, Aside from inspecting all the related code carefully, I also
performed various size and boundary tests using small buffers (like 1KB
and 2KB). I am confortable with these changes.

John

  parent reply	other threads:[~2025-09-05  9:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03  0:10 [PATCH v1] printk_ringbuffer: don't needlessly wrap data blocks around Daniil Tatianin
2025-09-04  7:33 ` John Ogness
2025-09-04 13:58 ` John Ogness
2025-09-04 16:33   ` Petr Mladek
2025-09-04 16:50     ` Daniil Tatianin
2025-09-05  9:13     ` John Ogness [this message]
2025-09-05 10:47       ` Petr Mladek
2025-09-04 14:30 ` 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=84ikhxfejl.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.