lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191210173007.GA14449@redhat.com>
Date:   Tue, 10 Dec 2019 18:30:08 +0100
From:   Oleg Nesterov <oleg@...hat.com>
To:     Ingo Molnar <mingo@...nel.org>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Juri Lelli <juri.lelli@...hat.com>,
        Vincent Guittot <vincent.guittot@...aro.org>,
        Miklos Szeredi <miklos@...redi.hu>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Felipe Balbi <balbi@...nel.org>
Subject: Re: [RFC PATCH] sched/wait: Make interruptible exclusive waitqueue
 wakeups reliable

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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