public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Daniil Tatianin <d-tatianin@yandex-team.ru>
Cc: linux-kernel@vger.kernel.org,
	Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>,
	Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: Re: [PATCH v2 0/2] printk_ringbuffer: don't needlessly wrap data blocks around
Date: Thu, 11 Sep 2025 18:11:40 +0200	[thread overview]
Message-ID: <aML0vKgiXQSh-j2_@pathway.suse.cz> (raw)
In-Reply-To: <aMLxAlUgXpSs-tVN@pathway.suse.cz>

On Thu 2025-09-11 17:55:49, Petr Mladek wrote:
> On Thu 2025-09-11 17:30:36, Petr Mladek wrote:
> > On Fri 2025-09-05 17:41:50, Daniil Tatianin wrote:
> > > This series fixes the issue where data blocks would wrap in cases where the last
> > > data block perfectly fits the ring. This caused whatever was at the beginning of
> > > the ring to get discarded in this case, and the data block would get put there
> > > even though it could be put at the end of the data ring just fine without
> > > discarding anything.
> > > 
> > > Fixing this issue also allows to simplify the check in data_check_size,
> > > previously it would ensure there's space for a trailing id, which we
> > > don't need anymore.
> > > 
> > > v0->v1:
> > > - Fix severely broken code alignment
> > > 
> > > v1->v2:
> > > - Rename & invert get_next_lpos -> is_blk_wrapped
> > > - Add a new commit for changing the logic in data_check_size
> > 
> > The patchset looks good to me. But I wanted to do some tests
> > and it failed. I did the following:
> > 
> > 1. Applied this patchset on top of printk/linux.git, branch for-next,
> >    https://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git/log/?h=for-next
> > 
> >    I this branch because it contains a new KUnit test for the printk
> >    ring buffer.
> 
> The KUnit test fails even without this patchset, see below.
> 
> > 2. I applied the following patch:
> > 
> >        + It reduces the size of the data ring. If I count it correctly
> > 	 it should be 256 (2 << 8).
> > 
> >        + It increases the maximal size of the text so that the maximal
> > 	 record size is 256.
> > 
> > 3. I built it with Kasan enabled:
> > 
> > 	$> grep KASAN .config
> > 	CONFIG_KASAN_SHADOW_OFFSET=0xdffffc0000000000
> > 	CONFIG_HAVE_ARCH_KASAN=y
> > 	CONFIG_HAVE_ARCH_KASAN_VMALLOC=y
> > 	CONFIG_CC_HAS_KASAN_GENERIC=y
> > 	CONFIG_CC_HAS_KASAN_SW_TAGS=y
> > 	CONFIG_KASAN=y
> > 	CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX=y
> > 	CONFIG_KASAN_GENERIC=y
> > 	# CONFIG_KASAN_OUTLINE is not set
> > 	CONFIG_KASAN_INLINE=y
> > 	CONFIG_KASAN_STACK=y
> > 	CONFIG_KASAN_VMALLOC=y
> > 	# CONFIG_KASAN_KUNIT_TEST is not set
> > 	# CONFIG_KASAN_EXTRA_INFO is not set
> > 
> > 
> > 4. I loaded the test module:
> > 
> > 	# depmod
> > 	# modprobe printk_ringbuffer_kunit_test
> > 
> > I am not sure if it is caused by this patchset or
> 
> Hmm, the KUnit test fails even after reverting this patchset.

I do not longer [*] see the problem with the following change in the
original code:

diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index bc811de18316..ff93c4a079f7 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -409,7 +409,7 @@ static bool data_check_size(struct prb_data_ring *data_ring, unsigned int size)
 	 * at least the ID of the next block.
 	 */
 	size = to_blk_size(size);
-	if (size > DATA_SIZE(data_ring) - sizeof(db->id))
+	if (size > (DATA_SIZE(data_ring) / 4))
 		return false;
 
 	return true;

[*] I did 10 runs on the Knuit test. The problem was always
    reproducible before.

I hope that the race happens only when one record uses more than
half of the data ring. Or something like this. So that printk()
could not meet it in practice.

Sigh.

Best Regards,
Petr

  reply	other threads:[~2025-09-11 16:11 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 [this message]
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

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=aML0vKgiXQSh-j2_@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=d-tatianin@yandex-team.ru \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --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