components/golang/patches/0062-release-branch.go1.5-runtime-take-stack-barrier-lock.patch
changeset 5331 9c955076ffe3
equal deleted inserted replaced
5330:c36e3195e3e9 5331:9c955076ffe3
       
     1 From 6b26788c55d2c1e874e6321b8ce33f1a2c0270e6 Mon Sep 17 00:00:00 2001
       
     2 From: Austin Clements <[email protected]>
       
     3 Date: Mon, 23 Nov 2015 15:03:38 -0500
       
     4 Subject: [PATCH 62/63] [release-branch.go1.5] runtime: take stack barrier lock
       
     5  during copystack
       
     6 
       
     7 Commit bbd1a1c prevented SIGPROF from scanning stacks that were being
       
     8 copied, but it didn't prevent a stack copy (specifically a stack
       
     9 shrink) from happening while SIGPROF is scanning the stack. As a
       
    10 result, a stack copy may adjust stack barriers while SIGPROF is in the
       
    11 middle of scanning a stack, causing SIGPROF to panic when it detects
       
    12 an inconsistent stack barrier.
       
    13 
       
    14 Fix this by taking the stack barrier lock while adjusting the stack.
       
    15 In addition to preventing SIGPROF from scanning this stack, this will
       
    16 block until any in-progress SIGPROF is done scanning the stack.
       
    17 
       
    18 For 1.5.2.
       
    19 
       
    20 Fixes #13362.
       
    21 Updates #12932.
       
    22 
       
    23 Change-Id: I422219c363054410dfa56381f7b917e04690e5dd
       
    24 Reviewed-on: https://go-review.googlesource.com/17191
       
    25 Run-TryBot: Austin Clements <[email protected]>
       
    26 Reviewed-by: Russ Cox <[email protected]>
       
    27 Run-TryBot: Russ Cox <[email protected]>
       
    28 TryBot-Result: Gobot Gobot <[email protected]>
       
    29 Reviewed-on: https://go-review.googlesource.com/17194
       
    30 ---
       
    31  src/runtime/stack1.go | 6 ++++++
       
    32  1 file changed, 6 insertions(+)
       
    33 
       
    34 diff --git a/src/runtime/stack1.go b/src/runtime/stack1.go
       
    35 index efcb5f2..19634ef 100644
       
    36 --- a/src/runtime/stack1.go
       
    37 +++ b/src/runtime/stack1.go
       
    38 @@ -609,6 +609,10 @@ func copystack(gp *g, newsize uintptr) {
       
    39  		print("copystack gp=", gp, " [", hex(old.lo), " ", hex(old.hi-used), " ", hex(old.hi), "]/", gp.stackAlloc, " -> [", hex(new.lo), " ", hex(new.hi-used), " ", hex(new.hi), "]/", newsize, "\n")
       
    40  	}
       
    41  
       
    42 +	// Disallow sigprof scans of this stack and block if there's
       
    43 +	// one in progress.
       
    44 +	gcLockStackBarriers(gp)
       
    45 +
       
    46  	// adjust pointers in the to-be-copied frames
       
    47  	var adjinfo adjustinfo
       
    48  	adjinfo.old = old
       
    49 @@ -640,6 +644,8 @@ func copystack(gp *g, newsize uintptr) {
       
    50  	gp.stackAlloc = newsize
       
    51  	gp.stkbar = newstkbar
       
    52  
       
    53 +	gcUnlockStackBarriers(gp)
       
    54 +
       
    55  	// free old stack
       
    56  	if stackPoisonCopy != 0 {
       
    57  		fillstack(old, 0xfc)
       
    58 -- 
       
    59 2.6.1
       
    60