• Nikhil Benesch's avatar
    runtime: ensure m.p is never stale · 8e0ec5ec
    Nikhil Benesch authored
    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: 's avatarDmitry Vyukov <dvyukov@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    8e0ec5ec
proc.go 143 KB