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/internal/atomic: Xadd64 missing alignment check on some 32-bit systems #17786
Comments
The change should not be reverted. Instead the 64-bit atomics on the 32-bit systems should all include alignment checks. On the 32-bit x86, it may appear that unaligned 64-bit atomics are atomic - they execute at least - but that turns out to be true in practice only when the 64-bit value does not span a cache line boundary. If it does, then the operation is silently non-atomic. The way to make a 64-bit value not span a cache line boundary is to be 64-bit aligned (because so are cache line boundaries). So all 32-bit systems should actively require in their 64-bit atomic implementations that values to be acted upon are 64-bit aligned in memory. |
CL https://golang.org/cl/33159 mentions this issue. |
Add a variant of sync/atomic's TestUnaligned64 to runtime/internal/atomic. Skips the test on arm for now where it's currently failing. Updates #17786 Change-Id: If63f9c1243e9db7b243a95205b2d27f7d1dc1e6e Reviewed-on: https://go-review.googlesource.com/33159 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
CL https://golang.org/cl/33236 mentions this issue. |
CL https://golang.org/cl/33235 mentions this issue. |
It turns out I have to add another padding in the runtime (CL https://go-review.googlesource.com/c/33235/). I am not sure this is the best way to do -- it makes the struct unnecessarily one word larger on 64-bit architectures, and it is not future-proofing (if we add/delete/change a field before it, we need to adjust the padding). Maybe we should do something in the compiler? Add a go:align pragma? (but I'm worried about adding too many pragmas...) |
I also don't like the current approach. How about we add a runtime.alignedInt64 type and handle it specially in the We can also make runtime/internal/atomic 64-bit atomic operations require We can decide whether to add something to the sync package later (for If there are interests, I can write up a proposal. But I'm a little |
We could potentially add a type for the runtime, but I don't think we could do this in sync. It still seems to me like a reasonable middle ground is to have a vet check for this (aka #11891). |
Make atomic access on 32-bit architectures happy. Updates #17786. Change-Id: I42de63ff1381af42124dc51befc887160f71797d Reviewed-on: https://go-review.googlesource.com/33235 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Austin Clements <austin@google.com>
Updates #17786. Will fix mips(32) when the port is fully landed. Change-Id: I00d4ff666ec14a38cadbcd52569b347bb5bc8b75 Reviewed-on: https://go-review.googlesource.com/33236 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reminder to revert https://go-review.googlesource.com/c/31635/ per @cherrymui's comment there.
But maybe we wait until mips lands and works.
The text was updated successfully, but these errors were encountered: