Re: [PATCH printk v3 3/7] printk: nbcon: Add buffer management

From: John Ogness
Date: Fri Sep 08 2023 - 09:03:41 EST


On 2023-09-06, Petr Mladek <pmladek@xxxxxxxx> wrote:
>> +bool nbcon_alloc(struct console *con)
>> +{
>> +
>> + con->pbufs = kmalloc(sizeof(*con->pbufs), GFP_KERNEL);
>
> We might need to use memblock_alloc() at least for early consoles.

I wasn't planning on addressing early consoles at this stage. The
initial 8250 NBCON implementation will only be for the regular console.

However, since it is planned that NBCON consoles are synchronized with
boot consoles using the console_lock, we might as well establish that
boot consoles (in general) are always synchronized uisng the
console_lock.

This allows us to use the single global pbufs of the legacy consoles
(see console_emit_next_record()) for NBCON boot consoles as well. The
static buffer is much more attractive because it is always available.

For v4, nbcon_alloc() will initialize con->pbufs to use the global
legacy pbufs for con->flags == CON_BOOT.

bool nbcon_alloc(struct console *con)
{
if (con->flags & CON_BOOT) {
/*
* Boot console printing is synchronized with legacy console
* printing, so boot consoles can share the same global printk
* buffers.
*/
con->pbufs = &printk_shared_pbufs;
} else {
con->pbufs = kmalloc(sizeof(*con->pbufs), GFP_KERNEL);
if (!con->pbufs) {
con_printk(KERN_ERR, con, "failed to allocate printing buffer\n");
return false;
}
}

return true;
}

John Ogness