Skip to content

Commit df18377

Browse files
committed
runtime: make consistentHeapStats acquire/release nosplit
consistentHeapStats is updated during a stack allocation, so a stack growth during an acquire or release could cause another acquire to happen before the operation completes fully. This may lead to an invalid sequence number. Fixes #49395. Change-Id: I41ce3393dff80201793e053d4d6394d7b211a5b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/361158 Trust: Michael Knyszek <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 6f32d20 commit df18377

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/runtime/mstats.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,15 @@ type consistentHeapStats struct {
790790
//
791791
// The caller's P must not change between acquire and
792792
// release. This also means that the caller should not
793-
// acquire a P or release its P in between.
793+
// acquire a P or release its P in between. A P also must
794+
// not acquire a given consistentHeapStats if it hasn't
795+
// yet released it.
796+
//
797+
// nosplit because a stack growth in this function could
798+
// lead to a stack allocation that could reenter the
799+
// function.
800+
//
801+
//go:nosplit
794802
func (m *consistentHeapStats) acquire() *heapStatsDelta {
795803
if pp := getg().m.p.ptr(); pp != nil {
796804
seq := atomic.Xadd(&pp.statsSeq, 1)
@@ -814,6 +822,12 @@ func (m *consistentHeapStats) acquire() *heapStatsDelta {
814822
// The caller's P must not change between acquire and
815823
// release. This also means that the caller should not
816824
// acquire a P or release its P in between.
825+
//
826+
// nosplit because a stack growth in this function could
827+
// lead to a stack allocation that causes another acquire
828+
// before this operation has completed.
829+
//
830+
//go:nosplit
817831
func (m *consistentHeapStats) release() {
818832
if pp := getg().m.p.ptr(); pp != nil {
819833
seq := atomic.Xadd(&pp.statsSeq, 1)

0 commit comments

Comments
 (0)