Skip to content

hrtimers: Cleanup hrtimer_forward() [ab]use

Thomas Gleixner alsa-devel dri-devel intel-gfx linux-can linux-pm lkml netdev 1 version Applied

Status from this message: Thanks, applied now to sound git tree.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest11 patches 5 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/11hrtimer: Add a mechanism to catch runaway timerskernel/time/hrtimer.c+25 -01 reply
2/11mac80211-hwsim: Fix late beacon hrtimer handlingdrivers/net/wireless/mac80211_hwsim.c+2 -20 replies
3/11net: iosm: Use hrtimer_forward_now()drivers/net/wwan/iosm/iosm_ipc_imem.c+2 -20 replies
4/11ALSA: pcsp: Make hrtimer forwarding more robustsound/drivers/pcsp/pcsp_lib.c+1 -11 reply
5/11can: bcm: Use hrtimer_forward_now()net/can/bcm.c+1 -11 reply
6/11power: reset: ltc2952: Use hrtimer_forward_now()drivers/power/reset/ltc2952-poweroff.c+1 -31 reply
7/11drm/i915/pmu: Use hrtimer_forward_now()drivers/gpu/drm/i915/i915_pmu.c+1 -11 reply
8/11signal: Move itimer rearming into itimer codeinclude/linux/posix-timers.h kernel/signal.c kernel/time/itimer.c+18 -120 replies
9/11posix-timers: Fixup stale commnt and reduce ifdefferykernel/time/posix-timers.c+15 -230 replies
10/11posix-timers: Use hrtimer_forward_now()kernel/time/posix-timers.c+1 -20 replies
11/11hrtimer: Make hrtimer_forward() private to core timer codeinclude/linux/hrtimer.h kernel/time/hrtimer.c kernel/time/posix-timers.c +1 more+25 -260 replies

Reviews trailers per patch

2 of 11 patches have a Reviewed-by or Acked-by.

PatchThomas GleixnerTvrtko Ursulin
1/11
2/11R-b
3/11
4/11
5/11
6/11
7/11R-b
8/11
9/11
10/11
11/11

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [patch 00/11] hrtimers: Cleanup hrtimer_forward() [ab]use

A recent syzbot report unearthed abuse of hrtimer_forward() which can cause runaway timers hogging the CPU in timer expiry context by rearming the timer in the past over and over.

This happens when the caller uses timer->expiry for the 'now' argument of hrtimer_forward(). That works as long as the timer expiry is on time, but can cause a long period of rearm/fire loops which hog the CPU. Expiring late can have various causes, but obviously virtualization is prone to that due to VCPU scheduling.

The correct usage of hrtimer_forward() is to hand the current time to the 'now' argument which ensures that the next event on the periodic time line is past now. This is what hrtimer_forward_now() provides.

The following series addresses this:

1) Add a debug mechanism to the hrtimer expiry loop

2) Convert all hrtimer_forward() usage outside of kernel/time/ to use hrtimer_forward_now().

3) Confine hrtimer_forward() to kernel/time/ core code.

The mac80211_hwsim patch has already been picked up by the wireless maintainer and all other patches which affect usage outside the core code can be picked up by the relevant subsystems. If a maintainer wants me to pick a particular patch up, please let me know.

The last patch which confines hrtimer_forward() will be postponed until all other patches have been merged into Linus tree.

The series is also available from git:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git hrtimer

Thanks,

tglx

---
 drivers/gpu/drm/i915/i915_pmu.c        |    2 -
 drivers/net/wireless/mac80211_hwsim.c  |    4 +-
 drivers/net/wwan/iosm/iosm_ipc_imem.c  |    4 +-
 drivers/power/reset/ltc2952-poweroff.c |    4 --
 include/linux/hrtimer.h                |   26 -----------------
 include/linux/posix-timers.h           |    3 ++
 kernel/signal.c                        |   14 +--------
 kernel/time/hrtimer.c                  |   48 ++++++++++++++++++++++++++++++++-
 kernel/time/itimer.c                   |   13 ++++++++
 kernel/time/posix-timers.c             |   42 +++++++++++-----------------
 kernel/time/tick-internal.h            |    1 
 net/can/bcm.c                          |    2 -
 sound/drivers/pcsp/pcsp_lib.c          |    2 -
 13 files changed, 92 insertions(+), 73 deletions(-)