]> Cypherpunks repositories - gostls13.git/commit
runtime: only acquire trace.lock on the system stack
authorAustin Clements <austin@google.com>
Thu, 21 Jul 2022 19:43:11 +0000 (15:43 -0400)
committerAustin Clements <austin@google.com>
Thu, 11 Aug 2022 20:16:35 +0000 (20:16 +0000)
commit6c2e327e35b6fe838b496ec1e8fb2f597c5bd59a
treea75a89f2c5f2950058d2045bd2524555a4b10b57
parent9923162f1cb88295bccb4d86ccc6829931199fdf
runtime: only acquire trace.lock on the system stack

Currently, trace.lock can be acquired while on a user G and stack
splits can happen while holding trace.lock. That means every lock used
by the stack allocator must be okay to acquire while holding
trace.lock, including various locks related to span allocation. In
turn, we cannot safely emit trace events while holding any
allocation-related locks because this would cause a cycle in the lock
rank graph.

To fix this, require that trace.lock only be acquired on the system
stack, like mheap.lock. This pushes it into the "bottom half" and
eliminates the lock rank relationship between tracing and stack
allocation, making it safe to emit trace events in many more places.

One subtlety is that the trace code has race annotations and uses
maps, which have race annotations. By default, we can't have race
annotations on the system stack, so we borrow the user race context
for these situations.

We'll update the lock graph itself in the next CL.

For #53979. This CL technically fixes the problem, but the lock rank
checker doesn't know that yet.

Change-Id: I9f5187a9c52a67bee4f7064db124b1ad53e5178f
Reviewed-on: https://go-review.googlesource.com/c/go/+/418956
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/runtime/trace.go