Skip to content

Check Metal with formal models ​

Metal has three PlusCal models in metal/formal/. TLC, the TLA+ model checker, runs every order of steps that the model allows, with crashes and lost replies, and reports the shortest path to a broken rule. A test runs only the orders that it names.

A model is a small copy of the design, not of the code. Each label in a model is one step that other goroutines or hosts can interleave: one lock, one record write, or one Firecracker call. A comment on each label names the Go function.

What does each model check? ​

ModelIt checksCode
HostMemoryWakes, Atlas creates and incoming migrations never use more host memory than the host has. A wake keeps its reservation until host capacity counts the VM.internal/vm/wake_admission.go, internal/vm/reconcile.go, internal/host/service.go
VirtualMachineLifecycleEvery VM action, with crashes and failed restores: a memory snapshot resumes only over the disk version it was captured with, and the VM reaches its desired state.internal/vm/reconcile.go, internal/vm/sleep_state.go, internal/firecracker/machine.go
MigrationLivenessA migration always ends, the VM then runs on one host, two hosts never run the guest, and rollback never drops guest writes.internal/vm/migration/

The memory snapshot rule comes from the guest disk corruption incident.

A pass holds only for the bounds in each .cfg file, such as 3 VMs or 4 failures. The models leave out network setup, disk transfer bytes, and Atlas placement.

State charts ​

tlc.py docs generates these charts from the models. An edge names the model labels that make the change. Act is an Atlas, traffic or transfer action. Pass is the first step of a reconcile pass.

The VM lifecycle, by sleep state and guest:

State diagram
Loading diagram...

A migration, by destination checkpoint:

State diagram
Loading diagram...

Run the checks ​

Run them from metal/. The script needs Python 3 and Java 11 or later. It downloads the pinned tla2tools.jar once and checks its SHA-256.

sh
python3 formal/tlc.py check --quick       # what CI runs, about 10 seconds
python3 formal/tlc.py check               # adds the slow *Full.cfg configs, several minutes
python3 formal/tlc.py check HostMemory    # one model

Set TLA2TOOLS to use a local jar. Output goes to metal/formal/.tmp/, which Git ignores.

A failure prints the broken rule and the actions of the shortest trace, for example Trace: Initial -> AdmitWake -> RestoreSavedState -> WriteAwake. Follow the trace in the code one action at a time. Then decide whether the code or the model is wrong.

Draw a state chart ​

sh
python3 formal/tlc.py chart MigrationLiveness --view destination

After you change a model, run python3 formal/tlc.py docs to rebuild the charts on this page. CI runs docs --check and fails on a stale chart.

The command prints each transition as text. It also writes chart.dot, and chart.svg when Graphviz is installed, under metal/formal/.tmp/<config>/. Choose --view variables that give at most 40 chart states, and use a small config.

Change a model ​

Change the model before you change the code that it covers. Then:

  1. Run python3 formal/tlc.py check and make every config pass.
  2. Break the rule on purpose, for example remove a lock or reorder two writes, and confirm that TLC finds it. A model that passes with the bug is too coarse.
  3. Add a Go test that fails without the code change.

A pull request that changes a .tla or .cfg file gets the formal-model label. A code owner of metal/formal/ in .github/CODEOWNERS must approve it.

Do not weaken a rule to make a model pass. Add a rule with INVARIANT for safety or PROPERTY for liveness in each config of the model.

Source code

AGPL-3.0