Re: [PATCH next v3 1/2] dump_stack: move cpu lock to printk.c

From: Sergey Senozhatsky
Date: Wed Jun 16 2021 - 07:55:43 EST


On (21/06/16 09:35), John Ogness wrote:
> It isn't about limiting. It is about tracking.

Oh, yes. I missed it.
>
[..]

> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index e67dc510fa1b..5376216e4f3d 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -3535,7 +3535,7 @@ EXPORT_SYMBOL_GPL(kmsg_dump_rewind);
>
> #ifdef CONFIG_SMP
> static atomic_t printk_cpulock_owner = ATOMIC_INIT(-1);
> -static bool printk_cpulock_nested;
> +static atomic_t printk_cpulock_nested = ATOMIC_INIT(0);
>
> /**
> * __printk_wait_on_cpu_lock() - Busy wait until the printk cpu-reentrant
> @@ -3596,7 +3598,7 @@ int __printk_cpu_trylock(void)
>
> } else if (old == cpu) {
> /* This CPU is already the owner. */
> - printk_cpulock_nested = true;
> + atomic_inc(&printk_cpulock_nested);
> return 1;
> }
>
> @@ -3613,8 +3615,8 @@ EXPORT_SYMBOL(__printk_cpu_trylock);
> */
> void __printk_cpu_unlock(void)
> {
> - if (printk_cpulock_nested) {
> - printk_cpulock_nested = false;
> + if (atomic_read(&printk_cpulock_nested)) {
> + atomic_dec(&printk_cpulock_nested);
> return;
> }

Looks good.