New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 655255 link

Starred by 2 users

Issue metadata

Status: Verified
Owner:
Closed: Oct 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 2
Type: Bug



Sign in to add a comment

usleep_range might return early

Project Member Reported by diand...@chromium.org, Oct 12 2016

Issue description

Forked from http://crosbug.com/p/58431

...we've fixed this on kernel-4.4, but we should decide if we want to port it to our other kernel trees:
* 3.8
* 3.10
* 3.14
* 3.18
 
From the original bug:

---

#8 snanda@google.com
IMO, we should cherry-pick this to older kernels.

dtor, groeck, thoughts?

---

#9 groeck@google.com
cherry-pick. "someone was relying on the old behavior" would be someone relying on a bug.

Sounds like we want to pick it.  Should I do the honors?

Comment 4 by snanda@chromium.org, Oct 13 2016

Yes, please.
For 3.14, which it's easy for me to test, I have it here.  I added a few patches to make the pick cleaner...

remote:   https://chromium-review.googlesource.com/398239 BACKPORT: timer: Remove pointless return value of do_usleep_range()
remote:   https://chromium-review.googlesource.com/398240 UPSTREAM: ktime: add ktime_after and ktime_before helper
remote:   https://chromium-review.googlesource.com/398241 FROMLIST: timers: Fix usleep_range() in the context of wake_up_process()

Once reviewed, I'll pick to more places...
Project Member

Comment 6 by bugdroid1@chromium.org, Oct 14 2016

Labels: merge-merged-chromeos-3.14
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/b0ee78c01b0b966f2f687e8fea4207996e0d3cf6

commit b0ee78c01b0b966f2f687e8fea4207996e0d3cf6
Author: Thomas Gleixner <tglx@linutronix.de>
Date: Tue Apr 14 21:09:28 2015

BACKPORT: timer: Remove pointless return value of do_usleep_range()

The only user ignores it anyway and rightfully so.

BUG= chromium:655255 
TEST=Build and boot

Conflicts:
	kernel/timer.c
...because this moved to kernel/time/timer.c upstream.

Change-Id: Idbee3f9774f863c8bf836b3762362d3d5308a88a
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20150414203503.756060258@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 6deba083e1de3f92f65c9849254e92a1ef001b73)
Reviewed-on: https://chromium-review.googlesource.com/398239
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/b0ee78c01b0b966f2f687e8fea4207996e0d3cf6/kernel/timer.c

Project Member

Comment 7 by bugdroid1@chromium.org, Oct 14 2016

Labels: merge-merged-chromeos-3.8
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/bbc41c8c317ef5181c2552e3a93960115984042e

commit bbc41c8c317ef5181c2552e3a93960115984042e
Author: Thomas Gleixner <tglx@linutronix.de>
Date: Tue Apr 14 21:09:28 2015

BACKPORT: timer: Remove pointless return value of do_usleep_range()

The only user ignores it anyway and rightfully so.

BUG= chromium:655255 
TEST=Build and boot

Conflicts:
	kernel/timer.c
...because this moved to kernel/time/timer.c upstream.

Change-Id: Idbee3f9774f863c8bf836b3762362d3d5308a88a
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20150414203503.756060258@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 6deba083e1de3f92f65c9849254e92a1ef001b73)
Reviewed-on: https://chromium-review.googlesource.com/398220
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/bbc41c8c317ef5181c2552e3a93960115984042e/kernel/timer.c

Project Member

Comment 8 by bugdroid1@chromium.org, Oct 14 2016

Labels: merge-merged-chromeos-3.18
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/28a51a42eae79cc2225c0e3451b782186de003d8

commit 28a51a42eae79cc2225c0e3451b782186de003d8
Author: Thomas Gleixner <tglx@linutronix.de>
Date: Tue Apr 14 21:09:28 2015

UPSTREAM: timer: Remove pointless return value of do_usleep_range()

The only user ignores it anyway and rightfully so.

BUG= chromium:655255 
TEST=Build and boot

Change-Id: Idbee3f9774f863c8bf836b3762362d3d5308a88a
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20150414203503.756060258@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 6deba083e1de3f92f65c9849254e92a1ef001b73)
Reviewed-on: https://chromium-review.googlesource.com/398200
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/28a51a42eae79cc2225c0e3451b782186de003d8/kernel/time/timer.c

Project Member

Comment 9 by bugdroid1@chromium.org, Oct 14 2016

Labels: merge-merged-chromeos-3.10
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/0cadf6c20d52be99a5973c0e827dc5a5379df9d3

commit 0cadf6c20d52be99a5973c0e827dc5a5379df9d3
Author: Thomas Gleixner <tglx@linutronix.de>
Date: Tue Apr 14 21:09:28 2015

BACKPORT: timer: Remove pointless return value of do_usleep_range()

The only user ignores it anyway and rightfully so.

BUG= chromium:655255 
TEST=Build and boot

Conflicts:
	kernel/timer.c
...because this moved to kernel/time/timer.c upstream.

Change-Id: Idbee3f9774f863c8bf836b3762362d3d5308a88a
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20150414203503.756060258@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 6deba083e1de3f92f65c9849254e92a1ef001b73)
Reviewed-on: https://chromium-review.googlesource.com/398221
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/0cadf6c20d52be99a5973c0e827dc5a5379df9d3/kernel/timer.c

Project Member

Comment 10 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/fbf6a266c23f5c3448e5d23be1fd6e2faf4a481b

commit fbf6a266c23f5c3448e5d23be1fd6e2faf4a481b
Author: Daniel Borkmann <dborkman@redhat.com>
Date: Wed Jun 11 16:19:28 2014

BACKPORT: ktime: add ktime_after and ktime_before helper

Add two minimal helper functions analogous to time_before() and
time_after() that will later on both be needed by SCTP code.

BUG= chromium:655255 
TEST=Build and boot

Conflicts:
	net/sctp/sm_make_chunk.c
...skipped the change to net/sctp/sm_make_chunk.c because it really
wasn't needed and didn't apply to this version of the kernel

Change-Id: Iba0afba4b5f1f9a382371badf13e5f426ca3e88b
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 67cb9366ff5f99868100198efba5ca88aaa6ad25)
Reviewed-on: https://chromium-review.googlesource.com/398378
Commit-Ready: Douglas Anderson <dianders@chromium.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/fbf6a266c23f5c3448e5d23be1fd6e2faf4a481b/include/linux/ktime.h

Project Member

Comment 11 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/48f381ee49a2580032275937fcbf51eb0e3b274f

commit 48f381ee49a2580032275937fcbf51eb0e3b274f
Author: Daniel Borkmann <dborkman@redhat.com>
Date: Wed Jun 11 16:19:28 2014

UPSTREAM: ktime: add ktime_after and ktime_before helper

Add two minimal helper functions analogous to time_before() and
time_after() that will later on both be needed by SCTP code.

BUG= chromium:655255 
TEST=Build and boot

Change-Id: Iba0afba4b5f1f9a382371badf13e5f426ca3e88b
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 67cb9366ff5f99868100198efba5ca88aaa6ad25)
Reviewed-on: https://chromium-review.googlesource.com/398240
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/48f381ee49a2580032275937fcbf51eb0e3b274f/include/linux/ktime.h
[modify] https://crrev.com/48f381ee49a2580032275937fcbf51eb0e3b274f/net/sctp/sm_make_chunk.c

Project Member

Comment 12 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/48f381ee49a2580032275937fcbf51eb0e3b274f

commit 48f381ee49a2580032275937fcbf51eb0e3b274f
Author: Daniel Borkmann <dborkman@redhat.com>
Date: Wed Jun 11 16:19:28 2014

UPSTREAM: ktime: add ktime_after and ktime_before helper

Add two minimal helper functions analogous to time_before() and
time_after() that will later on both be needed by SCTP code.

BUG= chromium:655255 
TEST=Build and boot

Change-Id: Iba0afba4b5f1f9a382371badf13e5f426ca3e88b
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 67cb9366ff5f99868100198efba5ca88aaa6ad25)
Reviewed-on: https://chromium-review.googlesource.com/398240
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/48f381ee49a2580032275937fcbf51eb0e3b274f/include/linux/ktime.h
[modify] https://crrev.com/48f381ee49a2580032275937fcbf51eb0e3b274f/net/sctp/sm_make_chunk.c

Project Member

Comment 13 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/48f381ee49a2580032275937fcbf51eb0e3b274f

commit 48f381ee49a2580032275937fcbf51eb0e3b274f
Author: Daniel Borkmann <dborkman@redhat.com>
Date: Wed Jun 11 16:19:28 2014

UPSTREAM: ktime: add ktime_after and ktime_before helper

Add two minimal helper functions analogous to time_before() and
time_after() that will later on both be needed by SCTP code.

BUG= chromium:655255 
TEST=Build and boot

Change-Id: Iba0afba4b5f1f9a382371badf13e5f426ca3e88b
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 67cb9366ff5f99868100198efba5ca88aaa6ad25)
Reviewed-on: https://chromium-review.googlesource.com/398240
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/48f381ee49a2580032275937fcbf51eb0e3b274f/include/linux/ktime.h
[modify] https://crrev.com/48f381ee49a2580032275937fcbf51eb0e3b274f/net/sctp/sm_make_chunk.c

