-
Notifications
You must be signed in to change notification settings - Fork 346
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
Consider the cargo workspace when checking if a frame is local #2024
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saethlin
commented
Mar 13, 2022
saethlin
commented
Mar 13, 2022
saethlin
force-pushed
the
better-local-check
branch
from
March 13, 2022 06:14
3e78bce
to
d382776
Compare
RalfJung
reviewed
Mar 16, 2022
RalfJung
reviewed
Mar 16, 2022
saethlin
force-pushed
the
better-local-check
branch
from
March 17, 2022 00:07
d382776
to
fa94a38
Compare
saethlin
force-pushed
the
better-local-check
branch
from
March 17, 2022 16:40
fa94a38
to
d951114
Compare
☔ The latest upstream changes (presumably #2029) made this pull request unmergeable. Please resolve the merge conflicts. |
RalfJung
reviewed
Mar 17, 2022
RalfJung
reviewed
Mar 17, 2022
RalfJung
reviewed
Mar 17, 2022
RalfJung
reviewed
Mar 17, 2022
saethlin
force-pushed
the
better-local-check
branch
2 times, most recently
from
March 18, 2022 19:36
8943a1a
to
f19d6f4
Compare
RalfJung
reviewed
Mar 18, 2022
saethlin
force-pushed
the
better-local-check
branch
from
March 18, 2022 20:28
f19d6f4
to
65125df
Compare
Thanks! @bors r+ |
📌 Commit 65125df has been approved by |
☀️ Test successful - checks-actions |
bors
added a commit
that referenced
this pull request
May 14, 2022
Print spans where tags are created and invalidated 5225225 called this "automatic tag tracking" and I think that may be a reasonable description, but I would like to kill tag tracking as a primary use of Miri if possible. Tag tracking isn't always possible; for example if the UB is only detected with isolation off and the failing tag is made unstable by removing isolation. (also it's bad UX to run the tool twice) This is just one of the things we can do with #2024 The memory usage of this is _shockingly_ low, I think because the memory usage of Miri is driven by allocations where each byte ends up with its own very large stack. The memory usage in this change is linear with the number of tags, not tags * bytes. If memory usage gets out of control we can cap the number of events we save per allocation, from experience we tend to only use the most recent few in diagnostics but of course there's no guarantee of that so if we can manage to keep everything that would be best. In many cases now I can tell exactly what these codebases are doing wrong just from the new outputs here, which I think is extremely cool. New helps generated with plain old `cargo miri test` on `rust-argon2` v1.0.0: ``` test argon2::tests::single_thread_verification_multi_lane_hash ... error: Undefined Behavior: trying to reborrow <1485898> for Unique permission at alloc110523[0x0], but that tag does not exist in the borrow stack for this location --> /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/mem/manually_drop.rs:89:9 | 89 | slot.value | ^^^^^^^^^^ | | | trying to reborrow <1485898> for Unique permission at alloc110523[0x0], but that tag does not exist in the borrow stack for this location | this error occurs as part of a reborrow at alloc110523[0x0..0x20] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information help: <1485898> was created by a retag at offsets [0x0..0x20] --> src/memory.rs:42:13 | 42 | vec.push(unsafe { &mut (*ptr) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: <1485898> was later invalidated at offsets [0x0..0x20] --> src/memory.rs:42:31 | 42 | vec.push(unsafe { &mut (*ptr) }); | ^^^^^^^^^^^ ``` And with `-Zmiri-tag-raw-pointers` on `slab` v0.4.5 ``` error: Undefined Behavior: trying to reborrow <2915> for Unique permission at alloc1418[0x0], but that tag does not exist in the borrow stack for this location --> /tmp/slab-0.4.5/src/lib.rs:835:16 | 835 | match (&mut *ptr1, &mut *ptr2) { | ^^^^^^^^^^ | | | trying to reborrow <2915> for Unique permission at alloc1418[0x0], but that tag does not exist in the borrow stack for this location | this error occurs as part of a reborrow at alloc1418[0x0..0x10] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information help: <2915> was created by a retag at offsets [0x0..0x10] --> /tmp/slab-0.4.5/src/lib.rs:833:20 | 833 | let ptr1 = self.entries.get_unchecked_mut(key1) as *mut Entry<T>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: <2915> was later invalidated at offsets [0x0..0x20] --> /tmp/slab-0.4.5/src/lib.rs:834:20 | 834 | let ptr2 = self.entries.get_unchecked_mut(key2) as *mut Entry<T>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` And without raw pointer tagging, `cargo miri test` on `half` v1.8.2 ``` error: Undefined Behavior: trying to reborrow <untagged> for Unique permission at alloc1340[0x0], but that tag only grants SharedReadOnly permission for this location --> /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/slice/raw.rs:141:9 | 141 | &mut *ptr::slice_from_raw_parts_mut(data, len) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | trying to reborrow <untagged> for Unique permission at alloc1340[0x0], but that tag only grants SharedReadOnly permission for this location | this error occurs as part of a reborrow at alloc1340[0x0..0x6] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information help: tag was most recently created at offsets [0x0..0x6] --> /tmp/half-1.8.2/src/slice.rs:309:22 | 309 | let length = self.len(); | ^^^^^^^^^^ help: this tag was also created here at offsets [0x0..0x6] --> /tmp/half-1.8.2/src/slice.rs:308:23 | 308 | let pointer = self.as_ptr() as *mut u16; | ^^^^^^^^^^^^^ ``` The second suggestion is close to guesswork, but from experience it tends to be correct (as in, it tends to locate the pointer the user wanted) more often that it doesn't.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DefId::is_local
returns a result which is technically correct, but doesn't match the user's intuition when running integration tests or doctests. This incorporates the workspace crates mentioned incargo metadata
into the check for whether a frame is local to match user intuition.For example, here is the backtrace you get from
MIRIFLAGS=-Zmiri-tag-raw-pointers cargo miri test
inbytes
1.1.0:We get these because the integration tests are occurring in a crate called
test
, not the actualbytes
crate. With this PR, we get this:Note that this kind of inflation is rather rare to see. Most backtraces change not at all or only a tiny bit.
I originally implemented this to support another improvement to Miri diagnostics, but I think this is hairy enough to deserve its own PR, if somewhat poorly-motivated.