]> Cypherpunks repositories - gostls13.git/commit
cmd/internal/obj: mark split-stack prologue nonpreemptible
authorCherry Zhang <cherryyz@google.com>
Fri, 15 Nov 2019 01:23:17 +0000 (20:23 -0500)
committerCherry Zhang <cherryyz@google.com>
Wed, 27 Nov 2019 01:30:19 +0000 (01:30 +0000)
commitb2482e481722357c6daa98ef074d8eaf8ac4baf3
tree32ce92d105f52c29f4ff65c90ac3576bc85e831e
parentc3f149250e036f6bf77e7c9512dd3d57e1c78452
cmd/internal/obj: mark split-stack prologue nonpreemptible

When there are both a synchronous preemption request (by
clobbering the stack guard) and an asynchronous one (by signal),
the running goroutine may observe the synchronous request first
in stack bounds check, and go to the path of calling morestack.
If the preemption signal arrives at this point before the call to
morestack, the goroutine will be asynchronously preempted,
entering the scheduler. When it is resumed, the scheduler clears
the preemption request, unclobbers the stack guard. But the
resumed goroutine will still call morestack, as it is already on
its way. morestack will, as there is no preemption request,
double the stack unnecessarily. If this happens multiple times,
the stack may grow too big, although only a small amount is
actually used.

To fix this, we mark the stack bounds check and the call to
morestack async-nonpreemptible, starting after the memory
instruction (mostly a load, on x86 CMP with memory).

Not done for Wasm as it does not support async preemption.

Fixes #35470.

Change-Id: Ibd7f3d935a3649b80f47539116ec9b9556680cf2
Reviewed-on: https://go-review.googlesource.com/c/go/+/207350
Reviewed-by: David Chase <drchase@google.com>
src/cmd/internal/obj/arm/obj5.go
src/cmd/internal/obj/arm64/obj7.go
src/cmd/internal/obj/mips/obj0.go
src/cmd/internal/obj/plist.go
src/cmd/internal/obj/ppc64/obj9.go
src/cmd/internal/obj/s390x/objz.go
src/cmd/internal/obj/x86/obj6.go