• Austin Clements's avatar
    runtime: avoid race on allp in findrunnable · 7c2cf4e7
    Austin Clements authored
    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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    7c2cf4e7
proc.go 139 KB