Skip to content
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

cannon: Implement thread-safe ll and sc operations #11906

Merged

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Sep 13, 2024

Description

Modify the behavior of load linked word (ll) and store conditional word (sc) operations in MTCannon. These opcodes provide the primitives used to implement atomic read-modify-write (RMW) operations. Because MTCannon can context-switch between the ll and sc calls, we need track whether the memory location reserved via the ll call is modified before sc is called.

This PR adds several new global fields to the MT State to track the memory location reserved via ll. Only a single memory reservation can be active at a given time - a new reservation will clear any previous reservation. If the reserved memory location is modified, the memory reservation is cleared. When an sc operation is executed, it will now only succeed if the memory reservation is intact, otherwise sc returns a 0 for failure.

Tests

Added additional differential tests to check ll and sc behavior. Ran the new ll/sc tests against develop to validate that the behavior is unchanged for the single-threaded implementation. Also added tests to validate that the memory reservation is cleared as expected when memory is modified.

Metadata

Fixes #11757

Copy link

codecov bot commented Sep 13, 2024

Codecov Report

Attention: Patch coverage is 84.52381% with 26 lines in your changes missing coverage. Please review.

Project coverage is 79.42%. Comparing base (c8d6dbb) to head (4666ffc).
Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
cannon/mipsevm/multithreaded/state.go 47.05% 12 Missing and 6 partials ⚠️
cannon/mipsevm/multithreaded/mips.go 91.66% 4 Missing and 1 partial ⚠️
cannon/mipsevm/singlethreaded/mips.go 92.30% 1 Missing and 1 partial ⚠️
...non/mipsevm/multithreaded/testutil/expectations.go 93.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #11906      +/-   ##
===========================================
- Coverage    79.52%   79.42%   -0.10%     
===========================================
  Files           41       41              
  Lines         3287     3412     +125     
===========================================
+ Hits          2614     2710      +96     
- Misses         511      532      +21     
- Partials       162      170       +8     
Flag Coverage Δ
cannon-go-tests 79.42% <84.52%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cannon/mipsevm/exec/mips_instructions.go 97.89% <100.00%> (+0.03%) ⬆️
cannon/mipsevm/exec/mips_syscalls.go 93.75% <100.00%> (+0.08%) ⬆️
cannon/mipsevm/multithreaded/testutil/mutators.go 71.42% <100.00%> (-5.32%) ⬇️
...non/mipsevm/multithreaded/testutil/expectations.go 97.22% <93.33%> (+0.12%) ⬆️
cannon/mipsevm/singlethreaded/mips.go 93.24% <92.30%> (-0.76%) ⬇️
cannon/mipsevm/multithreaded/mips.go 95.67% <91.66%> (-0.80%) ⬇️
cannon/mipsevm/multithreaded/state.go 53.67% <47.05%> (-2.78%) ⬇️

Copy link
Contributor

@Inphi Inphi left a comment

Choose a reason for hiding this comment

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

The ll/sc changes to MIPS.sol looks good to me. We should be doubly sure we're not introducing any new behavior to that contract. So it'll be good to differentially fuzz both singlethreaded VMs for ll/sc to confirm that we're not introducing new behavior.

One way to do this is to save the bytecode of the current MIPS.sol implementation in develop. And write a test that differentially fuzzes ll/sc inputs on that old bytecode against the new singlethreaded Go VM.

cannon/mipsevm/multithreaded/mips.go Show resolved Hide resolved
cannon/mipsevm/testutil/mips.go Outdated Show resolved Hide resolved
@mbaxter mbaxter force-pushed the issue-11757/implement-rmw-flow branch from ba4245c to 5de7fe9 Compare September 13, 2024 21:47
@mbaxter
Copy link
Contributor Author

mbaxter commented Sep 16, 2024

We should be doubly sure we're not introducing any new behavior

To double-check, I ran the new ll/sc tests against develop - they are passing there without the restructuring introduced in this PR.

@mbaxter mbaxter marked this pull request as ready for review September 16, 2024 15:52
@mbaxter mbaxter requested review from a team as code owners September 16, 2024 15:52
@mbaxter mbaxter requested review from mds1, ajsutton and Inphi and removed request for ajsutton and mds1 September 16, 2024 15:52
Copy link
Contributor

@Inphi Inphi left a comment

Choose a reason for hiding this comment

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

LGTM!

cannon/mipsevm/tests/evm_multithreaded_test.go Outdated Show resolved Hide resolved
@mbaxter mbaxter added this pull request to the merge queue Sep 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 16, 2024
@mbaxter mbaxter added this pull request to the merge queue Sep 16, 2024
Merged via the queue into ethereum-optimism:develop with commit 4af1fe6 Sep 16, 2024
59 checks passed
@mbaxter mbaxter deleted the issue-11757/implement-rmw-flow branch September 16, 2024 18:37
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.

Correctly emulate ll and sc instructions
2 participants