Commit Graph

2974 Commits

Author SHA1 Message Date
Ralf Jung
22aa7f98c5 call_function: make the unit-return-type case more convenient 2022-07-04 13:46:11 -04:00
Ralf Jung
a4e7e1e6b5 fix retagging of vtable ptrs 2022-07-03 11:56:29 -04:00
bors
cfad9d12f3 Auto merge of #1935 - saethlin:optimize-sb, r=RalfJung
Optimizing Stacked Borrows (part 1?): Cache locations of Tags in a Borrow Stack

Before this PR, a profile of Miri under almost any workload points quite squarely at these regions of code as being incredibly hot (each being ~40% of cycles):

dadcbebfbd/src/stacked_borrows.rs (L259-L269)

dadcbebfbd/src/stacked_borrows.rs (L362-L369)

This code is one of at least three reasons that stacked borrows analysis is super-linear: These are both linear in the number of borrows in the stack and they are positioned along the most commonly-taken paths.

I'm addressing the first loop (which is in `Stack::find_granting`) by adding a very very simple sort of LRU cache implemented on a `VecDeque`, which maps recently-looked-up tags to their position in the stack. For `Untagged` access we fall back to the same sort of linear search. But as far as I can tell there are never enough `Untagged` items to be significant.

I'm addressing the second loop by keeping track of the region of stack where there could be items granting `Permission::Unique`. This optimization is incredibly effective because `Read` access tends to dominate and many trips through this code path now skip the loop entirely.

These optimizations result in pretty enormous improvements:
Without raw pointer tagging, `mse` 34.5s -> 2.4s, `serde1` 5.6s -> 3.6s
With raw pointer tagging, `mse` 35.3s -> 2.4s, `serde1` 5.7s -> 3.6s

And there is hardly any impact on memory usage:
Memory usage on `mse` 844 MB -> 848 MB, `serde1` 184 MB -> 184 MB (jitter on these is a few MB).
2022-07-03 14:39:22 +00:00
Ben Kimock
b004a03bdb Typo 2022-07-02 20:45:27 -04:00
Ben Kimock
f3b479d556 Explain cache behavior a bit better, clean up diff 2022-07-02 19:44:55 -04:00
Ralf Jung
d9c441c5ab put call to stacked borrows end_call in a more sensible place 2022-07-02 18:38:07 -04:00
Ben Kimock
7cdbf98f57 Explain the behavior of the cache upon clear 2022-07-02 13:22:22 -04:00
Ralf Jung
98254f67af pointer tag tracking: on creation, log the offsets it is created for 2022-07-02 11:33:29 -04:00
bors
428245072e Auto merge of #2306 - RalfJung:unix, r=RalfJung
make some things available for all Unixes
2022-07-02 13:45:27 +00:00
Ralf Jung
5ba2c1e6be posix_fadvise is not Linux-specific 2022-07-02 09:45:00 -04:00
Ralf Jung
98d20490f4 move some POSIX file shims from linux to unix module 2022-07-02 09:45:00 -04:00
InfRandomness
5ec25359ff
Add environ extern implementation to freebsd
Signed-off-by: InfRandomness <infrandomness@gmail.com>
2022-07-02 12:42:14 +02:00
bors
602a3dcefd Auto merge of #2304 - LegNeato:shim-fstat64-mac, r=oli-obk
Support (stat/fstat/lstat)64 on macos

"In order to accommodate advanced capabilities of newer file systems,
     the struct stat, struct statfs, and struct dirent data structures
     were updated in Mac OSX 10.5."

"TRANSITIONAL DESCRIPTION (NOW DEPRECATED)
     The fstat64, lstat64 and stat64 routines are equivalent to their
     corresponding non-64-suffixed routine, when 64-bit inodes are in
     effect.  They were added before there was support for the symbol
     variants, and so are now deprecated.  Instead of using these, set
     the _DARWIN_USE_64_BIT_INODE macro before including header files to
     force 64-bit inode support. The stat64 structure used by these deprecated routines is the same
     as the stat structure when 64-bit inodes are in effect (see above)."

