Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: stack growth in nowritebarrierrec can have write barriers #22385

aclements opened this issue Oct 22, 2017 · 1 comment

runtime: stack growth in nowritebarrierrec can have write barriers #22385

aclements opened this issue Oct 22, 2017 · 1 comment


Copy link

@aclements aclements commented Oct 22, 2017

The go:nowritebarrierrec annotation is supposed to recursively disallow write barriers. However, it doesn't know about the implicit morestack call in most function prologues. Unfortunately, newstack (called from morestack) has a write barrier on the gp.sched.ctxt = ctxt line (complete with a comment explaining why that write barrier is important!), which means we can get a write barrier under a function that statically disallows write barriers if it causes stack growth.

I can think of two solutions:

  1. Make go:nowritebarrierrec require either go:systemstack or go:nosplitrec. This seems like an ugly constraint that would be hard to add to the runtime, and go:nosplitrec doesn't even exist right now.
  2. Eliminate the write barrier from newstack. The only write barrier is when assigning ctxt and ctxt is a little weird: it's really just a saved register. We just bounce ctxt between this register and gp.sched. Hence, it should be safe to simply drop the write barrier when saving ctxt (and when restoring it, which eliminates some nasty assembly code) and to instead scan it in scanstack, viewing it as a live register that goes along with the stack.

I have solution 2 implemented on amd64 and it seems to be working.

/cc @RLH

@aclements aclements added this to the Go1.10 milestone Oct 22, 2017
@aclements aclements self-assigned this Oct 22, 2017

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 23, 2017

Change mentions this issue: runtime: remove write barriers from newstack, gogo

@gopherbot gopherbot closed this in 3beaf26 Oct 29, 2017
@golang golang locked and limited conversation to collaborators Oct 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.