mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Rabin Vincent <rabin.vincent@axis.com>
Cc: Jesper Nilsson <jespern@axis.com>, linux-kernel@vger.kernel.org
Subject: Re: Soft lockups in __cancel_work_timer()
Date: Fri, 6 Feb 2015 13:01:37 -0500	[thread overview]
Message-ID: <20150206180137.GC10580@htj.dyndns.org> (raw)
In-Reply-To: <20150206171156.GA8942@axis.com>

Hello,

On Fri, Feb 06, 2015 at 06:11:56PM +0100, Rabin Vincent wrote:
> task1                           task2                           worker
> 
>                                                                 add to busy hash
>                                                                 clear pending
>                                                                 exec work
> 
> __cancel_work_timer()
>  try_to_grab_pending()
>    get pending, return 0
>  set work cancelling
>  flush_work()
>    wait_for_completion()
> 
>                                                                 remove from busy_hash
> 
>                                 __cancel_work_timer()
>                                 while (forever) {
>                                   try_to_grab_pending()
>                                     return -ENOENT due to cancelling
>                                   flush_work
>                                     return false due to already gone
>                                 }
> 
> 
> On kernels with CONFIG_PREEMPT disabled, this causes a permanent soft
> lockup of the system.

Ah, drat.

> Adding a cond_resched() to the loop in cancel_delayed_work_sync(), like
> below, helps the simple !PREEMPT case, but does not completely fix the
> problem, because the problem can still be seen if the thread which sees
> the ENOENT has for example SCHED_FIFO scheduling class, both on systems
> with CONFIG_PREEMPT enabled and on !PREEMPT with the cond_resched().
> 
> We've seen this problem with the cancel_delayed_work() call in
> jffs2_sync_fs(), but I've attached a testing patch which forces the
> problem on current mainline without the need for jffs2.
...
> @@ -2741,6 +2741,9 @@ static bool __cancel_work_timer(struct work_struct *work, bool is_dwork)
>  		 */
>  		if (unlikely(ret == -ENOENT))
>  			flush_work(work);
> +
> +		if (ret < 0)
> +			cond_resched();
>  	} while (unlikely(ret < 0));

Well, an obvious thing to do would be

		if (unlikely(ret == -ENOENT)) {
			if (!flush_work(work))
				schedule_timeout(1);
		}

It was gonna block for the work item anyway so I don't think
schedule_timeout() there is a problem.  That said, given that we're
guaranteed to be able to dereference @work there, there probably is a
better way.  I'll think more about it.

Thanks.

-- 
tejun

  reply	other threads:[~2015-02-06 18:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-06 17:11 Rabin Vincent
2015-02-06 18:01 ` Tejun Heo [this message]
2015-02-09 16:15 ` [PATCH for-3.20-fixes] workqueue: fix hang involving racing cancel[_delayed]_work_sync()'s for PREEMPT_NONE Tejun Heo
2015-02-09 16:29   ` Jesper Nilsson
2015-02-10  8:35     ` Jesper Nilsson
2015-02-10  9:33   ` Rabin Vincent
2015-03-02 12:26   ` Jesper Nilsson
2015-03-02 16:21     ` Tejun Heo
2015-03-03  7:52       ` Jesper Nilsson
2015-03-03 10:00       ` Tomeu Vizoso
2015-03-03 13:21         ` Tejun Heo
2015-03-03 13:45           ` [PATCH wq/for-4.0-fixes v2] " Tejun Heo
2015-03-03 13:57             ` Tomeu Vizoso
2015-03-05  9:24               ` Tomeu Vizoso
2015-03-05  9:36                 ` Tejun Heo
2015-03-05 11:46                   ` Tejun Heo
2015-03-05 13:03                 ` [PATCH v3 wq/for-4.0-fixes] " Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150206180137.GC10580@htj.dyndns.org \
    --to=tj@kernel.org \
    --cc=jespern@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rabin.vincent@axis.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome