Re: [PATCH v2 0/2] printk_ringbuffer: don't needlessly wrap data blocks around

Petr Mladek
2025-09-12T09:25:09Z

On Thu 2025-09-11 18:18:32, John Ogness wrote:
> On 2025-09-11, Petr Mladek <pmladek@suse.com> wrote:
> > diff --git a/kernel/printk/printk_ringbuffer_kunit_test.c b/kernel/printk/printk_ringbuffer_kunit_test.c
> > index 2282348e869a..241f7ef49ac6 100644
> > --- a/kernel/printk/printk_ringbuffer_kunit_test.c
> > +++ b/kernel/printk/printk_ringbuffer_kunit_test.c
> > @@ -56,7 +56,7 @@ struct prbtest_rbdata {
> > char text[] __counted_by(size);
> > };
> >
> > -#define MAX_RBDATA_TEXT_SIZE 0x80
> > +#define MAX_RBDATA_TEXT_SIZE (0x256 - sizeof(struct prbtest_rbdata))
>
> I guess this should be:
>
> #define MAX_RBDATA_TEXT_SIZE (256 - sizeof(struct prbtest_rbdata))

Great catch!

But the KUnit test fails even with this change, see below. And I am
not surprised. The test should work even with larger-than-allowed
messages. prbtest_writer() should skip then because prb_reserve()
should fail.

Here is test result with:

#define MAX_RBDATA_TEXT_SIZE (256 - sizeof(struct prbtest_rbdata))
#define MAX_PRB_RECORD_SIZE (sizeof(struct prbtest_rbdata) + MAX_RBDATA_TEXT_SIZE)

DEFINE_PRINTKRB(test_rb, 4, 4);

and with this patchset reverted, aka, sources from
printk/linux.git, branch for-next:

[ 229.020133] printk_ringbuffer_kunit_test: module verification failed: signature and/or required key missing - tainting kernel
[ 229.029453] KTAP version 1
[ 229.029793] 1..1
[ 229.030461] KTAP version 1
[ 229.030771] # Subtest: printk-ringbuffer
[ 229.031111] # module: printk_ringbuffer_kunit_test
[ 229.031142] 1..1
[ 229.032371] # test_readerwriter: running for 10000 ms
[ 229.034348] # test_readerwriter: start thread 001 (writer)
[ 229.034721] # test_readerwriter: start thread 002 (writer)
[ 229.035398] # test_readerwriter: start thread 003 (writer)
[ 229.035697] # test_readerwriter: start thread 004 (writer)
[ 229.038006] # test_readerwriter: start thread 005 (writer)
[ 229.041965] # test_readerwriter: start thread 006 (writer)
[ 229.042244] # test_readerwriter: start thread 007 (writer)
[ 229.042559] # test_readerwriter: start thread 008 (writer)
[ 229.042748] # test_readerwriter: start thread 009 (writer)
[ 229.042996] # test_readerwriter: start thread 010 (writer)
[ 229.043288] # test_readerwriter: starting test
[ 229.043299] # test_readerwriter: start thread 011 (writer)
[ 229.043370] # test_readerwriter: start reader
[ 229.043574] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=15 size=1111638594 text=
[ 239.133686] # test_readerwriter: end reader: read=14 seq=24
[ 239.134417] # test_readerwriter: completed test
[ 239.136019] # test_readerwriter: end thread 011: wrote=10466402
[ 239.136856] # test_readerwriter: end thread 010: wrote=10461343
[ 239.137825] # test_readerwriter: end thread 009: wrote=13686189
[ 239.138478] # test_readerwriter: end thread 008: wrote=10475551
[ 239.139106] # test_readerwriter: end thread 007: wrote=13652622
[ 239.139765] # test_readerwriter: end thread 006: wrote=10473282
[ 239.140376] # test_readerwriter: end thread 005: wrote=10444451
[ 239.140989] # test_readerwriter: end thread 004: wrote=10466857
[ 239.141652] # test_readerwriter: end thread 003: wrote=13733553
[ 239.142243] # test_readerwriter: end thread 002: wrote=13710538
[ 239.142859] # test_readerwriter: end thread 001: wrote=13738411
[ 239.143738] # test_readerwriter.speed: slow
[ 239.143771] not ok 1 test_readerwriter
[ 239.144161] not ok 1 printk-ringbuffer

