Skip to content

Commit f7b9470

Browse files
prattmicdmitshur
authored andcommitted
[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 <[email protected]> Run-TryBot: Michael Pratt <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Go Bot <[email protected]> (cherry picked from commit 20a620f) Reviewed-on: https://go-review.googlesource.com/c/go/+/341890
1 parent 4397d66 commit f7b9470

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/runtime/proc.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -4686,7 +4686,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
46864686
return
46874687
}
46884688

4689-
// On mips{,le}, 64bit atomics are emulated with spinlocks, in
4689+
// On mips{,le}/arm, 64bit atomics are emulated with spinlocks, in
46904690
// runtime/internal/atomic. If SIGPROF arrives while the program is inside
46914691
// the critical section, it creates a deadlock (when writing the sample).
46924692
// 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) {
46994699
return
47004700
}
47014701
}
4702+
if GOARCH == "arm" && goarm < 7 && GOOS == "linux" && pc&0xffff0000 == 0xffff0000 {
4703+
// runtime/internal/atomic functions call into kernel
4704+
// helpers on arm < 7. See
4705+
// runtime/internal/atomic/sys_linux_arm.s.
4706+
cpuprof.lostAtomic++
4707+
return
4708+
}
47024709
}
47034710

47044711
// Profiling runs concurrently with GC, so it must not allocate.

0 commit comments

Comments
 (0)