Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime/race: atomic operations fail on non-heap addresess #9136

Closed
rsc opened this issue Nov 20, 2014 · 6 comments
Closed

runtime/race: atomic operations fail on non-heap addresess #9136

rsc opened this issue Nov 20, 2014 · 6 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Nov 20, 2014

g% cat ~/x.go
package main

import (
    "log"
    "sync/atomic"
    "syscall"
    "unsafe"
)

func main() {
    data, err := syscall.Mmap(-1, 0, 4096, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON)
    if err != nil {
        log.Fatal(err)
    }
    println(data)
    atomic.AddUint32((*uint32)(unsafe.Pointer(&data[0])), 1)
}
g% go run ~/x.go
[4096/4096]0x2208335000
g% go run -race ~/x.go
[4096/4096]0xbf2000
unexpected fault address 0x200002fc8000
fatal error: fault
[signal 0xb code=0x1 addr=0x200002fc8000 pc=0xcc623]

goroutine 1 [running]:
runtime.gothrow(0x0, 0x0)
    /Users/rsc/g/go/src/runtime/panic.go:503 +0x8e fp=0x7fff5fbff4e0 sp=0x7fff5fbff4c8
exit status 2
g% 

Program should run under -race the same as it does normally.
This worked in Go 1.3, because Go 1.3 implemented these using raceread/raceacquire
instead of "fast paths".

This is blocking Go 1.4. One possible fix is to restore the old "slow path" Go
1.3 implementations of these functions.
@gopherbot
Copy link

Comment 1 by szamcsi@google.com:

I also have a simple program that fails with -race:
$ cat x.go
package main
import "fmt"
func main() {
    a := []string{"a"}
    i := 0
    a[i], a[len(a)-1], a = a[len(a)-1], "", a[:len(a)-1]
    fmt.Println(a)
}
$ go run x.go
panic: runtime error: index out of range
...

@davecheney
Copy link
Contributor

Comment 2:

szamcsi, could you please open a new issue for this. That is related to the race
detector and should be fixed, but is not related to detecting races in non heap memory.

@dvyukov
Copy link
Member

dvyukov commented Nov 20, 2014

Comment 3:

Moved this to https://golang.org/issue/9137
Thanks for the report!

@gopherbot
Copy link

Comment 4:

CL https://golang.org/cl/179030043 mentions this issue.

@dvyukov
Copy link
Member

dvyukov commented Nov 20, 2014

Comment 5:

This issue was closed by revision 2b3f379.

Status changed to Fixed.

@rsc
Copy link
Contributor Author

rsc commented Nov 20, 2014

Comment 6:

This issue was closed by revision 0f20d1afae39.

@rsc rsc added fixed labels Nov 20, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
rsc added a commit that referenced this issue May 11, 2015
…resses

««« CL 179030043 / e4ab8f908aac
runtime: fix atomic operations on non-heap addresses
Race detector runtime does not tolerate operations on addresses
that was not previously declared with __tsan_map_shadow
(namely, data, bss and heap). The corresponding address
checks for atomic operations were removed in
https://golang.org/cl/111310044
Restore these checks.
It's tricker than just not calling into race runtime,
because it is the race runtime that makes the atomic
operations themselves (if we do not call into race runtime
we skip the atomic operation itself as well). So instead we call
__tsan_go_ignore_sync_start/end around the atomic operation.
This forces race runtime to skip all other processing
except than doing the atomic operation itself.
Fixes #9136.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179030043

»»»

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/180030043
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
…resses

««« CL 179030043 / e4ab8f908aac
runtime: fix atomic operations on non-heap addresses
Race detector runtime does not tolerate operations on addresses
that was not previously declared with __tsan_map_shadow
(namely, data, bss and heap). The corresponding address
checks for atomic operations were removed in
https://golang.org/cl/111310044
Restore these checks.
It's tricker than just not calling into race runtime,
because it is the race runtime that makes the atomic
operations themselves (if we do not call into race runtime
we skip the atomic operation itself as well). So instead we call
__tsan_go_ignore_sync_start/end around the atomic operation.
This forces race runtime to skip all other processing
except than doing the atomic operation itself.
Fixes golang#9136.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179030043

»»»

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/180030043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
…resses

««« CL 179030043 / e4ab8f908aac
runtime: fix atomic operations on non-heap addresses
Race detector runtime does not tolerate operations on addresses
that was not previously declared with __tsan_map_shadow
(namely, data, bss and heap). The corresponding address
checks for atomic operations were removed in
https://golang.org/cl/111310044
Restore these checks.
It's tricker than just not calling into race runtime,
because it is the race runtime that makes the atomic
operations themselves (if we do not call into race runtime
we skip the atomic operation itself as well). So instead we call
__tsan_go_ignore_sync_start/end around the atomic operation.
This forces race runtime to skip all other processing
except than doing the atomic operation itself.
Fixes golang#9136.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179030043

»»»

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/180030043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
…resses

««« CL 179030043 / e4ab8f908aac
runtime: fix atomic operations on non-heap addresses
Race detector runtime does not tolerate operations on addresses
that was not previously declared with __tsan_map_shadow
(namely, data, bss and heap). The corresponding address
checks for atomic operations were removed in
https://golang.org/cl/111310044
Restore these checks.
It's tricker than just not calling into race runtime,
because it is the race runtime that makes the atomic
operations themselves (if we do not call into race runtime
we skip the atomic operation itself as well). So instead we call
__tsan_go_ignore_sync_start/end around the atomic operation.
This forces race runtime to skip all other processing
except than doing the atomic operation itself.
Fixes golang#9136.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179030043

»»»

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/180030043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 20, 2018
…resses

««« CL 179030043 / e4ab8f908aac
runtime: fix atomic operations on non-heap addresses
Race detector runtime does not tolerate operations on addresses
that was not previously declared with __tsan_map_shadow
(namely, data, bss and heap). The corresponding address
checks for atomic operations were removed in
https://golang.org/cl/111310044
Restore these checks.
It's tricker than just not calling into race runtime,
because it is the race runtime that makes the atomic
operations themselves (if we do not call into race runtime
we skip the atomic operation itself as well). So instead we call
__tsan_go_ignore_sync_start/end around the atomic operation.
This forces race runtime to skip all other processing
except than doing the atomic operation itself.
Fixes golang#9136.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179030043

»»»

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/180030043
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
…resses

««« CL 179030043 / e4ab8f908aac
runtime: fix atomic operations on non-heap addresses
Race detector runtime does not tolerate operations on addresses
that was not previously declared with __tsan_map_shadow
(namely, data, bss and heap). The corresponding address
checks for atomic operations were removed in
https://golang.org/cl/111310044
Restore these checks.
It's tricker than just not calling into race runtime,
because it is the race runtime that makes the atomic
operations themselves (if we do not call into race runtime
we skip the atomic operation itself as well). So instead we call
__tsan_go_ignore_sync_start/end around the atomic operation.
This forces race runtime to skip all other processing
except than doing the atomic operation itself.
Fixes golang#9136.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/179030043

»»»

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/180030043
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants