]> Cypherpunks repositories - gostls13.git/commit
runtime: ensure m.p is never stale
authorNikhil Benesch <nikhil.benesch@gmail.com>
Fri, 9 Nov 2018 05:55:13 +0000 (00:55 -0500)
committerDmitry Vyukov <dvyukov@google.com>
Sat, 10 Nov 2018 19:26:41 +0000 (19:26 +0000)
commit8e0ec5ec09f92464730f89ff1f05e847b881a58a
tree4e26a0aba670220044d50a6d950f65bf58412099
parente4c1feef74d7415ba134aa0950f7f285a3e1902a
runtime: ensure m.p is never stale

When a goroutine enters a syscall, its M unwires from its P to allow
the P to be retaken by another M if the syscall is slow. The M retains a
reference to its old P, however, so that if its old P has not been
retaken when the syscall returns, it can quickly reacquire that P.

The implementation, however, was confusing, as it left the reference to
the potentially-retaken P in m.p, which implied that the P was still
wired.

Make the code clearer by enforcing the invariant that m.p is never
stale. entersyscall now moves m.p to m.oldp and sets m.p to 0;
exitsyscall does the reverse, provided m.oldp has not been retaken.

With this scheme in place, the issue described in #27660 (assertion
failures in the race detector) would have resulted in a clean segfault
instead of silently corrupting memory.

Change-Id: Ib3e03623ebed4f410e852a716919fe4538858f0a
Reviewed-on: https://go-review.googlesource.com/c/148899
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/runtime/proc.go
src/runtime/runtime2.go