]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't call traceReadCPU on the system stack
authorMichael Pratt <mpratt@google.com>
Fri, 9 Feb 2024 18:49:21 +0000 (13:49 -0500)
committerGopher Robot <gobot@golang.org>
Fri, 9 Feb 2024 20:07:38 +0000 (20:07 +0000)
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.

Fixes #65607.

Change-Id: I335155b96d683aebb92b2f4e1eea063dd139f2d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/562996
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/trace2.go
src/runtime/trace2cpu.go

index d40596f39be985e7c726f57252872852fd2cd02c..673205dda8a4a68f61f54f80ed937ccb92642df0 100644 (file)
@@ -516,6 +516,9 @@ func traceAdvance(stopTrace bool) {
        }
        statusWriter.flush().end()
 
+       // Read everything out of the last gen's CPU profile buffer.
+       traceReadCPU(gen)
+
        systemstack(func() {
                // Flush CPU samples, stacks, and strings for the last generation. This is safe,
                // because we're now certain no M is writing to the last generation.
index 95c62c44b4411455869a013d816ccea281030e46..4635662c08d56a2615507c30e545cbd2d7537a85 100644 (file)
@@ -112,6 +112,9 @@ func traceStopReadCPU() {
 //
 // No more than one goroutine may be in traceReadCPU for the same
 // profBuf at a time.
+//
+// Must not run on the system stack because profBuf.read performs race
+// operations.
 func traceReadCPU(gen uintptr) bool {
        var pcBuf [traceStackSize]uintptr
 
@@ -198,9 +201,6 @@ func traceReadCPU(gen uintptr) bool {
 //
 //go:systemstack
 func traceCPUFlush(gen uintptr) {
-       // Read everything out of the last gen's CPU profile buffer.
-       traceReadCPU(gen)
-
        // Flush any remaining trace buffers containing CPU samples.
        if buf := trace.cpuBuf[gen%2]; buf != nil {
                lock(&trace.lock)