Skip to content

Commit fb67cbb

Browse files
prattmicbradfitz
authored andcommitted
[release-branch.go1.22] runtime: don't call traceReadCPU on the system stack
traceReadCPU calls profBuf.read, which does a raceacquire. g0 does not have a race context, so this crashes when running on the system stack. We could borrow a race context, but it is simpler to just move traceReadCPU off of the system stack. For golang#65607. Fixes golang#65644. Change-Id: I335155b96d683aebb92b2f4e1eea063dd139f2d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/562996 Auto-Submit: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> (cherry picked from commit 9fa153b) Reviewed-on: https://go-review.googlesource.com/c/go/+/562559
1 parent 20e5874 commit fb67cbb

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/runtime/trace2.go

+3
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ func traceAdvance(stopTrace bool) {
516516
}
517517
statusWriter.flush().end()
518518

519+
// Read everything out of the last gen's CPU profile buffer.
520+
traceReadCPU(gen)
521+
519522
systemstack(func() {
520523
// Flush CPU samples, stacks, and strings for the last generation. This is safe,
521524
// because we're now certain no M is writing to the last generation.

src/runtime/trace2cpu.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ func traceStopReadCPU() {
112112
//
113113
// No more than one goroutine may be in traceReadCPU for the same
114114
// profBuf at a time.
115+
//
116+
// Must not run on the system stack because profBuf.read performs race
117+
// operations.
115118
func traceReadCPU(gen uintptr) bool {
116119
var pcBuf [traceStackSize]uintptr
117120

@@ -198,9 +201,6 @@ func traceReadCPU(gen uintptr) bool {
198201
//
199202
//go:systemstack
200203
func traceCPUFlush(gen uintptr) {
201-
// Read everything out of the last gen's CPU profile buffer.
202-
traceReadCPU(gen)
203-
204204
// Flush any remaining trace buffers containing CPU samples.
205205
if buf := trace.cpuBuf[gen%2]; buf != nil {
206206
lock(&trace.lock)

0 commit comments

Comments
 (0)