runtime: prevent preemption while timer is in timerModifying
runtime: prevent preemption while timer is in timerModifying

Currently if a goroutine is preempted while owning a timer in the
timerModifying state, it could self-deadlock. When the goroutine is
preempted and calls into the scheduler, it could call checkTimers. If
checkTimers encounters the timerModifying timer and calls runtimer on
it, then runtimer will spin, waiting for that timer to leave the
timerModifying state, which it never will.

So far we got lucky that for the most part that there were no preemption
points while timerModifying is happening, however CL 221077 seems to
have introduced one, leading to sporadic self-deadlocks.

This change disables preemption explicitly while a goroutines holds a
timer in timerModifying. Since only checkTimers (and thus runtimer) is
called from the scheduler, this is sufficient to prevent
preemption-based self-deadlocks.

Fixes #38070.
Updates #37894.

Change-Id: Idbfac310889c92773023733ff7e2ff87e9896f0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/225497
Run-TryBot: Michael Knyszek <4473450dc5c88f06e1fb787f303d7805ec2aee65@google.com>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: Ian Lance Taylor <87e9c6d529889242b7e184afb632328636553ab4@golang.org>

golang/go,cloudflare/go,cloudflare/go,golang/go,CAFxX/go,akutz/go,nawawi/go,CAFxX/go,akutz/go,nawawi/go,golang/go,akutz/go,CAFxX/go,CAFxX/go,cloudflare/go,golang/go,cloudflare/go,nawawi/go,CAFxX/go,nawawi/go,CAFxX/go,akutz/go,akutz/go,golang/go,golang/go,cloudflare/go,nawawi/go,CAFxX/go,nawawi/go,cloudflare/go,golang/go,cloudflare/go,cloudflare/go,akutz/go,akutz/go,nawawi/go,akutz/go,golang/go,CAFxX/go,nawawi/go