"HISTORY
     An lstat() function call appeared in 4.2BSD.  The stat64(),
     fstat64(), and lstat64() system calls first appeared in Mac OS X
     10.5 (Leopard) and are now deprecated in favor of the corresponding
     symbol variants.  The fstatat() system call appeared in OS X 10.10"
2022-07-02 07:31:16 +00:00
Christian Legnitto
a1473ea8f5 Support (stat/fstat/lstat)64 on macos
"In order to accommodate advanced capabilities of newer file systems,
     the struct stat, struct statfs, and struct dirent data structures
     were updated in Mac OSX 10.5."

"TRANSITIONAL DESCRIPTION (NOW DEPRECATED)
     The fstat64, lstat64 and stat64 routines are equivalent to their
     corresponding non-64-suffixed routine, when 64-bit inodes are in
     effect.  They were added before there was support for the symbol
     variants, and so are now deprecated.  Instead of using these, set
     the _DARWIN_USE_64_BIT_INODE macro before including header files to
     force 64-bit inode support.

     The stat64 structure used by these deprecated routines is the same
     as the stat structure when 64-bit inodes are in effect (see above)."

"HISTORY
     An lstat() function call appeared in 4.2BSD.  The stat64(),
     fstat64(), and lstat64() system calls first appeared in Mac OS X
     10.5 (Leopard) and are now deprecated in favor of the corresponding
     symbol variants.  The fstatat() system call appeared in OS X 10.10"
2022-07-01 20:10:17 -06:00
Ben Kimock
17acc3f71c Document implementation a bit, add some fast paths 2022-07-01 20:15:34 -04:00
Ralf Jung
d09db1660b fix and slightly improve data race reports 2022-07-01 20:13:44 -04:00
Ben Kimock
3bbcafe3b5 Cache lookups into the borrow stack
This adds a very simple LRU-like cache which stores the locations of
often-used tags. While the implementation is very simple, the cache hit
rate is incredible at ~99.9% on most programs, and often the element at
position 0 in the cache has a hit rate of 90%. So the sub-optimality of
this cache basicaly vanishes into the noise in a profile.

Additionally, we keep a range which denotes where there might be an item
granting Unique permission in the stack, so that when we invalidate
Uniques we do not need to scan much of the stack, and often scan nothing
at all.
2022-07-01 17:51:16 -04:00
Ralf Jung
dfdedae840 avoid copying thread manager state in data race detector 2022-07-01 17:07:29 -04:00
Ralf Jung
f238513efa rename some data_race types for more clarity 2022-07-01 16:21:48 -04:00
bors
c1a37b87aa Auto merge of #2298 - InfRandomness:shim-error, r=RalfJung
Add `__error` to freebsd shims

Signed-off-by: InfRandomness <infrandomness@gmail.com>
2022-07-01 17:41:10 +00:00
InfRandomness
dca2bb68b3
Add __error to freebsd shims
Signed-off-by: InfRandomness <infrandomness@gmail.com>
2022-07-01 18:42:33 +02:00
Ralf Jung
12d04ac4c4 make clippy happy 2022-07-01 12:25:35 -04:00
Ralf Jung
af39709a9c rustup 2022-07-01 10:14:31 -04:00
Ralf Jung
7f3fbbdee7 allocation tracking: also print size, alignment, kind of the allocation 2022-06-30 22:24:23 -04:00
Ralf Jung
aef78d3a9f make -Zmiri-env-forward take precedence over -Zmiri-env-exclude 2022-06-30 11:14:30 -04:00
Ralf Jung
6a204e2dec use Rust SnakeCase 2022-06-29 22:17:46 -04:00
bors
5974e7d4a9 Auto merge of #2287 - RalfJung:field-retagging, r=RalfJung
stacked borrows: add option for recursive field retagging
2022-06-29 23:04:07 +00:00
Ralf Jung
c4e86e103e add option for recursive field retagging 2022-06-29 18:22:30 -04:00
Christian Legnitto
73a1a27a45 Support gettimeofday on more than macos
This appears to be in linux and in openbsd as well:

