You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/genmc.md
+21-26Lines changed: 21 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
# **(WIP)** Documentation for Miri-GenMC
2
2
3
-
**NOTE: GenMC mode is not yet fully implemented, and has [several correctness issues](https://github.com/rust-lang/miri/issues/4572). Using GenMC mode currently requires manually compiling Miri, see [Usage](#usage).**
4
-
3
+
**NOTE: GenMC mode is not yet fully implemented, and has [several correctness issues](https://github.com/rust-lang/miri/issues/4572) and [other limitations](#limitations). Using GenMC mode currently requires manually compiling Miri, see [Usage](#usage).**
5
4
6
5
[GenMC](https://github.com/MPI-SWS/genmc) is a stateless model checker for exploring concurrent executions of a program.
7
6
Miri-GenMC integrates that model checker into Miri.
@@ -12,11 +11,14 @@ This includes all possible thread interleavings and all allowed return values fo
12
11
It is hence still possible to have latent bugs in a test case even if they passed GenMC.)
13
12
14
13
GenMC requires the input program to be bounded, i.e., have finitely many possible executions, otherwise it will not terminate.
15
-
Any loops that may run infinitely must be replaced or bounded (see below).
14
+
Any loops that may run infinitely must be replaced or bounded (see [below](#eliminating-unbounded-loops)).
16
15
17
16
GenMC makes use of Dynamic Partial Order Reduction (DPOR) to reduce the number of executions that must be explored, but the runtime can still be super-exponential in the size of the input program (number of threads and amount of interaction between threads).
18
17
Large programs may not be verifiable in a reasonable amount of time.
19
18
19
+
GenMC currently only supports Linux hosts.
20
+
Both the host and the target must be 64-bit little-endian.
21
+
20
22
## Usage
21
23
22
24
For testing/developing Miri-GenMC:
@@ -50,16 +52,24 @@ Note that `cargo miri test` in GenMC mode is currently not supported.
50
52
-`debug2`: Print the execution graph after every memory access.
51
53
-`debug3`: Print reads-from values considered by GenMC.
52
54
-`-Zmiri-genmc-verbose`: Show more information, such as estimated number of executions, and time taken for verification.
53
-
54
-
#### Regular Miri parameters useful for GenMC mode
55
-
56
55
-`-Zmiri-disable-weak-memory-emulation`: Disable any weak memory effects (effectively upgrading all atomic orderings in the program to `SeqCst`). This option may reduce the number of explored program executions, but any bugs related to weak memory effects will be missed. This option can help determine if an error is caused by weak memory effects (i.e., if it disappears with this option enabled).
57
56
58
57
<!-- FIXME(genmc): explain Miri-GenMC specific functions. -->
59
58
60
-
## Tips
59
+
## Limitations
60
+
61
+
There are several limitations which can make GenMC miss bugs:
62
+
- GenMC does not support re-using freed memory for new allocations, so any bugs related to that will be missed.
63
+
- GenMC does not support `compare_exchange_weak`, so the consequences of spurious failures are not explored.
64
+
A warning will be emitted if this affects code you wrote (but not if it happens inside your dependencies).
65
+
- GenMC does not support the separate failure ordering of `compare_exchange`. Miri will take the maximum of the success and failure ordering and use that for the access; outcomes that rely on the real ordering being weaker will not be explored.
66
+
A warning will be emitted if this affects code you wrote (but not if it happens inside your dependencies).
67
+
- GenMC is incompatible with borrow tracking (Stacked/Tree Borrows). You need to set `-Zmiri-disable-stacked-borrows` to use GenMC.
68
+
- Like all C++ memory model verification tools, GenMC has to solve the [out-of-thin-air problem](https://www.cl.cam.ac.uk/~pes20/cpp/notes42.html).
69
+
It takes the [usual approach](https://plv.mpi-sws.org/scfix/paper.pdf) of requiring the union of "program-order" and "reads-from" to be acyclic.
70
+
This means it excludes certain behaviors allowed by the C++ memory model, some of which can occur on hardware that performs load buffering.
61
71
62
-
<!-- FIXME(genmc): add tips for using Miri-GenMC more efficiently. -->
GenMC is written in C++, which complicates development a bit.
138
137
The prerequisites for building Miri-GenMC are:
139
-
- A compiler with C++23 support.
140
-
- LLVM developments headers and clang.
141
-
<!-- FIXME(genmc,llvm): remove once LLVM dependency is no longer required. -->
138
+
- A compiler with sufficient C++20 support (we are testing GCC 13).
142
139
143
140
The actual code for GenMC is not contained in the Miri repo itself, but in a [separate GenMC repo](https://github.com/MPI-SWS/genmc) (with its own maintainers).
144
141
These sources need to be available to build Miri-GenMC.
@@ -149,6 +146,8 @@ The process for obtaining them is as follows:
149
146
If you place this directory inside the Miri folder, it is recommended to call it `genmc-src` as that tells `./miri fmt` to avoid
150
147
formatting the Rust files inside that folder.
151
148
149
+
<!-- FIXME(genmc): explain how submitting code to GenMC should be handled. -->
150
+
152
151
### Formatting the C++ code
153
152
154
153
For formatting the C++ code we provide a `.clang-format` file in the `genmc-sys` directory.
@@ -157,7 +156,3 @@ With `clang-format` installed, run this command to format the c++ files (replace
warning: GenMC currently does not model the failure ordering for `compare_exchange`. Due to success ordering 'Acquire', the failure ordering 'Relaxed' is treated like 'Acquire'. Miri with GenMC might miss bugs related to this memory access.
warning: GenMC currently does not model the failure ordering for `compare_exchange`. Due to success ordering 'SeqCst', the failure ordering 'Relaxed' is treated like 'SeqCst'. Miri with GenMC might miss bugs related to this memory access.
3
+
--> tests/genmc/pass/atomics/cas_simple.rs:LL:CC
4
+
|
5
+
LL | let _ = VALUE.compare_exchange(99, 99, SeqCst, Relaxed);
6
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GenMC might miss possible behaviors of this code
7
+
8
+
warning: GenMC currently does not model the failure ordering for `compare_exchange`. Success ordering 'Relaxed' was upgraded to 'SeqCst' to match failure ordering 'SeqCst'. Miri with GenMC might miss bugs related to this memory access.
9
+
--> tests/genmc/pass/atomics/cas_simple.rs:LL:CC
10
+
|
11
+
LL | let _ = VALUE.compare_exchange_weak(99, 99, Relaxed, SeqCst);
12
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GenMC might miss possible behaviors of this code
13
+
14
+
warning: GenMC currently does not model spurious failures of `compare_exchange_weak`. Miri with GenMC might miss bugs related to spurious failures.
15
+
--> tests/genmc/pass/atomics/cas_simple.rs:LL:CC
16
+
|
17
+
LL | let _ = VALUE.compare_exchange_weak(99, 99, Relaxed, SeqCst);
18
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GenMC might miss possible behaviors of this code
19
+
2
20
Verification complete with 1 executions. No errors found.
0 commit comments