Re: [syzbot] possible deadlock in worker_thread

From: Tejun Heo
Date: Mon Feb 14 2022 - 12:34:50 EST


Hello,

On Mon, Feb 14, 2022 at 10:36:57PM +0900, Tetsuo Handa wrote:
> OK. Then, I propose below patch. If you are OK with this approach, I can
> keep this via my tree as a linux-next only experimental patch for one or
> two weeks, in order to see if someone complains.

I don't mind you testing that way but this and would much prefer this and
related changes in the wq tree.

> +static void warn_if_flushing_global_workqueue(struct workqueue_struct *wq)
> +{
> +#ifdef CONFIG_PROVE_LOCKING
> + static DEFINE_RATELIMIT_STATE(flush_warn_rs, 600 * HZ, 1);
> + const char *name;
> +
> + if (wq == system_wq)
> + name = "system_wq";
> + else if (wq == system_highpri_wq)
> + name = "system_highpri_wq";
> + else if (wq == system_long_wq)
> + name = "system_long_wq";
> + else if (wq == system_unbound_wq)
> + name = "system_unbound_wq";
> + else if (wq == system_freezable_wq)
> + name = "system_freezable_wq";
> + else if (wq == system_power_efficient_wq)
> + name = "system_power_efficient_wq";
> + else if (wq == system_freezable_power_efficient_wq)
> + name = "system_freezable_power_efficient_wq";
> + else
> + return;
> + ratelimit_set_flags(&flush_warn_rs, RATELIMIT_MSG_ON_RELEASE);
> + if (!__ratelimit(&flush_warn_rs))
> + return;
> + pr_warn("Since system-wide WQ is shared, flushing system-wide WQ can introduce unexpected locking dependency. Please replace %s usage in your code with your local WQ.\n",
> + name);
> + dump_stack();
> +#endif

Instead of doing the above, please add a wq flag to mark system wqs and
trigger the warning that way and I'd leave it regardless of PROVE_LOCKING.

Thanks.

--
tejun