Skip to content

Conversation

@michaliskok
Copy link
Contributor

@michaliskok michaliskok commented Nov 28, 2025

This PR bumps the GenMC version to 0.16.1:

r? @RalfJung
(Each commit includes a description and can be reviewed separately.)

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Nov 28, 2025
Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The last commit mentions issues with memory allocation; what exactly are you referring to?

View changes since this review

@RalfJung
Copy link
Member

Also, please run ./miri fmt to apply our standard formatting to the Rust code.
@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Nov 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Nov 29, 2025
@RalfJung
Copy link
Member

RalfJung commented Nov 29, 2025

The last commit mentions issues with memory allocation; what exactly are you referring to?

Ah, the PR description mentions "Fixes overflowing on large allocations". Is this about a single large allocation, or many allocations accumulating to exhaust the 4GB per-thread limit? How large is "large"? Is it possible to test for that? What happens now when the per-thread 4GB memory region is exhausted?

@michaliskok
Copy link
Contributor Author

The last commit mentions issues with memory allocation; what exactly are you referring to?

Ah, the PR description mentions "Fixes overflowing on large allocations". Is this about a single large allocation, or many allocations accumulating to exhaust the 4GB per-thread limit? How large is "large"? Is it possible to test for that? What happens now when the per-thread 4GB memory region is exhausted?

Each thread can allocate up to 4GB. If the limit is exceeded, the allocator would silently wrap around 0 and handle duplicate addresses. The new commit makes GenMC crash if the limit is exceeded, and doesn't overflow if a size/alignment >2^32 is passed to alloc_aligned.

GenMC has a single API that was handled in a collection of different
files. This commit collects all API wrappers to Exploration.cpp.

(The Setup.cpp file remains intact as it contains setting translation
and setup functions.)
This commit makes the code a bit more compact by using ERROR_ON()
whenever possible. It also renames a particularly verbose variable
used in ERROR's condition.
Use scoped constexprs instead.
These comments explain the default values used internally
in (some) calls of the GenMC library, which is unnecessary.
@michaliskok michaliskok force-pushed the genmc-bug-fixes branch 2 times, most recently from c964074 to 8f8c08e Compare November 29, 2025 10:01
@RalfJung
Copy link
Member

The new commit makes GenMC crash if the limit is exceeded,

That may make it tricky to add a test then, depending on the exit status this will trigger.

@michaliskok
Copy link
Contributor Author

michaliskok commented Nov 29, 2025

The new commit makes GenMC crash if the limit is exceeded,

That may make it tricky to add a test then, depending on the exit status this will trigger.

The alternative would be to return an error code to Miri and let Miri crash.

@RalfJung
Copy link
Member

RalfJung commented Nov 29, 2025

I tried what happened when one thread allocates more than 4GB memory in total (but not at the same time, i.e. we allocate chunks of 512MB and free them again):

./miri run --features=genmc bench-cargo-miri/big-allocs/src/main.rs -Zmiri-genmc

With this PR, that leads to a panic:

thread 'rustc' (123993) panicked at src/concurrency/genmc/mod.rs:597:9:
assertion `left != right` failed: GenMC malloc returned nullptr.

EDIT: I get the same with an 8GB allocation, using this test:

fn main() {
    let _v = Vec::<u8>::with_capacity(8 * 1024 * 1024 * 1024);
}

So, I can't reproduce the GenMC crash.

@RalfJung
Copy link
Member

RalfJung commented Nov 29, 2025

The alternative would be to return an error code to Miri and let Miri crash.

The alternative would be to make Miri emit a nice error saying we ran out of memory for this thread. :)

We don't have to resolve that in this PR, but ideally we'd have some tests before we mark the item in #4572 as resolved.

@RalfJung
Copy link
Member

Here's a little patch to give the user some more explanation for why they may run out of address space in genmc mode:

diff --git a/src/diagnostics.rs b/src/diagnostics.rs
index bb8ba1969..8e252d306 100644
--- a/src/diagnostics.rs
+++ b/src/diagnostics.rs
@@ -362,6 +362,10 @@ pub fn report_result<'tcx>(
                 vec![
                     note!("this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support"),
                 ],
+            ResourceExhaustion(ResourceExhaustionInfo::AddressSpaceFull) if ecx.machine.data_race.as_genmc_ref().is_some() =>
+                vec![
+                    note!("in GenMC mode, the address space is limited to 4GB per thread, and addresses cannot be reused")
+                ],
             UndefinedBehavior(AlignmentCheckFailed { .. })
                 if ecx.machine.check_alignment == AlignmentCheck::Symbolic
             =>

@rustbot

This comment has been minimized.

@michaliskok
Copy link
Contributor Author

I tried what happened when one thread allocates more than 4GB memory in total (but not at the same time, i.e. we allocate chunks of 512MB and free them again):

./miri run --features=genmc bench-cargo-miri/big-allocs/src/main.rs -Zmiri-genmc

With this PR, that leads to a panic:

thread 'rustc' (123993) panicked at src/concurrency/genmc/mod.rs:597:9:
assertion `left != right` failed: GenMC malloc returned nullptr.

EDIT: I get the same with an 8GB allocation, using this test:

fn main() {
    let _v = Vec::<u8>::with_capacity(8 * 1024 * 1024 * 1024);
}

So, I can't reproduce the GenMC crash.

Indeed, sorry about that.

I thought I made GenMC panic in all cases, but that's not the case. For allocations taking place via handleMalloc, GenMC returns nullptr (and potentially an error trace, but error reporting is not hooked up yet anyway). I added a test ensuring that Miri produces an error report if addresses get depleted.

I also incorporated your other comments.

GenMC's handleFree() does return an optional<Error>, so we
may as well use that value.
GenMC can currently allocate up to 4GB per thread. If it cannot
allocated any more memory, it will return nullptr.

This commit adds a test in Miri that ensures we gracefully throw
if this ever happens.
GenMC's allocator can currently only allocate up to 4GB per thread.

Authored-by: Ralf Jung
This version fixes some issues with atomic_{umix,umax} operation
and memory allocation.
@michaliskok
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Nov 29, 2025
@RalfJung
Copy link
Member

Looks great, thanks :)

@RalfJung RalfJung enabled auto-merge November 29, 2025 12:26
@RalfJung RalfJung added this pull request to the merge queue Nov 29, 2025
Merged via the queue into rust-lang:master with commit 0749929 Nov 29, 2025
14 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants