All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Felipe Balbi <balbi@kernel.org>
Subject: Re: [RFC PATCH] sched/wait: Make interruptible exclusive waitqueue wakeups reliable
Date: Tue, 10 Dec 2019 18:30:08 +0100	[thread overview]
Message-ID: <20191210173007.GA14449@redhat.com> (raw)
In-Reply-To: <20191210072921.GB114501@gmail.com>

On 12/10, Ingo Molnar wrote:
>
> --- a/kernel/sched/wait.c
> +++ b/kernel/sched/wait.c
> @@ -290,6 +290,11 @@ long prepare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_en
>  		 * But we need to ensure that set-condition + wakeup after that
>  		 * can't see us, it should wake up another exclusive waiter if
>  		 * we fail.
> +		 *
> +		 * In other words, if an exclusive waiter got here, then the
> +		 * waitqueue condition is and stays true and we are guaranteed
> +		 * to exit the waitqueue loop and will ignore the -ERESTARTSYS
> +		 * and return success.
>  		 */
>  		list_del_init(&wq_entry->entry);
>  		ret = -ERESTARTSYS;

Agreed, this makes it more clear... but at the same time technically this is
not 100% correct, or perhaps I misread this comment.

We are not guaranteed to return success even if condition == T and we were
woken up as an exclusive waiter, another waiter can consume the condition.
But this is fine. Say,

	long LOCK;
	wait_queue_head WQ;

	int lock()
	{
		return wait_event_interruptible_exclusive(&WQ, xchg(&LOCK, 1) == 0);
	}

	void unlock()
	{
		xchg(&LOCK, 0);
		wake_up(&WQ, TASK_NORMAL);
	}

A woken exclusive waiter can return -ERESTARTSYS if it races with another
lock(), or it races with another sleeping waiter woken up by the signal,
this is fine.

So may be

		 * In other words, if an exclusive waiter got here and the
		 * waitqueue condition is and stays true, then we are guaranteed
		 * to exit the waitqueue loop and will ignore the -ERESTARTSYS
		 * and return success.

is more accurate?

Oleg.


  reply	other threads:[~2019-12-10 17:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-08 21:12 Fundamental race condition in wait_event_interruptible_exclusive() ? Linus Torvalds
2019-12-09  9:18 ` [RFC PATCH] sched/wait: Make interruptible exclusive waitqueue wakeups reliable Ingo Molnar
2019-12-09 10:27   ` Ingo Molnar
2019-12-09 13:00     ` Oleg Nesterov
2019-12-10  7:21       ` Ingo Molnar
2019-12-10 19:19         ` [PATCH] sched/wait: fix ___wait_var_event(exclusive) Oleg Nesterov
2019-12-17 12:39           ` [tip: sched/core] " tip-bot2 for Oleg Nesterov
2019-12-09 18:06     ` [RFC PATCH] sched/wait: Make interruptible exclusive waitqueue wakeups reliable Linus Torvalds
2019-12-09 12:08   ` Oleg Nesterov
2019-12-10  7:29     ` Ingo Molnar
2019-12-10 17:30       ` Oleg Nesterov [this message]
2019-12-09 17:38 ` Fundamental race condition in wait_event_interruptible_exclusive() ? Oleg Nesterov
2019-12-09 18:03   ` Linus Torvalds

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=20191210173007.GA14449@redhat.com \
    --to=oleg@redhat.com \
    --cc=balbi@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.guittot@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.