Re: [PATCH printk v2 1/9] printk: ringbuffer: Do not skip non-finalized records with prb_next_seq()

From: John Ogness
Date: Tue Nov 21 2023 - 11:17:42 EST


On 2023-11-20, Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> wrote:
> based on my research this should be the most recent post of this patch.
> If so then
>
> On 2023-11-06 22:13:22 [+0106], John Ogness wrote:
>> --- a/kernel/printk/printk_ringbuffer.c
>> +++ b/kernel/printk/printk_ringbuffer.c
>> + /*
>> + * The provided sequence is only the lower 32 bits of the ringbuffer
>> + * sequence. It needs to be expanded to 64bit. Get the first sequence
>> + * number from the ringbuffer and fold it.
>> + */
>> + seq = rb_first_seq - ((u32)rb_first_seq - ulseq);
>
> This needs to become
> seq = rb_first_seq - ((s32)((u32)rb_first_seq - ulseq));
>
> in order to continue booting on 32bit.

Indeed. The code assumes the passed in value (@ulseq) always represents
a 64-bit number that is less than or equal to the basis value
(@rb_first_seq). For kernel/printk/nbcon.c:__nbcon_seq_to_seq() that
assumption is correct. For this function, it is not.

Your change will round up or down to the nearest 32 bits of the basis
value.

For example, with @rb_first_seq = 0x200000000 and @ulseq = 0x1:

before your change (where @ulseq cannot represent something higher than
@rb_first_seq):

@ulseq translates to 0x100000001

after your change:

@ulseq translates to 0x200000001

Since __ulseq_to_u64seq() must deal with arbitrary values, I think the
32-bit rounding is appropriate.

Despite not strictly being necessary (because of the valid assumption),
I think we should also update __nbcon_seq_to_seq() to avoid any bizarre
cases due to different translations of the 32-bit value.

In fact, there is no reason to have 2 macros for this. I will create a
single macro using the 32-bit rounding.

Thanks for researching this!

John