]> Cypherpunks repositories - gostls13.git/commit
runtime: avoid race on allp in findrunnable
authorAustin Clements <austin@google.com>
Thu, 4 Jan 2018 15:43:29 +0000 (10:43 -0500)
committerAustin Clements <austin@google.com>
Thu, 4 Jan 2018 18:01:55 +0000 (18:01 +0000)
commit7c2cf4e779a66b212a3c94f2b20ade1c2c275b84
treef3eddc8fc46b92bc46980ae958d763b807e7aba2
parent1f84cd9771c6aab344dc6f46b50838ff7d239e87
runtime: avoid race on allp in findrunnable

findrunnable loops over allp to check run queues *after* it has
dropped its own P. This is unsafe because allp can change when nothing
is blocking safe-points. Hence, procresize could change allp
concurrently with findrunnable's loop. Beyond generally violating Go's
memory model, in the best case this could findrunnable to observe a
nil P pointer if allp has been grown but the new slots not yet
initialized. In the worst case, the reads of allp could tear, causing
findrunnable to read a word that isn't even a valid *P pointer.

Fix this by taking a snapshot of the allp slice header (but not the
backing store) before findrunnable drops its P and iterating over this
snapshot. The actual contents of allp are immutable up to len(allp),
so this fixes the race.

Updates #23098 (may fix).

Change-Id: I556ae2dbfffe9fe4a1bf43126e930b9e5c240ea8
Reviewed-on: https://go-review.googlesource.com/86215
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/proc.go