]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.17] runtime: consistently access pollDesc r/w Gs with atomics
authorMichael Pratt <mpratt@google.com>
Thu, 14 Oct 2021 22:18:49 +0000 (18:18 -0400)
committerDmitri Shuralyov <dmitshur@golang.org>
Thu, 28 Oct 2021 15:31:28 +0000 (15:31 +0000)
commit8bdb0b235afda5360699f6e786b31bf02580e4a9
treed1e60b5272508820f2e400d3c8d852f527b29fd9
parent3a03ddf735f0e8eff3f8325a496f28b71d3dbe39
[release-branch.go1.17] runtime: consistently access pollDesc r/w Gs with atomics

Both netpollblock and netpollunblock read gpp using a non-atomic load.
When consuming a ready event, netpollblock clears gpp using a non-atomic
store, thus skipping a barrier.

Thus on systems with weak memory ordering, a sequence like so this is
possible:

             T1                                T2

1. netpollblock: read gpp -> pdReady
2. netpollblock: store gpp -> 0

                                 3. netpollunblock: read gpp -> pdReady
                                 4. netpollunblock: return

i.e., without a happens-before edge between (2) and (3), netpollunblock
may read the stale value of gpp.

Switch these access to use atomic loads and stores in order to create
these edges.

For ease of future maintainance, I've simply changed rg and wg to always
be accessed atomically, though I don't believe pollOpen or pollClose
require atomics today.

For #48925
Fixes #49010

Change-Id: I903ea667eea320277610b4f969129935731520c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/355952
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
(cherry picked from commit 1b072b3ed56c18619587354f499fcda5279718a2)
Reviewed-on: https://go-review.googlesource.com/c/go/+/356369
src/runtime/netpoll.go