]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: replace rwmutexR/W with per-rwmutex lock rank
authorMichael Pratt <mpratt@google.com>
Tue, 9 Jan 2024 18:13:45 +0000 (13:13 -0500)
committerMichael Pratt <mpratt@google.com>
Tue, 9 Jan 2024 21:07:15 +0000 (21:07 +0000)
commitdcbe77246922fe7ef41f07df228f47a37803f360
tree170a02eaa317e4370f9e455706b26d3fd45ad06d
parent59ecebf47f70d018cffd650ade91f44e25d128ea
runtime: replace rwmutexR/W with per-rwmutex lock rank

CL 549536 intended to decouple the internal implementation of rwmutex
from the semantic meaning of an rwmutex read/write lock in the static
lock ranking.

Unfortunately, it was not thought through well enough. The internals
were represented with the rwmutexR and rwmutexW lock ranks. The idea was
that the internal lock ranks need not model the higher-level ordering,
since those have separate rankings. That is incorrect; rwmutexW is held
for the duration of a write lock, so it must be ranked before any lock
taken while any write lock is held, which is precisely what we were
trying to avoid.

This is visible in violations like:

        0 : execW 11 0x0
        1 : rwmutexW 51 0x111d9c8
        2 : fin 30 0x111d3a0
        fatal error: lock ordering problem

execW < fin is modeled, but rwmutexW < fin is missing.

Fix this by eliminating the rwmutexR/W lock ranks shared across
different types of rwmutex. Instead require users to define an
additional "internal" lock rank to represent the implementation details
of rwmutex.rLock. We can avoid an additional "internal" lock rank for
rwmutex.wLock because the existing writeRank has the same semantics for
semantic and internal locking. i.e., writeRank is held for the duration
of a write lock, which is exactly how rwmutex.wLock is used, so we can
use writeRank directly on wLock.

For #64722.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-staticlockranking
Change-Id: Ia572de188a46ba8fe054ae28537648beaa16b12c
Reviewed-on: https://go-review.googlesource.com/c/go/+/555055
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/export_test.go
src/runtime/lockrank.go
src/runtime/mklockrank.go
src/runtime/proc.go
src/runtime/rwmutex.go