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]
Date:	Wed, 11 Nov 2015 17:48:29 +0800
From:	Herbert Xu <herbert@...dor.apana.org.au>
To:	Peter Zijlstra <peterz@...radead.org>
Cc:	tatsu@...jp.nec.com, mingo@...hat.com,
	linux-kernel@...r.kernel.org,
	"David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
	Jiri Olsa <jolsa@...hat.com>,
	Eric Dumazet <eric.dumazet@...il.com>
Subject: Re: [PATCH v2] wait: add comment before waitqueue_active noting
 memory barrier is required

Peter Zijlstra <peterz@...radead.org> wrote:
>
>> >> Second, on the waiting thread side, the CPU can reorder the load of
>> >> CONDITION to occur during add_wait_queue active, before the entry is
>> >> added to the wait queue.
>> >>      wake_up thread                 waiting thread
>> >>                                       (reordered)
>> >> ------------------------------------------------------------------------
>> >>                                 spin_lock_irqsave(...)      <add_wait_queue>
>> >>                                 if (CONDITION)
>> >> CONDITION = 1;
>> >> if (waitqueue_active(wq))
>> >     wake_up();
>> >>                                 __add_wait_queue(...)       <add_wait_queue>
>> >>                                 spin_unlock_irqrestore(...) <add_wait_queue>
>> >>                                 wait_woken(&wait, ...);
>> >> ------------------------------------------------------------------------
>> > 
>> > This isn't actually a problem IIRC, because wait_woken() will test
>> > WQ_FLAG_WOKEN and not actually sleep.
>> 
>> In the above figure, waitqueue_active(wq) will return 0 (queue is
>> inactive) and skip the whole wake_up() call, because __add_wait_queue()
>> hasn't been called yet.  This actually does occur using a reproducer.
> 
> Duh, indeed.

BTW, the networking folks found this years ago and even added
helpers to deal with this.  See for example wq_has_sleeper in
include/net/sock.h.  It would be good if we can move some of
those helpers into wait.h instead.

Thanks,
-- 
Email: Herbert Xu <herbert@...dor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists