allocations: document that they can be read-only - #159503
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@rfcbot merge opsem |
|
@RalfJung has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
Is there a reason we can't model this more simply as just only handing out read-only provenance pointers to these allocations without needing a separate notion of a read-only allocation? Checking my box anyway – if there's a reason that a provenance-based approach isn't viable (or isn't genuinely simpler) then I'm happy to merge as-is. |
I think with the restrictions we have on atomics, that does not work. Doing a |
|
Our docs on atomic accesses to read-only memory say:
IIUC, this is a platform-level detail, not an opsem thing? In other words, the fact that an atomic
...because opsem doesn't "know" that the underlying atomic load is implemented via compare-exchange? |
Correct. On the semantics / Abstract Machine level, a failing CAS and an atomic load are read-only operations, they don't change the contents of memory. (They do change some other state related to the concurrency memory model, but that's a separate question.) In other words, this is sound, at least under Tree Borrows: use std::sync::atomic::*;
fn main() { unsafe {
let x = 0i32;
let atomic_x = &*(&x as *const i32 as *const AtomicI32);
// atomic_x is derived from &x, so it has read-only provenance.
atomic_x.load(Ordering::SeqCst);
} } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Jacob Lifshay <programmerjake@gmail.com>
|
@bors r+ rollup |
|
📋 This PR cannot be approved because it currently has the following label: |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
|
@bors r=Mark-Simulacrum rollup |
…acrum allocations: document that they can be read-only Miri currently tracks "read-only" as an explicit flag on allocations that exists independent of provenance. It essentially corresponds to a read-only mapping in the page table. Let's make this officially part of our model. Cc @rust-lang/lang @rust-lang/opsem
…acrum allocations: document that they can be read-only Miri currently tracks "read-only" as an explicit flag on allocations that exists independent of provenance. It essentially corresponds to a read-only mapping in the page table. Let's make this officially part of our model. Cc @rust-lang/lang @rust-lang/opsem
…uwer Rollup of 10 pull requests Successful merges: - #157572 (stabilize size_of_val_raw, align_of_val_raw, Layout::for_value_raw) - #160012 (miri: ensure validity of references and pointers we dereference and cast) - #160294 (Update Enzyme to resolve one of the open bugs) - #159503 (allocations: document that they can be read-only) - #160250 (When issuing suggestions for missing trait items, label unstable items) - #160251 (Replace unsafe usage of `NonNull::new_unchecked` with `Box::into_non_null`) - #160311 (Remove final use of sealed traits from stdlib) - #160313 (Make the noundef-on-Cast size guard explicit) - #160323 (Box::leak: tell people to avoid unleaking) - #160328 (Move `check_track_caller` into the attribute parser)
…uwer Rollup of 12 pull requests Successful merges: - #157572 (stabilize size_of_val_raw, align_of_val_raw, Layout::for_value_raw) - #160012 (miri: ensure validity of references and pointers we dereference and cast) - #160294 (Update Enzyme to resolve one of the open bugs) - #159503 (allocations: document that they can be read-only) - #160179 (std: Update `wasip3` crate dependency) - #160250 (When issuing suggestions for missing trait items, label unstable items) - #160251 (Replace unsafe usage of `NonNull::new_unchecked` with `Box::into_non_null`) - #160311 (Remove final use of sealed traits from stdlib) - #160313 (Make the noundef-on-Cast size guard explicit) - #160323 (Box::leak: tell people to avoid unleaking) - #160328 (Move `check_track_caller` into the attribute parser) - #160333 (Remove itertools dependency from `rustc_ast_pretty`)
…uwer Rollup of 12 pull requests Successful merges: - rust-lang/rust#157572 (stabilize size_of_val_raw, align_of_val_raw, Layout::for_value_raw) - rust-lang/rust#160012 (miri: ensure validity of references and pointers we dereference and cast) - rust-lang/rust#160294 (Update Enzyme to resolve one of the open bugs) - rust-lang/rust#159503 (allocations: document that they can be read-only) - rust-lang/rust#160179 (std: Update `wasip3` crate dependency) - rust-lang/rust#160250 (When issuing suggestions for missing trait items, label unstable items) - rust-lang/rust#160251 (Replace unsafe usage of `NonNull::new_unchecked` with `Box::into_non_null`) - rust-lang/rust#160311 (Remove final use of sealed traits from stdlib) - rust-lang/rust#160313 (Make the noundef-on-Cast size guard explicit) - rust-lang/rust#160323 (Box::leak: tell people to avoid unleaking) - rust-lang/rust#160328 (Move `check_track_caller` into the attribute parser) - rust-lang/rust#160333 (Remove itertools dependency from `rustc_ast_pretty`)
View all comments
Miri currently tracks "read-only" as an explicit flag on allocations that exists independent of provenance. It essentially corresponds to a read-only mapping in the page table.
Let's make this officially part of our model.
Cc @rust-lang/lang @rust-lang/opsem