Project Member

Comment 14 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/6702353d7f62817fd2a345985479087e69079090

commit 6702353d7f62817fd2a345985479087e69079090
Author: Douglas Anderson <dianders@chromium.org>
Date: Mon Oct 10 21:04:02 2016

FROMLIST: timers: Fix usleep_range() in the context of wake_up_process()

Users of usleep_range() expect that it will _never_ return in less time
than the minimum passed parameter.  However, nothing in any of the code
ensures this.  Specifically:

usleep_range() => do_usleep_range() => schedule_hrtimeout_range() =>
schedule_hrtimeout_range_clock() just ends up calling schedule() with an
appropriate timeout set using the hrtimer.  If someone else happens to
wake up our task then we'll happily return from usleep_range() early.

msleep() already has code to handle this case since it will loop as long
as there was still time left.  usleep_range() had no such loop.

The problem is is easily demonstrated with a small bit of test code:

  static int usleep_test_task(void *data)
  {
    atomic_t *done = data;
    ktime_t start, end;

    start = ktime_get();
    usleep_range(50000, 100000);
    end = ktime_get();
    pr_info("Requested 50000 - 100000 us.  Actually slept for %llu us\n",
      (unsigned long long)ktime_to_us(ktime_sub(end, start)));
    atomic_set(done, 1);

    return 0;
  }

  static void run_usleep_test(void)
  {
    struct task_struct *t;
    atomic_t done;

    atomic_set(&done, 0);

    t = kthread_run(usleep_test_task, &done, "usleep_test_task");
    while (!atomic_read(&done)) {
      wake_up_process(t);
      udelay(1000);
    }
    kthread_stop(t);
  }

If you run the above code without this patch you get things like:
  Requested 50000 - 100000 us.  Actually slept for 967 us

If you run the above code _with_ this patch, you get:
  Requested 50000 - 100000 us.  Actually slept for 50001 us

Presumably this problem was not detected before because:
- It's not terribly common to use wake_up_process() directly.
- Other ways for processes to wake up are not typically mixed with
  usleep_range().
- There aren't lots of places that use usleep_range(), since many people
  call either msleep() or udelay().

BUG= chromium:655255 
TEST=See CL:Ib2eaa31e272c15a9a7a17796a4b22fe954f332bf

Conflicts:
	kernel/timer.c
...due to upstream having "delta" as u64.
...because this moved to kernel/time/timer.c upstream.

Change-Id: Ibb93ce0dd9fb9688d4a8d10447c098c1dfbd7a1d
Reported-by: Tao Huang <huangtao@rock-chips.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(am from https://patchwork.kernel.org/patch/9369963/)
Reviewed-on: https://chromium-review.googlesource.com/396132
Tested-by: Jianqun Xu <jay.xu@rock-chips.com>
Tested-by: Eric gao <eric.gao@rock-chips.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Tao Huang <huangtao@rock-chips.com>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@google.com>
Reviewed-by: Eric gao <eric.gao@rock-chips.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
(cherry picked from commit f5f520d79ec610cc9c7faf8d6aa73cb5ecbac792)
Reviewed-on: https://chromium-review.googlesource.com/398241

[modify] https://crrev.com/6702353d7f62817fd2a345985479087e69079090/kernel/timer.c

Project Member

Comment 15 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/11f3b5b2dbc551298070e48dacedeb9aff1d4b35

commit 11f3b5b2dbc551298070e48dacedeb9aff1d4b35
Author: Daniel Borkmann <dborkman@redhat.com>
Date: Wed Jun 11 16:19:28 2014

BACKPORT: ktime: add ktime_after and ktime_before helper

Add two minimal helper functions analogous to time_before() and
time_after() that will later on both be needed by SCTP code.

BUG= chromium:655255 
TEST=Build and boot

Conflicts:
	net/sctp/sm_make_chunk.c
...skipped the change to net/sctp/sm_make_chunk.c because it really
wasn't needed and didn't apply to this version of the kernel

Change-Id: Iba0afba4b5f1f9a382371badf13e5f426ca3e88b
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 67cb9366ff5f99868100198efba5ca88aaa6ad25)
Reviewed-on: https://chromium-review.googlesource.com/398222
Commit-Ready: Douglas Anderson <dianders@chromium.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>

[modify] https://crrev.com/11f3b5b2dbc551298070e48dacedeb9aff1d4b35/include/linux/ktime.h

Project Member

Comment 16 by bugdroid1@chromium.org, Oct 14 2016

Labels: merge-merged-chromeos-3.10
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/421ffdd75ec5256b8bf71e3511b1cfa17b28c919

commit 421ffdd75ec5256b8bf71e3511b1cfa17b28c919
Author: Douglas Anderson <dianders@chromium.org>
Date: Mon Oct 10 21:04:02 2016

FROMLIST: timers: Fix usleep_range() in the context of wake_up_process()

Users of usleep_range() expect that it will _never_ return in less time
than the minimum passed parameter.  However, nothing in any of the code
ensures this.  Specifically:

usleep_range() => do_usleep_range() => schedule_hrtimeout_range() =>
schedule_hrtimeout_range_clock() just ends up calling schedule() with an
appropriate timeout set using the hrtimer.  If someone else happens to
wake up our task then we'll happily return from usleep_range() early.

msleep() already has code to handle this case since it will loop as long
as there was still time left.  usleep_range() had no such loop.

The problem is is easily demonstrated with a small bit of test code:

  static int usleep_test_task(void *data)
  {
    atomic_t *done = data;
    ktime_t start, end;

    start = ktime_get();
    usleep_range(50000, 100000);
    end = ktime_get();
    pr_info("Requested 50000 - 100000 us.  Actually slept for %llu us\n",
      (unsigned long long)ktime_to_us(ktime_sub(end, start)));
    atomic_set(done, 1);

    return 0;
  }

  static void run_usleep_test(void)
  {
    struct task_struct *t;
    atomic_t done;

    atomic_set(&done, 0);

    t = kthread_run(usleep_test_task, &done, "usleep_test_task");
    while (!atomic_read(&done)) {
      wake_up_process(t);
      udelay(1000);
    }
    kthread_stop(t);
  }

If you run the above code without this patch you get things like:
  Requested 50000 - 100000 us.  Actually slept for 967 us

If you run the above code _with_ this patch, you get:
  Requested 50000 - 100000 us.  Actually slept for 50001 us

Presumably this problem was not detected before because:
- It's not terribly common to use wake_up_process() directly.
- Other ways for processes to wake up are not typically mixed with
  usleep_range().
- There aren't lots of places that use usleep_range(), since many people
  call either msleep() or udelay().

BUG= chromium:655255 
TEST=See CL:Ib2eaa31e272c15a9a7a17796a4b22fe954f332bf

Conflicts:
	kernel/timer.c
...due to upstream having "delta" as u64.
...because this moved to kernel/time/timer.c upstream.

Change-Id: Ibb93ce0dd9fb9688d4a8d10447c098c1dfbd7a1d
Reported-by: Tao Huang <huangtao@rock-chips.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(am from https://patchwork.kernel.org/patch/9369963/)
Reviewed-on: https://chromium-review.googlesource.com/396132
Tested-by: Jianqun Xu <jay.xu@rock-chips.com>
Tested-by: Eric gao <eric.gao@rock-chips.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Tao Huang <huangtao@rock-chips.com>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@google.com>
Reviewed-by: Eric gao <eric.gao@rock-chips.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
(cherry picked from commit f5f520d79ec610cc9c7faf8d6aa73cb5ecbac792)
Reviewed-on: https://chromium-review.googlesource.com/398241
(cherry picked from commit 6702353d7f62817fd2a345985479087e69079090)
Reviewed-on: https://chromium-review.googlesource.com/399159

[modify] https://crrev.com/421ffdd75ec5256b8bf71e3511b1cfa17b28c919/kernel/timer.c

Project Member

Comment 17 by bugdroid1@chromium.org, Oct 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/8b2233402f51a5b83019c5e4c10de621763fbd75

commit 8b2233402f51a5b83019c5e4c10de621763fbd75
Author: Douglas Anderson <dianders@chromium.org>
Date: Mon Oct 10 21:04:02 2016

FROMLIST: timers: Fix usleep_range() in the context of wake_up_process()

Users of usleep_range() expect that it will _never_ return in less time
than the minimum passed parameter.  However, nothing in any of the code
ensures this.  Specifically:

usleep_range() => do_usleep_range() => schedule_hrtimeout_range() =>
schedule_hrtimeout_range_clock() just ends up calling schedule() with an
appropriate timeout set using the hrtimer.  If someone else happens to
wake up our task then we'll happily return from usleep_range() early.

msleep() already has code to handle this case since it will loop as long
as there was still time left.  usleep_range() had no such loop.

The problem is is easily demonstrated with a small bit of test code:

  static int usleep_test_task(void *data)
  {
    atomic_t *done = data;
    ktime_t start, end;

    start = ktime_get();
    usleep_range(50000, 100000);
    end = ktime_get();
    pr_info("Requested 50000 - 100000 us.  Actually slept for %llu us\n",
      (unsigned long long)ktime_to_us(ktime_sub(end, start)));
    atomic_set(done, 1);

    return 0;
  }

  static void run_usleep_test(void)
  {
    struct task_struct *t;
    atomic_t done;

    atomic_set(&done, 0);

    t = kthread_run(usleep_test_task, &done, "usleep_test_task");
    while (!atomic_read(&done)) {
      wake_up_process(t);
      udelay(1000);
    }
    kthread_stop(t);
  }

If you run the above code without this patch you get things like:
  Requested 50000 - 100000 us.  Actually slept for 967 us

If you run the above code _with_ this patch, you get:
  Requested 50000 - 100000 us.  Actually slept for 50001 us

Presumably this problem was not detected before because:
- It's not terribly common to use wake_up_process() directly.
- Other ways for processes to wake up are not typically mixed with
  usleep_range().
- There aren't lots of places that use usleep_range(), since many people
  call either msleep() or udelay().

BUG= chromium:655255 
TEST=See CL:Ib2eaa31e272c15a9a7a17796a4b22fe954f332bf

Conflicts:
	kernel/timer.c
...due to upstream having "delta" as u64.
...because this moved to kernel/time/timer.c upstream.

Change-Id: Ibb93ce0dd9fb9688d4a8d10447c098c1dfbd7a1d
Reported-by: Tao Huang <huangtao@rock-chips.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(am from https://patchwork.kernel.org/patch/9369963/)
Reviewed-on: https://chromium-review.googlesource.com/396132
Tested-by: Jianqun Xu <jay.xu@rock-chips.com>
Tested-by: Eric gao <eric.gao@rock-chips.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Tao Huang <huangtao@rock-chips.com>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@google.com>
Reviewed-by: Eric gao <eric.gao@rock-chips.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
(cherry picked from commit f5f520d79ec610cc9c7faf8d6aa73cb5ecbac792)
Reviewed-on: https://chromium-review.googlesource.com/398241
(cherry picked from commit 6702353d7f62817fd2a345985479087e69079090)
Reviewed-on: https://chromium-review.googlesource.com/399158

[modify] https://crrev.com/8b2233402f51a5b83019c5e4c10de621763fbd75/kernel/timer.c

Status: Fixed (was: Untriaged)
Fixed everywhere.  Hopefully upstream will decide to land, too.
Labels: Merge-Request-55

Comment 20 by dimu@chromium.org, Oct 20 2016

Labels: -Merge-Request-55 Merge-Approved-55 Hotlist-Merge-Approved
Your change meets the bar and is auto-approved for M55 (branch: 2883)
Project Member

Comment 21 by bugdroid1@chromium.org, Oct 20 2016

Labels: merge-merged-release-R55-8872.B-chromeos-3.18
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/third_party/kernel/+/4728b2ac85a30eb5d89c77938d30955b4bae6480

commit 4728b2ac85a30eb5d89c77938d30955b4bae6480
Author: Thomas Gleixner <tglx@linutronix.de>
Date: Tue Apr 14 21:09:28 2015

UPSTREAM: timer: Remove pointless return value of do_usleep_range()

The only user ignores it anyway and rightfully so.

BUG= chromium:655255 
TEST=Build and boot

Change-Id: Idbee3f9774f863c8bf836b3762362d3d5308a88a
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20150414203503.756060258@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
(cherry picked from commit 6deba083e1de3f92f65c9849254e92a1ef001b73)
Previous-Reviewed-on: https://chromium-review.googlesource.com/398200
(cherry picked from commit 356ad6b868f5eab7bf5db19e1b76ff1820ffd8b4)
Reviewed-on: https://chromium-review.googlesource.com/401262
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Commit-Queue: Daniel Kurtz <djkurtz@chromium.org>
Tested-by: Daniel Kurtz <djkurtz@chromium.org>
Trybot-Ready: Daniel Kurtz <djkurtz@chromium.org>

[modify] https://crrev.com/4728b2ac85a30eb5d89c77938d30955b4bae6480/kernel/time/timer.c

Project Member

Comment 22 by sheriffbot@chromium.org, Oct 23 2016

This issue has been approved for a merge. Please merge the fix to any appropriate branches as soon as possible!

If all merges have been completed, please remove any remaining Merge-Approved labels from this issue.

Thanks for your time! To disable nags, add the Disable-Nags label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Labels: -Merge-Approved-55 Merge-Merged
Opening  bug #658801  to track getting the newer version upstream.

Comment 24 by ka...@chromium.org, Jan 13 2017

Status: Verified (was: Fixed)

Sign in to add a comment