-
Notifications
You must be signed in to change notification settings - Fork 470
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
Question (epoch): How to avoid Miri to report data race on an Atomic
pointer?
#993
Comments
What platform did you run the test? (I'm thinking about #992) |
macOS arm64 $ rustc +nightly -Vv
rustc 1.72.0-nightly (6bba06146 2023-06-16)
binary: rustc
commit-hash: 6bba061467f7c2cab04b262b95eb67bf89265587
commit-date: 2023-06-16
host: aarch64-apple-darwin
release: 1.72.0-nightly
LLVM version: 16.0.5 |
Thanks. Yeah. It seems #992 is related. I tried the following dependency and the error has changed. crossbeam-epoch = { git = "https://github.com/crossbeam-rs/crossbeam.git", branch = "taiki-e/consume" } So, Miri does not seem to understand Now it is detecting a stacked borrow violation... error: Undefined Behavior: trying to retag from <221231> for SharedReadWrite permission at alloc96329[0x8], but that tag does not exist in the borrow stack for this location
--> /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/internal.rs:552:9
|
552 | &*local_ptr
| ^^^^^^^^^^^
| |
| trying to retag from <221231> for SharedReadWrite permission at alloc96329[0x8], but that tag does not exist in the borrow stack for this location
| this error occurs as part of retag at alloc96329[0x0..0xb8]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows 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: <221231> was created by a SharedReadWrite retag at offsets [0x0..0x8]
--> src/bin/main1.rs:64:21
|
64 | let guard = pin();
| ^^^^^
= note: BACKTRACE (of the first span):
= note: inside `<crossbeam_epoch::internal::Local as crossbeam_epoch::sync::list::IsElement<crossbeam_epoch::internal::Local>>::element_of` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/internal.rs:552:9: 552:20
= note: inside `<crossbeam_epoch::sync::list::Iter<'_, crossbeam_epoch::internal::Local, crossbeam_epoch::internal::Local> as std::iter::Iterator>::next` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/sync/list.rs:290:37: 290:53
= note: inside `crossbeam_epoch::internal::Global::try_advance` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/internal.rs:237:22: 237:45
= note: inside `crossbeam_epoch::internal::Global::collect` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/internal.rs:202:28: 202:51
= note: inside `crossbeam_epoch::internal::Local::pin` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/internal.rs:436:17: 436:46
= note: inside `crossbeam_epoch::LocalHandle::pin` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/collector.rs:81:18: 81:37
= note: inside closure at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/default.rs:40:26: 40:38
= note: inside closure at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/default.rs:60:23: 60:27
= note: inside `std::thread::LocalKey::<crossbeam_epoch::LocalHandle>::try_with::<[closure@crossbeam_epoch::default::with_handle<[closure@crossbeam_epoch::pin::{closure#0}], crossbeam_epoch::Guard>::{closure#0}], crossbeam_epoch::Guard>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:270:16: 270:31
= note: inside `crossbeam_epoch::default::with_handle::<[closure@crossbeam_epoch::pin::{closure#0}], crossbeam_epoch::Guard>` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/default.rs:59:5: 60:28
= note: inside `crossbeam_epoch::pin` at /Users/tatsuya/.cargo/git/checkouts/crossbeam-5d5b005504a37dac/39da3f8/crossbeam-epoch/src/default.rs:40:5: 40:39
note: inside `tests::read_and_maybe_replace`
--> src/bin/main1.rs:64:21
|
64 | let guard = pin();
| ^^^^^ |
SB errors from epoch should be fixed in #871. |
Wow! That was super quick. Thank you so much! I tried $ rustc +nightly -Vv
rustc 1.72.0-nightly (6bba06146 2023-06-16)
binary: rustc
commit-hash: 6bba061467f7c2cab04b262b95eb67bf89265587
commit-date: 2023-06-16
host: aarch64-apple-darwin
release: 1.72.0-nightly
LLVM version: 16.0.5
$ cargo +nightly miri test --bin main1
Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done
WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping.
Finished test [unoptimized + debuginfo] target(s) in 0.04s
Running unittests src/bin/main1.rs (target/miri/aarch64-apple-darwin/debug/deps/main1-5aa366f684d43212)
running 1 test
test tests::concurrent_read_and_modify ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out |
p.s. I ran
crossbeam-epoch = { git = "https://github.com/crossbeam-rs/crossbeam.git", branch = "master", optional = true } Terminal Log $ cargo tree -i crossbeam-epoch
crossbeam-epoch v0.9.15 (https://github.com/crossbeam-rs/crossbeam.git?branch=master#ce31c186)
└── moka v0.11.2 (...)
$ MIRIFLAGS="-Zmiri-tree-borrows" cargo +nightly miri test --lib cht::segment::tests::concurrent_overlapped_removal
Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done
WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping.
Finished test [unoptimized + debuginfo] target(s) in 0.08s
Running unittests src/lib.rs (target/miri/aarch64-apple-darwin/debug/deps/moka-451ea5dfd08c9c07)
running 1 test
test cht::segment::tests::concurrent_overlapped_removal ... ^C
## Pressed Ctrl + C after ~1 minute. Otherwise it can take few hours to complete. |
Hi. Some time ago, we implemented a lock-free concurrent hash table using
crossbeam-epoch
and it has been working fine. However, a user of our hash table library discovered that runningcargo +nightly miri test
on it reports a data race error during concurrent read/write on acrossbeam_epoch::Atomic
pointer.Since it is a lock-free data structure, we expect such a data race to occur. Readers may see stale data, which is okay, and reading the data will never cause use-after-free problem because the data is retained by
crossbeam_epoch
'sGuard
.However, Miri's error raised some questions:
Atomic
pointer andGuard
correctly?Below is a minimized version of the code that causes the same Miri error:
src/bin/main1.rs
Here is the result:
Miri test
I replaced
v_ref: &usize
with*const usize
, but Miri reported the same error on the linelet _ = unsafe { *v_raw.ptr }
of oursrc/bin/main2.rs
diff
Versions:
crossbeam-epoch
v0.9.15The text was updated successfully, but these errors were encountered: