Skip to content

Conversation

Patrick-6
Copy link
Contributor

Followup to #4566 and #4506.

This PR adds support for using compare_exchange{_weak} for GenMC mode, and adds code to emit warnings in cases where bugs may be missed. This includes the missing support for spurious failures for the weak variant, and missing modelling for the failure memory ordering leading to certain executions that cannot be explored.

This PR also adds tests compare_exchange.

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Sep 11, 2025
@Patrick-6
Copy link
Contributor Author

Patrick-6 commented Sep 11, 2025

r? @RalfJung

I have more tests that use compare_exchange, but they require supporting provenance, which needs a change on the GenMC side first.

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! This is a much more manageable size. :)

View changes since this review

Comment on lines 389 to 394
warnings_cache.warn_once_rmw_failure_ordering(
ecx,
success,
upgraded_success_ordering,
fail,
);
Copy link
Member

Choose a reason for hiding this comment

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

Please have the logic that decides whether we will warn here, instead of splitting it across files.

I don't think you need an entire file for this, all you need is something like

type WarningCache = RwLock<FxHashSet<Span>>;

fn emit_warning(cache: &WarningCache, diagnostic: impl FnOnce() -> NonHaltingDiagnostic) { ... }


// Translated from GenMC's test `wrong/racy/MPU2+rels+rlx`.
// Test if Miri with GenMC can detect the data race on `X`.
// The data race only occurs if thread 1 finishes, then threads 3 and 4 run, then thread 1.
Copy link
Member

Choose a reason for hiding this comment

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

One of the 1 here should be a 2 I assume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, one at the end.

Copy link
Member

Choose a reason for hiding this comment

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

What is this test about? Please at least link to the corresponding GenMC test.

Same for ccr and cii.

Also, none of the actually concurrent tests are checking the values we are seeing, would one of them be suited for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add result printing to the MPU2_rels_acqf test.

Y.store(1, Relaxed);
});
spawn_pthread_closure(|| {
let expected = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Please inline these trivial let-bindings that are only used once (in all tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah these are some leftovers from C/C++, where the compare_exchange functions take a pointer/reference, so they can update the expected value ^^

@Patrick-6
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 Sep 12, 2025
@Patrick-6 Patrick-6 marked this pull request as ready for review September 12, 2025 07:16
@Patrick-6
Copy link
Contributor Author

Patrick-6 commented Sep 12, 2025

That CI failure doesn't look like it is caused by my change?

@RalfJung
Copy link
Member

Yeah, the Ubuntu repos are having some sort of trouble.

@RalfJung
Copy link
Member

Please rebase, that should fix the CI.

@RalfJung
Copy link
Member

Oh and you can also squash the commits, this is ready otherwise. :)

- Handling Compare-Exchange operations.
  - Limitation: Compare-Exchange currently ignores possibility of spurious failures.
  - Limitation: Compare-Exchange failure memory ordering is ignored.
    - Upgrade compare-exchange success ordering to avoid reporting non-existent bugs.
- Add warnings for GenMC mode for unsupported features.
- Add a lot of tests, including translation of GenMC litmus tests and Loom tests.
- Cleanup
@rustbot
Copy link
Collaborator

rustbot commented Sep 12, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung RalfJung enabled auto-merge September 12, 2025 15:43
@RalfJung RalfJung added this pull request to the merge queue Sep 12, 2025
Merged via the queue into rust-lang:master with commit e7da309 Sep 12, 2025
12 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Sep 12, 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