It is well reproducible. It always fails after reading few records.
Here are results from few other runs:

[ 1617.607865] KTAP version 1
[ 1617.608377] # Subtest: printk-ringbuffer
[ 1617.608891] # module: printk_ringbuffer_kunit_test
[ 1617.609041] 1..1
[ 1617.613633] # test_readerwriter: running for 10000 ms
[ 1617.614796] # test_readerwriter: start thread 001 (writer)
[ 1617.615562] # test_readerwriter: start thread 002 (writer)
[ 1617.616399] # test_readerwriter: start thread 003 (writer)
[ 1617.617911] # test_readerwriter: start thread 004 (writer)
[ 1617.618763] # test_readerwriter: start thread 005 (writer)
[ 1617.619067] # test_readerwriter: start thread 006 (writer)
[ 1617.619368] # test_readerwriter: start thread 007 (writer)
[ 1617.619650] # test_readerwriter: start thread 008 (writer)
[ 1617.619921] # test_readerwriter: start thread 009 (writer)
[ 1617.620211] # test_readerwriter: start thread 010 (writer)
[ 1617.620462] # test_readerwriter: starting test
[ 1617.623169] # test_readerwriter: start thread 011 (writer)
[ 1617.623175] # test_readerwriter: start reader
[ 1617.624508] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=9 size=1111638594 text=
[ 1617.626400] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=13 size=1111638594 text=
[ 1617.628225] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=17 size=1111638594 text=
[ 1627.681624] # test_readerwriter: end reader: read=14 seq=17
[ 1627.682370] # test_readerwriter: completed test
[ 1627.683960] # test_readerwriter: end thread 011: wrote=10452656
[ 1627.684779] # test_readerwriter: end thread 010: wrote=13707777
[ 1627.685412] # test_readerwriter: end thread 009: wrote=10480695
[ 1627.686274] # test_readerwriter: end thread 008: wrote=10470822
[ 1627.687081] # test_readerwriter: end thread 007: wrote=13697351
[ 1627.687716] # test_readerwriter: end thread 006: wrote=10464543
[ 1627.688317] # test_readerwriter: end thread 005: wrote=10488791
[ 1627.688919] # test_readerwriter: end thread 004: wrote=10488529
[ 1627.689492] # test_readerwriter: end thread 003: wrote=13738659
[ 1627.690321] # test_readerwriter: end thread 002: wrote=13718856
[ 1627.690915] # test_readerwriter: end thread 001: wrote=13675859
[ 1627.691694] # test_readerwriter.speed: slow
[ 1627.691753] not ok 1 test_readerwriter
[ 1627.692512] not ok 1 printk-ringbuffer

[ 1627.693708] KTAP version 1
[ 1627.694046] # Subtest: printk-ringbuffer
[ 1627.694385] # module: printk_ringbuffer_kunit_test
[ 1627.694410] 1..1
[ 1627.695698] # test_readerwriter: running for 10000 ms
[ 1627.698351] # test_readerwriter: start thread 001 (writer)
[ 1627.698935] # test_readerwriter: start thread 002 (writer)
[ 1627.699341] # test_readerwriter: start thread 003 (writer)
[ 1627.699657] # test_readerwriter: start thread 004 (writer)
[ 1627.699891] # test_readerwriter: start thread 005 (writer)
[ 1627.700111] # test_readerwriter: start thread 006 (writer)
[ 1627.700337] # test_readerwriter: start thread 007 (writer)
[ 1627.700620] # test_readerwriter: start thread 008 (writer)
[ 1627.700885] # test_readerwriter: start thread 009 (writer)
[ 1627.701134] # test_readerwriter: start thread 010 (writer)
[ 1627.701371] # test_readerwriter: starting test
[ 1627.701374] # test_readerwriter: start thread 011 (writer)
[ 1627.705369] # test_readerwriter: start reader
[ 1627.706115] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=16 size=1111638594 text=
[ 1627.707966] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=20 size=1111638594 text=
[ 1627.710886] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=24 size=16962 text=
[ 1637.917622] # test_readerwriter: end reader: read=14 seq=27
[ 1637.918372] # test_readerwriter: completed test
[ 1637.919848] # test_readerwriter: end thread 011: wrote=10559459
[ 1637.920670] # test_readerwriter: end thread 010: wrote=13811125
[ 1637.921309] # test_readerwriter: end thread 009: wrote=10572663
[ 1637.922176] # test_readerwriter: end thread 008: wrote=10570916
[ 1637.922818] # test_readerwriter: end thread 007: wrote=13832304
[ 1637.923456] # test_readerwriter: end thread 006: wrote=10571421
[ 1637.924082] # test_readerwriter: end thread 005: wrote=10579437
[ 1637.924703] # test_readerwriter: end thread 004: wrote=13861481
[ 1637.925318] # test_readerwriter: end thread 003: wrote=10590865
[ 1637.925977] # test_readerwriter: end thread 002: wrote=13852926
[ 1637.926570] # test_readerwriter: end thread 001: wrote=13845110
[ 1637.927172] # test_readerwriter.speed: slow
[ 1637.927202] not ok 1 test_readerwriter
[ 1637.927611] not ok 1 printk-ringbuffer

[ 1658.412099] KTAP version 1
[ 1658.412409] # Subtest: printk-ringbuffer
[ 1658.412784] # module: printk_ringbuffer_kunit_test
[ 1658.412813] 1..1
[ 1658.416372] # test_readerwriter: running for 10000 ms
[ 1658.417927] # test_readerwriter: start thread 001 (writer)
[ 1658.418309] # test_readerwriter: start thread 002 (writer)
[ 1658.418785] # test_readerwriter: start thread 003 (writer)
[ 1658.418996] # test_readerwriter: start thread 004 (writer)
[ 1658.419262] # test_readerwriter: start thread 005 (writer)
[ 1658.419531] # test_readerwriter: start thread 006 (writer)
[ 1658.419758] # test_readerwriter: start thread 007 (writer)
[ 1658.420028] # test_readerwriter: start thread 008 (writer)
[ 1658.420239] # test_readerwriter: start thread 009 (writer)
[ 1658.420516] # test_readerwriter: start thread 010 (writer)
[ 1658.420737] # test_readerwriter: starting test
[ 1658.420739] # test_readerwriter: start thread 011 (writer)
[ 1658.420791] # test_readerwriter: start reader
[ 1658.420879] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=8 size=217 text=DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\x10\xa2\xff\xff\xff\xff#\x8b^M\xa4\xff\xff\xff\xff\xb3\x8a\xb5A
[ 1658.421015] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=9 size=217 text=DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\x10\xa2\xff\xff\xff\xff#\x8b^M\xa4\xff\xff\xff\xff\xb3\x8a\xb5A
[ 1658.421152] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=10 size=1145324612 text=
[ 1658.431961] # test_readerwriter: EXPECTATION FAILED at kernel/printk/printk_ringbuffer_kunit_test.c:80
BAD RECORD: seq=18 size=1145324612 text=
[ 1668.637609] # test_readerwriter: end reader: read=13 seq=20
[ 1668.638384] # test_readerwriter: completed test
[ 1668.639464] # test_readerwriter: end thread 011: wrote=13482649
[ 1668.640116] # test_readerwriter: end thread 010: wrote=10354440
[ 1668.640934] # test_readerwriter: end thread 009: wrote=10388436
[ 1668.642245] # test_readerwriter: end thread 008: wrote=13621613
[ 1668.642886] # test_readerwriter: end thread 007: wrote=10072648
[ 1668.643536] # test_readerwriter: end thread 006: wrote=13582778
[ 1668.644171] # test_readerwriter: end thread 005: wrote=10397092
[ 1668.644792] # test_readerwriter: end thread 004: wrote=13499818
[ 1668.645415] # test_readerwriter: end thread 003: wrote=10362779
[ 1668.646319] # test_readerwriter: end thread 002: wrote=10348508
[ 1668.646924] # test_readerwriter: end thread 001: wrote=13616849
[ 1668.647584] # test_readerwriter.speed: slow
[ 1668.647618] not ok 1 test_readerwriter
[ 1668.648311] not ok 1 printk-ringbuffer

Best Regards,
Petr