* https://github.com/torvalds/linux/blob/master/lib/vdso/gettimeofday.c
* https://github.com/openbsd/src/blob/master/sys/sys/time.h#L439

Co-authored-by: Ralf Jung <post@ralfj.de>
2022-06-29 17:48:04 -04:00
Ralf Jung
839c120b40 fmt 2022-06-29 10:09:18 -04:00
Ralf Jung
f389d46b04 also prune caller_location frames when backtrace=off 2022-06-29 09:33:12 -04:00
Ralf Jung
28dea673be rustup 2022-06-29 08:33:06 -04:00
Ralf Jung
8bd4bbe3e4 tweak int2ptr diagnostics 2022-06-28 08:52:22 -04:00
bors
aaaed51ab8 Auto merge of #2279 - RalfJung:adjacent-allocs, r=RalfJung
Allow non-ZST allocations to be adjacent

Also `cargo update` in test-cargo-miri... no need to make a separate PR for that right?...
2022-06-28 02:52:23 +00:00
Ralf Jung
c16b380d6b finally we can actually have adjacent allocations :) 2022-06-27 22:52:02 -04:00
Ralf Jung
098704e10f make use of get_alloc_info 2022-06-27 21:22:46 -04:00
bors
7fafbde038 Auto merge of #2275 - RalfJung:permissive-provenance-for-all, r=RalfJung
Enable permissive provenance by default

This completes the plan laid out in https://github.com/rust-lang/miri/issues/2133:
- We use permissive provenance with wildcard pointers by default.
- We print a warning on int2ptr casts. `-Zmiri-permissive-provenance` suppresses the warning; `-Zmiri-strict-provenance` turns it into a hard error.
- Raw pointer tagging is now always enabled, so we remove the `-Zmiri-tag-raw-pointers` flag and the code for untagged pointers. (Passing the flag still works, for compatibility -- but we just ignore it, with a warning.)

We also fix an intptrcast issue:
- Only live allocations are considered when computing the AllocId from an address.

So, finally, Miri has a good story for ptr2int2ptr roundtrips *and* no weird false negatives when doing raw pointer stuff with Stacked Borrows. :-) 🎉   Thanks a lot to everyone who helped with this, in particular `@carbotaniuman` who convinced me this is even possible.

Fixes https://github.com/rust-lang/miri/issues/2133
Fixes https://github.com/rust-lang/miri/issues/1866
Fixes https://github.com/rust-lang/miri/issues/1993
2022-06-28 01:20:40 +00:00
Ralf Jung
c1eddbc7fe show int2ptr warning once for each span (but don't duplicate the long help) 2022-06-27 20:50:45 -04:00
Ralf Jung
67e89b53e2 fix warning text 2022-06-27 20:04:46 -04:00
Ralf Jung
5719897fb0
improve old comment 2022-06-27 13:38:32 -04:00
Ralf Jung
d9e7a3ae82 typo
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-27 09:08:56 -04:00
Ralf Jung
b479f092a8 avoid unnecessary indirection in miri-track-raw-pointers warning 2022-06-26 23:14:16 -04:00
Ralf Jung
1a5dfbeb7a fmt 2022-06-26 22:36:45 -04:00
Ralf Jung
5c16713056 remove support for untagged pointers
good riddance!
2022-06-26 22:19:56 -04:00
Ralf Jung
294ef15adb more int2ptr cast tests, and fix casting of addresses inside dead allocations 2022-06-26 22:19:56 -04:00
Ralf Jung
13d425daeb make permissive provenance and raw-ptr tagging the default 2022-06-26 21:14:42 -04:00
infrandomness
aa072d72cc Cargo fmt 2022-06-27 01:39:25 +02:00
infrandomness
84a02787d8 Address code review
- Merge pthread_attr_getstack shim to unix/foreign_items.rs
2022-06-27 01:39:24 +02:00
infrandomness
93c61f3905 Add pthread_attr_get_np shim 2022-06-27 01:39:24 +02:00
infrandomness
f2cbd3e2bc Add pthread_attr_getstack shim 2022-06-27 01:39:24 +02:00