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: for arm and mips compare-and-swap does not have a memory barrier on failure #63506

Open
ianlancetaylor opened this issue Oct 11, 2023 · 4 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

In the discussion about #63384 we agreed that it would be best if atomic compare-and-swap applied a memory barrier even if the comparison fails. That avoids potential race conditions such as the one described in that issue.

Based on my own inspection, the arm and mips implementation of compare-and-swap do not implement the expected memory barrier. The arm64 and mips64 implementations look OK.

CC @golang/arm @golang/mips @golang/runtime

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 11, 2023
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Oct 11, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 11, 2023
mauri870 added a commit to mauri870/go that referenced this issue Oct 17, 2023
This CL adds a memory barrier on the failure case of the
compare-and-swap for arm.

For golang#63506
mauri870 added a commit to mauri870/go that referenced this issue Oct 17, 2023
Add a memory barrier on the failure case of the
compare-and-swap for mips, this avoids potential
race conditions.

For golang#63506
@gopherbot
Copy link

Change https://go.dev/cl/536115 mentions this issue: runtime/internal/atomic: add memory barrier for arm Cas on failure

@gopherbot
Copy link

Change https://go.dev/cl/536116 mentions this issue: runtime/internal/atomic: add memory barrier for mips Cas on failure

gopherbot pushed a commit that referenced this issue Oct 24, 2023
Add a memory barrier on the failure case of the
compare-and-swap for mips, this avoids potential
race conditions.

For #63506

Change-Id: I3df1479d1438ba72aa72567eb3dea76ff745e98d
GitHub-Last-Rev: 2101b9f
GitHub-Pull-Request: #63604
Reviewed-on: https://go-review.googlesource.com/c/go/+/536116
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@mauri870
Copy link
Member

mauri870 commented Nov 7, 2023

@ianlancetaylor I'm not sure how to proceed with the fix for the arm platform, quoting Keith Randall reply on the CL:

The pre-cas barriers already existed for mips and ppc64, they were not part of the fix to 63506. That said, maybe arm needs one? I'm not entirely sure why we would need a barrier both on entry and on exit. Just one of the two should suffice?
This is very tricky code. I am unsure how we would convince ourselves of the correctness...

@aclements
Copy link
Member

I'm not positive this would work, but ARM does have a model checker for ARM64 memory synchronization code: https://developer.arm.com/herd7 (docs). While ARM64 is pretty different from ARM in general, I think in this particular case the code can be translated to ARM64 without loss of fidelity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Status: In Progress
Development

No branches or pull requests

4 participants