Skip to content

fix data race in ReentrantLock fallback for targets without 64bit atomics #141248

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

Merged
merged 2 commits into from
May 19, 2025

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented May 19, 2025

See Zulip for details: the address used to identify a thread might get lazily allocated inside tls_addr(), so if we call that after doing the tls_addr.load() it is too late to establish synchronization with prior threads that used the same address -- the load() thus races with the store() by that prior thread, and might hence see outdated values, and then the entire logic breaks down.

r? @joboet

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 19, 2025

The Miri subtree was changed

cc @rust-lang/miri

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will not be run by bors, only by the Miri test suite on the next sync. I verified it locally.

However we anyway don't have mips-unknown-linux-gnu in the Miri test suite... is there any tier 1 target without 64bit atomics?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there is not. rust-lang/miri#4333 adds this mips target so that we will cover this in the future.

Copy link
Member

@joboet joboet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that was subtle...
r=me once CI passes

@RalfJung
Copy link
Member Author

@bors r=joboet

@bors
Copy link
Collaborator

bors commented May 19, 2025

📌 Commit 26ea763 has been approved by joboet

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 19, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 19, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#131200 (Handle `rustc_query_system` cases of `rustc::potential_query_instability` lint)
 - rust-lang#141244 (windows: document that we rely on an undocumented property of GetUserProfileDirectoryW)
 - rust-lang#141247 (skip compiler tools sanity checks on certain commands)
 - rust-lang#141248 (fix data race in ReentrantLock fallback for targets without 64bit atomics)
 - rust-lang#141249 (introduce common macro for `MutVisitor` and `Visitor` to dedup code)
 - rust-lang#141253 (Warning added when dependency crate has async drop types, and the feature is disabled)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6e784f8 into rust-lang:master May 19, 2025
6 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 19, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 19, 2025
Rollup merge of rust-lang#141248 - RalfJung:reentrant-lock-race, r=joboet

fix data race in ReentrantLock fallback for targets without 64bit atomics

See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/269128-miri/topic/reentrant.20lock.20failure.20on.20musl) for details: the address used to identify a thread might get lazily allocated inside `tls_addr()`, so if we call that *after* doing the `tls_addr.load()` it is too late to establish synchronization with prior threads that used the same address -- the `load()` thus races with the `store()` by that prior thread, and might hence see outdated values, and then the entire logic breaks down.

r? `@joboet`
@RalfJung RalfJung deleted the reentrant-lock-race branch May 20, 2025 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants