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: unaligned atomic access to m.procid on 32-bit (arm, 386, ...) #52810

Closed
bradfitz opened this issue May 10, 2022 · 3 comments
Closed

Comments

@bradfitz
Copy link
Contributor

bradfitz commented May 10, 2022

Repro, on Go 1.18.1:

package main

import (
        "fmt"
        "runtime"
        "syscall"
)

func main() {
        fmt.Println(runtime.Version())
        err := syscall.Setgroups([]int{1, 2, 3})
        fmt.Println(err)
}

Run on a Raspberry Pi (where it was first found) or really any 32-bit device or GOARCH=386 on amd64 and:

go1.18.1
panic: unaligned 64-bit atomic operation
preempt off reason: doAllThreadsSyscall
fatal error: panic during preemptoff

goroutine 1 [running]:
runtime.throw({0xb29fd, 0x17})
	/home/bradfitz/sdk/go1.18.1/src/runtime/panic.go:992 +0x5c fp=0xc9ae4c sp=0xc9ae38 pc=0x45b14
panic({0xa6658, 0xccb24})
	/home/bradfitz/sdk/go1.18.1/src/runtime/panic.go:780 +0x710 fp=0xc9aeac sp=0xc9ae4c pc=0x4595c
runtime/internal/atomic.panicUnaligned()
	/home/bradfitz/sdk/go1.18.1/src/runtime/internal/atomic/unaligned.go:8 +0x24 fp=0xc9aeb8 sp=0xc9aeac pc=0x11f54
runtime/internal/atomic.Load64(0xc80024)
	/home/bradfitz/sdk/go1.18.1/src/runtime/internal/atomic/atomic_arm.s:280 +0x14 fp=0xc9aebc sp=0xc9aeb8 pc=0x122a8
syscall.runtime_doAllThreadsSyscall(0xce, 0x3, 0xcb8020, 0x0, 0x0, 0x0, 0x0)
	/home/bradfitz/sdk/go1.18.1/src/runtime/os_linux.go:816 +0x360 fp=0xc9af2c sp=0xc9aebc pc=0x72e50
syscall.AllThreadsSyscall(0xce, 0x3, 0xcb8020, 0x0)
	/home/bradfitz/sdk/go1.18.1/src/syscall/syscall_linux.go:987 +0x6c fp=0xc9af58 sp=0xc9af2c pc=0x904c4
syscall.Setgroups({0xc9afa4, 0x3, 0x3})
	/home/bradfitz/sdk/go1.18.1/src/syscall/syscall_linux.go:307 +0x2cc fp=0xc9af80 sp=0xc9af58 pc=0x90388
main.main()
	/home/bradfitz/hack/setgroups/setgroups.go:11 +0xb0 fp=0xc9afc0 sp=0xc9af80 pc=0x9bfe8
runtime.main()
	/home/bradfitz/sdk/go1.18.1/src/runtime/proc.go:250 +0x26c fp=0xc9afec sp=0xc9afc0 pc=0x48764
runtime.goexit()
	/home/bradfitz/sdk/go1.18.1/src/runtime/asm_arm.s:824 +0x4 fp=0xc9afec sp=0xc9afec pc=0x75a64

