From: Michael Pratt Date: Thu, 12 Aug 2021 21:17:51 +0000 (-0400) Subject: [release-branch.go1.17] runtime: drop SIGPROF while in ARM < 7 kernel helpers X-Git-Tag: go1.17~2 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f7b9470992bfae96fe61d45bec40b7fc282f15f0;p=gostls13.git [release-branch.go1.17] runtime: drop SIGPROF while in ARM < 7 kernel helpers On Linux ARMv6 and below runtime/internal/atomic.Cas calls into a kernel cas helper at a fixed address. If a SIGPROF arrives while executing the kernel helper, the sigprof lostAtomic logic will miss that we are potentially in the spinlock critical section, which could cause a deadlock when using atomics later in sigprof. For #47505 Fixes #47688 Change-Id: If8ba0d0fc47e45d4e6c68eca98fac4c6ed4e43c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/341889 Trust: Michael Pratt Run-TryBot: Michael Pratt Reviewed-by: Michael Knyszek Reviewed-by: Cherry Mui TryBot-Result: Go Bot (cherry picked from commit 20a620fd9f7bc35739c1af3602d53808d0430814) Reviewed-on: https://go-review.googlesource.com/c/go/+/341890 --- diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 7bc2a92590..a144b36ec8 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -4686,7 +4686,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) { return } - // On mips{,le}, 64bit atomics are emulated with spinlocks, in + // On mips{,le}/arm, 64bit atomics are emulated with spinlocks, in // runtime/internal/atomic. If SIGPROF arrives while the program is inside // the critical section, it creates a deadlock (when writing the sample). // As a workaround, create a counter of SIGPROFs while in critical section @@ -4699,6 +4699,13 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) { return } } + if GOARCH == "arm" && goarm < 7 && GOOS == "linux" && pc&0xffff0000 == 0xffff0000 { + // runtime/internal/atomic functions call into kernel + // helpers on arm < 7. See + // runtime/internal/atomic/sys_linux_arm.s. + cpuprof.lostAtomic++ + return + } } // Profiling runs concurrently with GC, so it must not allocate.