From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752879AbcCJPQm (ORCPT ); Thu, 10 Mar 2016 10:16:42 -0500 Received: from mga03.intel.com ([134.134.136.65]:60768 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751366AbcCJPQe (ORCPT ); Thu, 10 Mar 2016 10:16:34 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,316,1455004800"; d="scan'208";a="761688753" Subject: Re: [PATCH] workqueue: warn if memory reclaim tries to flush !WQ_MEM_RECLAIM workqueue To: Tejun Heo , Peter Zijlstra References: <20151203002810.GJ19878@mtj.duckdns.org> <20151203093350.GP17308@twins.programming.kicks-ass.net> <20151203100018.GO11639@twins.programming.kicks-ass.net> <20151203144811.GA27463@mtj.duckdns.org> <20151203150442.GR17308@twins.programming.kicks-ass.net> <20151203150604.GC27463@mtj.duckdns.org> <20151203192616.GJ27463@mtj.duckdns.org> Cc: Ulrich Obergfell , Ingo Molnar , Andrew Morton , linux-kernel@vger.kernel.org, kernel-team@fb.com From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Message-ID: <56E18EF6.1010006@intel.com> Date: Thu, 10 Mar 2016 17:12:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20151203192616.GJ27463@mtj.duckdns.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/12/15 21:26, Tejun Heo wrote: > Task or work item involved in memory reclaim trying to flush a > non-WQ_MEM_RECLAIM workqueue or one of its work items can lead to > deadlock. Trigger WARN_ONCE() if such conditions are detected. > > Signed-off-by: Tejun Heo > Cc: Peter Zijlstra > --- > Hello, > > So, something like this. Seems to work fine here. If there's no > objection, I'm gonna push it through wq/for-4.5. > > Thanks. > > kernel/workqueue.c | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > --- a/kernel/workqueue.c > +++ b/kernel/workqueue.c > @@ -2330,6 +2330,37 @@ repeat: > goto repeat; > } > > +/** > + * check_flush_dependency - check for flush dependency sanity > + * @target_wq: workqueue being flushed > + * @target_work: work item being flushed (NULL for workqueue flushes) > + * > + * %current is trying to flush the whole @target_wq or @target_work on it. > + * If @target_wq doesn't have %WQ_MEM_RECLAIM, verify that %current is not > + * reclaiming memory or running on a workqueue which doesn't have > + * %WQ_MEM_RECLAIM as that can break forward-progress guarantee leading to > + * a deadlock. > + */ > +static void check_flush_dependency(struct workqueue_struct *target_wq, > + struct work_struct *target_work) > +{ > + work_func_t target_func = target_work ? target_work->func : NULL; > + struct worker *worker; > + > + if (target_wq->flags & WQ_MEM_RECLAIM) > + return; > + > + worker = current_wq_worker(); > + > + WARN_ONCE(current->flags & PF_MEMALLOC, > + "workqueue: PF_MEMALLOC task %d(%s) is flushing !WQ_MEM_RECLAIM %s:%pf", > + current->pid, current->comm, target_wq->name, target_func); > + WARN_ONCE(worker && (worker->current_pwq->wq->flags & WQ_MEM_RECLAIM), > + "workqueue: WQ_MEM_RECLAIM %s:%pf is flushing !WQ_MEM_RECLAIM %s:%pf", > + worker->current_pwq->wq->name, worker->current_func, > + target_wq->name, target_func); > +} > + > struct wq_barrier { > struct work_struct work; > struct completion done; > @@ -2539,6 +2570,8 @@ void flush_workqueue(struct workqueue_st > list_add_tail(&this_flusher.list, &wq->flusher_overflow); > } > > + check_flush_dependency(wq, NULL); > + > mutex_unlock(&wq->mutex); > > wait_for_completion(&this_flusher.done); > @@ -2711,6 +2744,8 @@ static bool start_flush_work(struct work > pwq = worker->current_pwq; > } > > + check_flush_dependency(pwq->wq, work); > + > insert_wq_barrier(pwq, barr, work, worker); > spin_unlock_irq(&pool->lock); > > I am hitting the warnings when using cancel_delayed_work_sync(). I would have thought that forward progress would still be guaranteed in that case. Is it true that it is not?