That os_linux.go:816 is:

                for atomic.Load64(&mp.procid) == 0 {                                 |

The m type is:

type m struct {
        g0      *g     // goroutine with scheduling stack
        morebuf gobuf  // gobuf arg to morestack
        divmod  uint32 // div/mod denominator for arm - known to liblink

        // Fields not known to debuggers.
        procid        uint64            // for debuggers, but offset not hard-coded
        gsignal       *g                // signal-handling g

Looks like gobuf is 7 words wide, which puts procid at 9 words offset? (not 64-bit aligned)

Didn't look too closely.

/cc @maisem @raggi @golang/runtime

@bradfitz
Copy link
Contributor Author

bradfitz commented May 10, 2022

Maybe a regression from 8ac23a1 which added a word to gobuf? 8ac23a1#diff-2fee911f97df63422c5ecf0a75227796f174f1a8e0ae9200fe0acdbd29ffc29b ?

Edit: nope. 8ac23a1 passes, as does its parent, 678568a.

@bradfitz bradfitz changed the title runtime: unaligned atomic access to m.procid on linux/arm (32-bit) runtime: unaligned atomic access to m.procid on 32-bit (arm, 386, ...) May 10, 2022
@bradfitz
Copy link
Contributor Author

It broke as of 0a5fae2 (https://golang.org/cl/383434) on Feb 15. It's fine at 0a5fae2's parent (0b321c9).

bradfitz@tsdev:~/hack/setgroups$ GOARCH=386 ~/hack/go/bin/go run -exec=sudo setgroups.go
devel go1.18-0b321c9a7c Tue Feb 15 15:40:29 2022 +0000
<nil>
bradfitz@tsdev:~/hack/setgroups$ GOARCH=386 ~/hack/go/bin/go run -exec=sudo setgroups.go
devel go1.18-0a5fae2a0e Tue Feb 15 15:40:35 2022 +0000
panic: unaligned 64-bit atomic operation
preempt off reason: doAllThreadsSyscall
fatal error: panic during preemptoff

goroutine 1 [running]:
runtime.throw({0x80d8c54, 0x17})
        /home/bradfitz/hack/go/src/runtime/panic.go:992 +0x6a fp=0xa05ce54 sp=0xa05ce40 pc=0x80786ca
panic({0x80cbb00, 0x80f2170})
        /home/bradfitz/hack/go/src/runtime/panic.go:780 +0x606 fp=0xa05ceb0 sp=0xa05ce54 pc=0x8078526
runtime/internal/atomic.panicUnaligned()
        /home/bradfitz/hack/go/src/runtime/internal/atomic/unaligned.go:8 +0x2d fp=0xa05cebc sp=0xa05ceb0 pc=0x8049b1d
runtime/internal/atomic.Load64(0xa080024)
        /home/bradfitz/hack/go/src/runtime/internal/atomic/atomic_386.s:225 +0x10 fp=0xa05cec0 sp=0xa05cebc pc=0x8049d80
syscall.runtime_doAllThreadsSyscall(0xce, 0x3, 0xa010080, 0x0, 0x0, 0x0, 0x0)
        /home/bradfitz/hack/go/src/runtime/os_linux.go:816 +0x367 fp=0xa05cf30 sp=0xa05cec0 pc=0x809f097
syscall.AllThreadsSyscall(0xce, 0x3, 0xa010080, 0x0)
        /home/bradfitz/hack/go/src/syscall/syscall_linux.go:987 +0x7b fp=0xa05cf5c sp=0xa05cf30 pc=0x80b989b
syscall.Setgroups({0xa05cfa4, 0x3, 0x3})
        /home/bradfitz/hack/go/src/syscall/syscall_linux.go:307 +0x262 fp=0xa05cf84 sp=0xa05cf5c pc=0x80b97a2
main.main()
        /home/bradfitz/hack/setgroups/setgroups.go:11 +0xcf fp=0xa05cfc4 sp=0xa05cf84 pc=0x80c3b7f
runtime.main()
        /home/bradfitz/hack/go/src/runtime/proc.go:250 +0x24d fp=0xa05cff0 sp=0xa05cfc4 pc=0x807accd
runtime.goexit()
        /home/bradfitz/hack/go/src/runtime/asm_386.s:1326 +0x1 fp=0xa05cff4 sp=0xa05cff0 pc=0x80a1681
exit status 2

/cc @prattmic

@bradfitz
Copy link
Contributor Author

Sigh. And now I found dup bug #51776.

Closing.

@golang golang locked and limited conversation to collaborators May 10, 2023
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

2 participants