[release-branch.go1.23] runtime: explicitly disable async preempt for internal/runtime

Fixes #72114
For #71591
Relevant CL 560155

Change-Id: Iebc497d56b36d50c13a6dd88e7bca4578a03cf63
Reviewed-on: https://go-review.googlesource.com/c/go/+/654916
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
(cherry picked from commit 92a63bdfee9f8347df70293e5733661ae31ae285)
Reviewed-on: https://go-review.googlesource.com/c/go/+/660935
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
Andy Pan 2025-03-05 16:14:42 +08:00 committed by Gopher Robot
parent 2c0a0fc6b9
commit c72a2bad68
2 changed files with 12 additions and 2 deletions

View File

@ -43,6 +43,9 @@ type PkgSpecial struct {
}
var runtimePkgs = []string{
// TODO(panjf2000): consider syncing the list inside the
// isAsyncSafePoint in preempt.go based on this list?
"runtime",
"internal/runtime/atomic",

View File

@ -419,14 +419,21 @@ func isAsyncSafePoint(gp *g, pc, sp, lr uintptr) (bool, uintptr) {
name := u.srcFunc(uf).name()
if stringslite.HasPrefix(name, "runtime.") ||
stringslite.HasPrefix(name, "runtime/internal/") ||
stringslite.HasPrefix(name, "internal/runtime/") ||
stringslite.HasPrefix(name, "reflect.") {
// For now we never async preempt the runtime or
// anything closely tied to the runtime. Known issues
// include: various points in the scheduler ("don't
// preempt between here and here"), much of the defer
// implementation (untyped info on stack), bulk write
// barriers (write barrier check),
// reflect.{makeFuncStub,methodValueCall}.
// barriers (write barrier check), atomic functions in
// internal/runtime/atomic, reflect.{makeFuncStub,methodValueCall}.
//
// Note that this is a subset of the runtimePkgs in pkgspecial.go
// and these checks are theoretically redundant because the compiler
// marks "all points" in runtime functions as unsafe for async preemption.
// But for some reason, we can't eliminate these checks until https://go.dev/issue/72031
// is resolved.
//
// TODO(austin): We should improve this, or opt things
// in incrementally.