mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Balbir Singh <bsingharora@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Nicholas Piggin <nicholas.piggin@gmail.com>
Subject: Re: [RFC][PATCH] Fix a race between rwsem and the scheduler
Date: Tue, 30 Aug 2016 14:19:37 +0200	[thread overview]
Message-ID: <20160830121937.GQ10138@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <4050f2ce-1aee-d2aa-39e3-36e995b56252@gmail.com>

On Tue, Aug 30, 2016 at 06:49:37PM +1000, Balbir Singh wrote:
> 
> 
> The origin of the issue I've seen seems to be related to
> rwsem spin lock stealing. Basically I see the system deadlock'd in the
> following state

As Nick says (good to see you're back Nick!), this is unrelated to
rwsems.

This is true for pretty much every blocking wait loop out there, they
all do:

	for (;;) {
		current->state = UNINTERRUPTIBLE;
		smp_mb();
		if (cond)
			break;
		schedule();
	}
	current->state = RUNNING;

Which, if the wakeup is spurious, is just the pattern you need.

> +++ b/kernel/sched/core.c
> @@ -2016,6 +2016,17 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
>  	success = 1; /* we're going to change ->state */
>  	cpu = task_cpu(p);
>  
> +	/*
> +	 * Ensure we see on_rq and p_state consistently
> +	 *
> +	 * For example in __rwsem_down_write_failed(), we have
> +	 *    [S] ->on_rq = 1				[L] ->state
> +	 *    MB					 RMB

There isn't an MB there. The best I can do is UNLOCK+LOCK, which, thanks
to PPC, is _not_ MB. It is however sufficient for this case.

> +	 *    [S] ->state = TASK_UNINTERRUPTIBLE	[L] ->on_rq
> +	 * In the absence of the RMB p->on_rq can be observed to be 0
> +	 * and we end up spinning indefinitely in while (p->on_cpu)
> +	 */


	/*
	 * Ensure we load p->on_rq _after_ p->state, otherwise it would
	 * be possible to, falsely, observe p->on_rq == 0 and get stuck
	 * in smp_cond_load_acquire() below.
	 *
	 * sched_ttwu_pending()			try_to_wake_up()
	 *   [S] p->on_rq = 1;			[L] P->state
	 *       UNLOCK rq->lock
	 *
	 * schedule()				RMB
	 *       LOCK rq->lock
	 *       UNLOCK rq->lock
	 *
	 * [task p]
	 *   [S] p->state = UNINTERRUPTIBLE	[L] p->on_rq
	 *
	 * Pairs with the UNLOCK+LOCK on rq->lock from the
	 * last wakeup of our task and the schedule that got our task
	 * current.
	 */

> +	smp_rmb();
>  	if (p->on_rq && ttwu_remote(p, wake_flags))
>  		goto stat;
>  


Now, this has been present for a fair while, I suspect ever since we
reworked the wakeup path to not use rq->lock twice. Curious you only now
hit it.

  parent reply	other threads:[~2016-08-30 12:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-30  8:49 Balbir Singh
2016-08-30  9:13 ` Nicholas Piggin
2016-08-30 12:19 ` Peter Zijlstra [this message]
2016-08-30 13:04   ` Oleg Nesterov
2016-08-30 14:13     ` Peter Zijlstra
2016-08-30 16:57       ` Oleg Nesterov
2016-08-30 18:34         ` Peter Zijlstra
2016-08-30 21:28           ` Benjamin Herrenschmidt
2016-08-31  7:18             ` Peter Zijlstra
2016-08-31 10:56               ` Benjamin Herrenschmidt
2016-08-31 13:31             ` Peter Zijlstra
2016-08-31 21:47               ` Benjamin Herrenschmidt
2016-09-01  6:49                 ` Balbir Singh
2016-09-01  6:57                 ` Peter Zijlstra
2016-09-01 14:17                   ` Boqun Feng
2016-09-01 15:33                     ` Peter Zijlstra
2016-08-30 21:25     ` Benjamin Herrenschmidt
2016-08-31  7:20       ` Peter Zijlstra
2016-08-31 10:55         ` Benjamin Herrenschmidt
2016-08-31  3:41   ` Balbir Singh
2016-08-31  7:28     ` Peter Zijlstra
2016-08-31 10:17       ` Balbir Singh
2016-08-31 10:57       ` Benjamin Herrenschmidt
2016-09-01  1:48       ` Alexey Kardashevskiy
2016-09-01 12:16         ` Alexey Kardashevskiy
2016-08-30 12:58 ` Oleg Nesterov
2016-08-31  3:25   ` Balbir Singh

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=20160830121937.GQ10138@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=benh@kernel.crashing.org \
    --cc=bsingharora@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicholas.piggin@gmail.com \
    --cc=oleg@redhat.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