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/internal/atomic: Xadd64 missing alignment check on some 32-bit systems #17786

Closed
bradfitz opened this issue Nov 4, 2016 · 7 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Nov 4, 2016

Reminder to revert https://go-review.googlesource.com/c/31635/ per @cherrymui's comment there.

But maybe we wait until mips lands and works.

@bradfitz bradfitz added this to the Go1.8 milestone Nov 4, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 7, 2016
@rsc
Copy link
Contributor

rsc commented Nov 11, 2016

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.

@rsc rsc changed the title runtime: revert alignment change runtime/internal/atomic: Xadd64 missing alignment check on some 32-bit systems Nov 11, 2016
@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Nov 12, 2016
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>
@gopherbot
Copy link

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

@gopherbot
Copy link

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

@cherrymui
Copy link
Member

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...)

@minux
Copy link
Member

minux commented Nov 15, 2016

I also don't like the current approach.

How about we add a runtime.alignedInt64 type and handle it specially in the
compiler (similar to how runtime.hex is handled by the compiler.)

We can also make runtime/internal/atomic 64-bit atomic operations require
pointer to that type instead of regular *int64.

We can decide whether to add something to the sync package later (for
example, we could add a sync/atomic.Int64 type with accessor methods and
also make the compiler reject any direct access to values of that type.)

If there are interests, I can write up a proposal. But I'm a little
concerned that it might lead to abuse of the sync/atomic package, which, in
general, is very hard to use correctly.

@aclements
Copy link
Member

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).

gopherbot pushed a commit that referenced this issue Nov 21, 2016
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>
gopherbot pushed a commit that referenced this issue Nov 21, 2016
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>
@golang golang locked and limited conversation to collaborators Nov 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants