linux/include
Thomas Gleixner 9bc7491906 hrtimer: Prevent stale expiry time in hrtimer_interrupt()
hrtimer_interrupt() has the following subtle issue:

hrtimer_interrupt()
  lock(cpu_base);
  expires_next = KTIME_MAX;

  expire_timers(CLOCK_MONOTONIC);
  expires = get_next_timer(CLOCK_MONOTONIC);
  if (expires < expires_next)
    expires_next = expires;

  expire_timers(CLOCK_REALTIME);
    unlock(cpu_base);
    wakeup()
    hrtimer_start(CLOCK_MONOTONIC, newtimer);
    lock(cpu_base();  
  expires = get_next_timer(CLOCK_REALTIME);
  if (expires < expires_next)
    expires_next = expires;

So because we already evaluated the next expiring timer of
CLOCK_MONOTONIC we ignore that the expiry time of newtimer might be
earlier than the overall next expiry time in hrtimer_interrupt().

To solve this, remove the caching of the next expiry value from
hrtimer_interrupt() and reevaluate all active clock bases for the next
expiry value. To avoid another code duplication, create a shared
evaluation function and use it for hrtimer_get_next_event(),
hrtimer_force_reprogram() and hrtimer_interrupt().

There is another subtlety in this mechanism:

While hrtimer_interrupt() is running, we want to avoid to touch the
hardware device because we will reprogram it anyway at the end of
hrtimer_interrupt(). This works nicely for hrtimers which get rearmed
via the HRTIMER_RESTART mechanism, because we drop out when the
callback on that CPU is running. But that fails, if a new timer gets
enqueued like in the example above.

This has another implication: While hrtimer_interrupt() is running we
refuse remote enqueueing of timers - see hrtimer_interrupt() and
hrtimer_check_target().

hrtimer_interrupt() tries to prevent this by setting cpu_base->expires
to KTIME_MAX, but that fails if a new timer gets queued.

Prevent both the hardware access and the remote enqueue
explicitely. We can loosen the restriction on the remote enqueue now
due to reevaluation of the next expiry value, but that needs a
seperate patch.

Folded in a fix from Vignesh Radhakrishnan.

Reported-and-tested-by: Stanislav Fomichev <stfomichev@yandex-team.ru>
Based-on-patch-by: Stanislav Fomichev <stfomichev@yandex-team.ru>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: vigneshr@codeaurora.org
Cc: john.stultz@linaro.org
Cc: viresh.kumar@linaro.org
Cc: fweisbec@gmail.com
Cc: cl@linux.com
Cc: stuart.w.hayes@gmail.com
Link: http://lkml.kernel.org/r/alpine.DEB.2.11.1501202049190.5526@nanos
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2015-01-23 12:13:20 +01:00
..
acpi ACPI / processor: Convert apic_id to phys_id to make it arch agnostic 2015-01-05 23:32:42 +01:00
asm-generic mm: mmu_gather: use tlb->end != 0 only for TLB invalidation 2015-01-13 15:20:40 +13:00
clocksource
crypto crypto: af_alg - add user space interface for AEAD 2014-12-05 23:56:55 +08:00
drm Revert "drm/gem: Warn on illegal use of the dumb buffer interface v2" 2014-12-24 13:13:22 +10:00
dt-bindings Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal into thermal-soc 2014-12-21 22:49:12 +08:00
keys
kvm arm/arm64: KVM: Require in-kernel vgic for the arch timers 2014-12-15 11:50:42 +01:00
linux hrtimer: Prevent stale expiry time in hrtimer_interrupt() 2015-01-23 12:13:20 +01:00
math-emu
media [media] media: v4l2-image-sizes.h: correct the SVGA height definition 2014-12-04 13:56:56 -02:00
memory
misc
net Here's just a single fix - a revert of a patch that broke the 2015-01-06 13:29:27 -05:00
pcmcia
ras
rdma IB/core: Implement support for MMU notifiers regarding on demand paging regions 2014-12-15 18:13:36 -08:00
rxrpc
scsi SCSI for-linus on 20141220 2014-12-20 13:42:57 -08:00
soc Merge branch 'at91/cleanup5' into next/drivers 2014-12-08 18:29:20 +01:00
sound ALSA: pcm: Fix kerneldoc for params_*() functions 2014-12-30 16:41:11 +01:00
target target: Drop left-over fabric_max_sectors attribute 2015-01-09 15:22:05 -08:00
trace SCSI for-linus on 20141220 2014-12-20 13:42:57 -08:00
uapi Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2015-01-15 11:17:37 +13:00
video OMAPDSS: Remove all references to obsolete HDMI audio callbacks 2014-12-01 11:09:59 +02:00
xen x86/xen: properly retrieve NMI reason 2015-01-13 09:39:50 +00:00
Kbuild