Skip to content

Commit c3163d2

Browse files
committed
runtime: eliminate write barriers from save
As for dropg, save is writing a nil pointer that will generate a write barrier with the hybrid barrier. However, in this case, ctxt always should already be nil, so replace the write with an assertion that this is the case. At this point, we're ready to disable the write barrier elision optimizations that interfere with the hybrid barrier. Updates #17503. Change-Id: I83208e65aa33403d442401f355b2e013ab9a50e9 Reviewed-on: https://go-review.googlesource.com/31571 Reviewed-by: Rick Hudson <[email protected]>
1 parent 8044b77 commit c3163d2

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/runtime/proc.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ func badmorestackgsignal() {
399399
write(2, sp.str, int32(sp.len))
400400
}
401401

402+
//go:nosplit
403+
func badctxt() {
404+
throw("ctxt != 0")
405+
}
406+
402407
func lockedOSThread() bool {
403408
gp := getg()
404409
return gp.lockedm != nil && gp.m.lockedg != nil
@@ -2285,6 +2290,12 @@ func goexit0(gp *g) {
22852290
schedule()
22862291
}
22872292

2293+
// save updates getg().sched to refer to pc and sp so that a following
2294+
// gogo will restore pc and sp.
2295+
//
2296+
// save must not have write barriers because invoking a write barrier
2297+
// can clobber getg().sched.
2298+
//
22882299
//go:nosplit
22892300
//go:nowritebarrierrec
22902301
func save(pc, sp uintptr) {
@@ -2294,8 +2305,13 @@ func save(pc, sp uintptr) {
22942305
_g_.sched.sp = sp
22952306
_g_.sched.lr = 0
22962307
_g_.sched.ret = 0
2297-
_g_.sched.ctxt = nil
22982308
_g_.sched.g = guintptr(unsafe.Pointer(_g_))
2309+
// We need to ensure ctxt is zero, but can't have a write
2310+
// barrier here. However, it should always already be zero.
2311+
// Assert that.
2312+
if _g_.sched.ctxt != nil {
2313+
badctxt()
2314+
}
22992315
}
23002316

23012317
// The goroutine g is about to enter a system call.

0 commit comments

Comments
 (0)