Re: [PATCH] printk: CPU backtrace not printing on panic

From: John Ogness
Date: Mon Jul 29 2024 - 08:19:58 EST


Sorry, missed an important negation...

On 2024-07-29, John Ogness <john.ogness@xxxxxxxxxxxxx> wrote:
> Hi Ryo,
>
> On 2024-07-29, takakura@xxxxxxxxxxxxx wrote:
>> Or can we use cpu_sync for checking wheather non-panicked CPUs can
>> write to ringbuffer and let nbcon_atomic_flush_pending() do the
>> printing
>
> Yes, I like this. Let the non-panic CPUs write their messages, but keep
> the actual printing to the panic CPU.
>
> Right after the call to panic_other_cpus_shutdown() we plan [0] on
> calling printk_legacy_allow_panic_sync(), which will handle flushing the
> legacy consoles.
>
>> something like:
>>
>> ----- BEGIN -----
>> diff --git a/kernel/panic.c b/kernel/panic.c
>> index 7e207092576b..eed76e3e061b 100644
>> --- a/kernel/panic.c
>> +++ b/kernel/panic.c
>> @@ -252,8 +252,10 @@ void check_panic_on_warn(const char *origin)
>> */
>> static void panic_other_cpus_shutdown(bool crash_kexec)
>> {
>> - if (panic_print & PANIC_PRINT_ALL_CPU_BT)
>> + if (panic_print & PANIC_PRINT_ALL_CPU_BT) {
>> trigger_all_cpu_backtrace();
>> + nbcon_atomic_flush_pending();
>> + }
>>
>> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
>> index d0bff0b0abfd..b8132801ea07 100644
>> --- a/kernel/printk/printk.c
>> +++ b/kernel/printk/printk.c
>> @@ -2354,7 +2354,7 @@ asmlinkage int vprintk_emit(int facility, int level,
>> * non-panic CPUs are generating any messages, they will be
>> * silently dropped.
>> */
>> - if (other_cpu_in_panic())
>> + if (other_cpu_in_panic() && !__printk_cpu_sync_owner())
>> return 0;
>>
>> if (level == LOGLEVEL_SCHED) {
>> @@ -4511,6 +4511,11 @@ void __printk_cpu_sync_wait(void)
>> }
>> EXPORT_SYMBOL(__printk_cpu_sync_wait);
>>
>> +bool __printk_cpu_sync_owner(void)
>> +{
>> + return (atomic_read(&printk_cpu_sync_owner) == raw_smp_processor_id());
>> +}
>> +
>> ----- END -----
>
> Note that printing on the non-panic CPUs is guaranteed for nbcon

Note that _preventing_ printing on the non-panic CPUs...

> consoles because of the other_cpu_in_panic() in
> nbcon_context_try_acquire_direct() and for the legacy consoles because
> the cpu_sync holder must defer printing [1].
>
> I am curious what Petr has to say.
>
> John
>
> [0] https://lore.kernel.org/lkml/20240527063749.391035-26-john.ogness@xxxxxxxxxxxxx
>
> [1] https://lore.kernel.org/lkml/87plrcqyii.fsf@xxxxxxxxxxxxxxxxxxxxx