]> Cypherpunks repositories - gostls13.git/commit
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)
committerMichael Pratt <mpratt@google.com>
Fri, 15 Oct 2021 20:34:15 +0000 (20:34 +0000)
commit1b072b3ed56c18619587354f499fcda5279718a2
treedda97e6d2393a17fe3eeae3172ce872db78d62c4
parent85cbdda5a6d8525973580776c835e725452db898
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.

Fixes #48925

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>
src/runtime/netpoll.go