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

Closed
aclements opened this issue Oct 22, 2017 · 1 comment
Closed

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

aclements opened this issue Oct 22, 2017 · 1 comment
Milestone

Comments

@aclements
Copy link
Member

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
@gopherbot
Copy link

Change https://golang.org/cl/72553 mentions this issue: runtime: remove write barriers from newstack, gogo

@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.
Projects
None yet
Development

No branches or pull requests

2 participants