From: Peter Zijlstra <peterz@infradead.org>
To: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: "mingo@kernel.org" <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>, Neil Brown <neilb@suse.de>,
Michael Shaver <jmshaver@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH] sched: Avoid that __wait_on_bit_lock() hangs
Date: Wed, 3 Aug 2016 20:11:28 +0200 [thread overview]
Message-ID: <20160803181128.GH6879@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <d3e0bd29-9844-f61b-dcc3-55638fbbd9ba@sandisk.com>
On Wed, Aug 03, 2016 at 09:35:03AM -0700, Bart Van Assche wrote:
> If try_to_wakeup() reads the task state before abort_exclusive_wait()
> sets the task state and if autoremove_wake_function() is called after
> abort_exclusive_wait() has removed a task from a wait list then the
> cascading mechanism for exclusive wakeups in abort_exclusive_wait()
> won't be triggered. Avoid this by serializing the task state change
> in abort_exclusive_wait() and try_to_wakeup().
I'm dense.. what!?
CPU0 CPU1 CPU2
__lock_page_killable()
__wait_on_bit_lock()
bit_wait_io()
schedule()
__wake_up_bit()
__wake_up(.nr_exclusive=1)
spin_lock(&q->lock)
__wake_up_common()
autoremove_wake_func()
try_to_wake_up(p, TASK_NORMAL)
list_del_init(&wait->task_list)
spin_unlock(&q->lock)
complete_signal(p)
signal_wake_up(p, 1)
sigaddset(&p->pending.signal, SIGKILL)
try_to_wake_up(p, TASK_WAKEKILL)
if (signal_pending_state(TASK_KILLABLE))
return -EINTR;
abort_exclusive_wait()
__set_current_state(RUNNING)
spin_lock(q->lock)
if (!list_empty()) /* empty */
else if (waitqueue_active()) /* pending ? */
__wake_up_locked_key(q, mode, key)
spin_unlock(q->lock)
That seems to do the right thing, so clearly I misunderstand. Please
clarify.
> +++ b/kernel/sched/wait.c
> @@ -277,10 +277,17 @@ void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait,
> unsigned int mode, void *key)
> {
> unsigned long flags;
> + long wake_up;
> +
> + /* Serialize against try_to_wake_up() */
> + raw_spin_lock_irqsave(¤t->pi_lock, flags);
> + wake_up = current->state & (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE);
> + if (wake_up)
> + __set_current_state(TASK_RUNNING);
> + raw_spin_unlock_irqrestore(¤t->pi_lock, flags);
>
> - __set_current_state(TASK_RUNNING);
> spin_lock_irqsave(&q->lock, flags);
> - if (!list_empty(&wait->task_list))
> + if (wake_up)
> list_del_init(&wait->task_list);
> else if (waitqueue_active(q))
> __wake_up_locked_key(q, mode, key);
That just feels wrong,.. very wrong.
next prev parent reply other threads:[~2016-08-03 19:42 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-03 16:35 [PATCH] sched: Avoid that __wait_on_bit_lock() hangs Bart Van Assche
2016-08-03 18:11 ` Peter Zijlstra [this message]
2016-08-03 18:56 ` Bart Van Assche
2016-08-03 21:30 ` Oleg Nesterov
2016-08-03 21:51 ` Bart Van Assche
2016-08-04 14:09 ` Peter Zijlstra
2016-08-04 14:31 ` Bart Van Assche
2016-08-05 17:41 ` Bart Van Assche
2016-08-08 10:22 ` Peter Zijlstra
2016-08-08 14:38 ` Bart Van Assche
2016-08-08 16:20 ` Oleg Nesterov
2016-08-08 18:31 ` Bart Van Assche
2016-08-09 17:14 ` Oleg Nesterov
2016-08-09 18:48 ` Bart Van Assche
2016-08-09 23:10 ` Bart Van Assche
2016-08-10 10:45 ` Oleg Nesterov
2016-08-10 16:01 ` Bart Van Assche
2016-08-10 16:27 ` Oleg Nesterov
2016-08-10 19:58 ` Bart Van Assche
2016-08-11 17:36 ` Oleg Nesterov
2016-08-12 16:16 ` Oleg Nesterov
2016-08-12 16:27 ` Bart Van Assche
2016-08-12 22:47 ` Bart Van Assche
2016-08-13 16:32 ` Oleg Nesterov
2016-08-15 23:39 ` Bart Van Assche
2016-08-16 13:06 ` Oleg Nesterov
2016-08-16 16:54 ` Bart Van Assche
2016-08-17 17:30 ` Oleg Nesterov
2016-08-13 17:07 ` Oleg Nesterov
2016-08-09 23:56 ` Bart Van Assche
2016-08-10 10:57 ` Oleg Nesterov
2016-08-10 11:03 ` Peter Zijlstra
2016-08-04 0:05 ` Bart Van Assche
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=20160803181128.GH6879@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=bart.vanassche@sandisk.com \
--cc=hannes@cmpxchg.org \
--cc=jmshaver@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=neilb@suse.de \
--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