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: <20131119104438.6d45828b@notabene.brown>
Date:	Tue, 19 Nov 2013 10:44:38 +1100
From:	NeilBrown <neilb@...e.de>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	lkml <linux-kernel@...r.kernel.org>,
	"Dr. H. Nikolaus Schaller" <hns@...delico.com>,
	Marek Belisko <marek@...delico.com>,
	Mark Brown <broonie@...nel.org>
Subject: Re: [PATCH/RFC] wait_for_completion_timeout() considered harmful.

On Mon, 18 Nov 2013 15:27:46 -0800 Andrew Morton <akpm@...ux-foundation.org>
wrote:

> On Sun, 17 Nov 2013 08:06:03 +1100 NeilBrown <neilb@...e.de> wrote:
> 
> > It would be reasonable to assume that
> > 
> >       wait_for_completion_timeout(&wm8350->auxadc_done, msecs_to_jiffies(5));
> > 
> > would wait at least 5 msecs for the auxadc_done to complete.  But it does not.
> > With a HZ of 200 or less, msecs_to_jiffies(5) has value '1', and so this
> > will only wait until the next "timer tick", which could happen immediately.
> > 
> > This can lead to incorrect results - and has done so in out-of-tree patches
> > for drivers/misc/bmp085.c which uses a very similar construct to enable interrupt
> > based result collection.
> > 
> > The documentation for several *_timeout* functions claim they will wait for
> > "timeout jiffies" to have elapsed where this is not the case.  They will
> > actually wait for "timeout" jiffies to have started implying an elapsed time
> > between (timeout-1) and (timeout).
> > 
> > This patch corrects some of this documentation, and adds a collection of
> >   wait_for_completion*_msecs()
> > interfaces which wait at least the given number of milliseconds for the
> > completion (or a signal).
> 
> Mutter.  wait_for_x(..., 5ms) should wait for a minimum of 5ms, no matter
> what.
> 
> So I'd suggest we make that happen, rather than adding some new interfaces?

I thought of that.  It would certainly be nice.

However what we have is 
         XXX_timeout(...., jiffies).
And if we decided that
         XXX_timeout(...., msecs_to_jiffies(5))
would only timeout after at least 5ms, then
         schedule_timeout(1)
would have to wait at least one full jiffie, which is quite different to what
it currently does.

We have loops that have
    timeout = schedule_timeout(timeout)
in the middle and if we change the semantics of schedule_timeout() to round
up, those loops could wait quite a bit longer than expected.

So I think that we do need to add new interfaces just like msleep() was introduced
a while back to fix all the various misuses of
    schedule_timeout(msecs_to_jiffies(XX))).

Possibly we can also discard old bad interfaces.
Maybe the *_timeout() interfaces should become *_until() where the jiffies
number isn't a count but is a value that we wait for "jiffies" to exceed.

I don't think there is a really easy solution, but thanks for pushing the
discussion along towards trying to understand one.

NeilBrown


Download attachment "signature.asc" of type "application/pgp-signature" (829 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