]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: handle m0 padding better
authorRuss Cox <rsc@golang.org>
Tue, 4 Mar 2025 15:31:02 +0000 (10:31 -0500)
committerGopher Robot <gobot@golang.org>
Fri, 11 Apr 2025 19:24:59 +0000 (12:24 -0700)
The SpinbitMutex experiment requires m structs other than m0
to be allocated in 2048-byte size class, by adding padding.
Do the calculation more explicitly, to avoid future CLs like CL 653335.

Change-Id: I83ae1e86ef3711ab65441f4e487f94b9e1429029
Reviewed-on: https://go-review.googlesource.com/c/go/+/654595
Reviewed-by: Rhys Hiltner <rhys.hiltner@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

src/runtime/asan.go
src/runtime/asan0.go
src/runtime/lock_spinbit.go
src/runtime/proc.go
src/runtime/runtime2.go

index 32d5f452256f2d1fe1212c5f974eef00f81bf822..ee070d3270aa8f56221f8d046a02fa2083713ecb 100644 (file)
@@ -26,6 +26,7 @@ func ASanWrite(addr unsafe.Pointer, len int) {
 
 // Private interface for the runtime.
 const asanenabled = true
+const asanenabledBit = 1
 
 // asan{read,write} are nosplit because they may be called between
 // fork and exec, when the stack must not grow. See issue #50391.
index 83316539821bdafad0d714b87800b94046fb0490..f20eae0af773bee14626f69c5906d020d39f5c3d 100644 (file)
@@ -13,6 +13,7 @@ import (
 )
 
 const asanenabled = false
+const asanenabledBit = 0
 
 // Because asanenabled is false, none of these functions should be called.
 
index 7e84f3e1c2153224b449deb8624a64f0621f0a6d..ba5268abdd53bdaa2380984941f1d84c8564cca7 100644 (file)
@@ -90,7 +90,7 @@ type mWaitList struct {
 
 // lockVerifyMSize confirms that we can recreate the low bits of the M pointer.
 func lockVerifyMSize() {
-       size := roundupsize(unsafe.Sizeof(m{}), false) + mallocHeaderSize
+       size := roundupsize(unsafe.Sizeof(mPadded{}), false) + mallocHeaderSize
        if size&mutexMMask != 0 {
                print("M structure uses sizeclass ", size, "/", hex(size), " bytes; ",
                        "incompatible with mutex flag mask ", hex(mutexMMask), "\n")
index c7ae71a13608fa47fb0c0e48231d9272161f6686..8f603021e5197fa2fdd762c0701d8a10550e9286 100644 (file)
@@ -2256,7 +2256,7 @@ func allocm(pp *p, fn func(), id int64) *m {
                unlock(&sched.lock)
        }
 
-       mp := new(m)
+       mp := &new(mPadded).m
        mp.mstartfn = fn
        mcommoninit(mp, id)
 
index 6b9f49d5037feeec9b389b75439bc806e566893e..4318930d9c76bf7c7e6b2e48443a924dfa0d3c2c 100644 (file)
@@ -619,13 +619,18 @@ type m struct {
        // Up to 10 locks held by this m, maintained by the lock ranking code.
        locksHeldLen int
        locksHeld    [10]heldLockInfo
+}
+
+const mRedZoneSize = (16 << 3) * asanenabledBit // redZoneSize(2048)
+
+type mPadded struct {
+       m
 
        // Size the runtime.m structure so it fits in the 2048-byte size class, and
        // not in the next-smallest (1792-byte) size class. That leaves the 11 low
        // bits of muintptr values available for flags, as required for
        // GOEXPERIMENT=spinbitmutex.
-       _ [goexperiment.SpinbitMutexInt * 64 * goarch.PtrSize / 8]byte
-       _ [goexperiment.SpinbitMutexInt * 700 * (2 - goarch.PtrSize/4)]byte
+       _ [goexperiment.SpinbitMutexInt * (2048 - mallocHeaderSize - mRedZoneSize - unsafe.Sizeof(m{}))]byte
 }
 
 type p struct {