-
Notifications
You must be signed in to change notification settings - Fork 353
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
Initialisation value of atomic types can no longer be observed if the first atomic access is a store #2164
Labels
Comments
cbeuw
changed the title
Initialisation value of atomic types can no longer be observed if the first atomic access is a write
Initialisation value of atomic types can no longer be observed if the first atomic access is a store
May 29, 2022
RalfJung
added
C-bug
Category: This is a bug.
A-weak-memory
Area: emulation of weak memory effects (store buffers)
labels
Jun 5, 2022
6 tasks
cbeuw
added a commit
to cbeuw/miri
that referenced
this issue
Jun 5, 2022
cbeuw
added a commit
to cbeuw/miri
that referenced
this issue
Jun 5, 2022
RalfJung
added a commit
to RalfJung/miri
that referenced
this issue
Jul 14, 2022
LegNeato
pushed a commit
to LegNeato/miri
that referenced
this issue
Jul 14, 2022
workingjubilee
added a commit
to workingjubilee/rustc
that referenced
this issue
Aug 27, 2024
…saethlin miri weak memory emulation: put previous value into initial store buffer Fixes rust-lang/miri#2164 by doing a read before each atomic write so that we can initialize the store buffer. The read suppresses memory access hooks and UB exceptions, to avoid otherwise influencing the program behavior. If the read fails, we store that as `None` in the store buffer, so that when an atomic read races with the first atomic write to some memory and previously the memory was uninitialized, we can report UB due to reading uninit memory. `@cbeuw` this changes a bit the way we initialize the store buffers. Not sure if you still remember all this code, but if you could have a look to make sure this still makes sense, that would be great. :) r? `@saethlin`
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Aug 27, 2024
Rollup merge of rust-lang#128942 - RalfJung:interpret-weak-memory, r=saethlin miri weak memory emulation: put previous value into initial store buffer Fixes rust-lang/miri#2164 by doing a read before each atomic write so that we can initialize the store buffer. The read suppresses memory access hooks and UB exceptions, to avoid otherwise influencing the program behavior. If the read fails, we store that as `None` in the store buffer, so that when an atomic read races with the first atomic write to some memory and previously the memory was uninitialized, we can report UB due to reading uninit memory. ``@cbeuw`` this changes a bit the way we initialize the store buffers. Not sure if you still remember all this code, but if you could have a look to make sure this still makes sense, that would be great. :) r? ``@saethlin``
github-actions bot
pushed a commit
that referenced
this issue
Aug 28, 2024
miri weak memory emulation: put previous value into initial store buffer Fixes #2164 by doing a read before each atomic write so that we can initialize the store buffer. The read suppresses memory access hooks and UB exceptions, to avoid otherwise influencing the program behavior. If the read fails, we store that as `None` in the store buffer, so that when an atomic read races with the first atomic write to some memory and previously the memory was uninitialized, we can report UB due to reading uninit memory. ``@cbeuw`` this changes a bit the way we initialize the store buffers. Not sure if you still remember all this code, but if you could have a look to make sure this still makes sense, that would be great. :) r? ``@saethlin``
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
On platforms with weaker memory models (such as ARM), it should be possible for the above program to print 0, because
X.store(1, Relaxed)
does not happen beforeX.load(Relaxed)
so it's allowed to observe an "outdated" value.However, on Miri, once
X.store(1, Relaxed)
is executed, the initialisation value 0 can never be observed again. This is because the store buffers used to keep the atomic stores are lazily allocated on the first atomic access of a location. We can't obtain the value in the underlying location in the atomic write shim because callingread_scalar()
on the location has side effects which implies that a read on the location happened in the MIR even though there isn't one.To fix,
rustc_const_eval
needs to provide a method letting us obtain the value on a location for internal machine implementation rather than user program behaviourThe text was updated successfully, but these errors were encountered: