Definition
Deterministic invocation state is the property that every run of a guest program starts from the same defined state, whatever earlier runs did. A guest program is code that a host runs inside a virtual machine §2.3 (VM); one run is an invocation. This state covers the registers, stack, scratch memory §2.24, instruction budget §2.32, the position of the first instruction, and the host’s status and result storage. A run’s outcome then depends only on its declared inputs: the event’s data, state kept on purpose between runs, and host function results.
The idea
A host keeps one VM object and runs the same eBPF §2.1 (extended Berkeley Packet Filter) filter program on every received message. The program counts suspicious bytes in register R6 and rejects a message that has more than 2. It never sets R6 to 0 itself, because this runtime promised that every register other than the input register R1 and the stack register R10 starts at 0. Message A contains 3 suspicious bytes and is rejected, which leaves 3 in R6. If the runtime does not clear R6 before the next run, message B, with 1 suspicious byte, ends with and is rejected too. A fresh VM would have counted 1 and allowed B. The same program and the same message gave different answers because of something the message did not contain.
The remedy is a contract about what a run can observe at its start, kept by the host on every run: each run behaves like the first run on a freshly built VM with the same inputs. Fresh does not require every byte to be zero; a runtime may instead track which registers and bytes the current run has written and refuse reads of the others. What matters is that nothing an earlier run wrote is readable by accident. State that must survive between runs, such as a counter in a BPF map §2.18, a key-value table the host owns, is a separate, deliberate input, described in the Guest persistent state §2.36 entry.
How it works
Define the starting state once, as a list, and have the host establish every item before every run.
Position. The program counter §2.9, the position of the next instruction, is set to the program’s entry point.
Registers. The input registers receive this run’s inputs: in eBPF, R1 holds the address of the guest context §2.23, the block of memory that describes the event, and R10 holds the address of the stack. Every other register is either set to a fixed value, such as 0, or marked unreadable until written. The eBPF verifier §3.3 in Linux takes the second approach: it rejects, when the program is loaded, any program that can read a register before writing it.
Stack and scratch memory. The guest’s stack and its scratch memory, a temporary area lent for one run, are cleared, or their unwritten bytes are made unreadable.
Budget. The instruction budget is set to its full amount, not to whatever an earlier run left.
Status and result. The host’s status and result storage are set to no result yet, so that a failed run cannot leave an earlier run’s answer in place.
After the run, the host turns the status and the value into a decision through its fault-to-verdict mapping §2.34 and releases whatever it lent to the run, such as references to buffers whose lifetime ends with the event. Only then may the VM object serve the next run, which begins again at item 1.
The outcome is then a function of the declared inputs: the program, the event’s context, the contents of every map the program reads, and every value returned by a helper function §2.19, a host function the guest may call. Some helpers return changing values, such as the time or random numbers. With them, two runs on the same event can legitimately differ, and the claim becomes: the same program, context, map contents and helper results give the same outcome.
Worked example
Take a runtime that promises, before every run, a cleared 4-byte scratch area, a budget of 100 units and result storage set to no result yet. Run A writes the value 9 into scratch byte 3, uses all 100 units and returns allow, stored as the result 1. Consider the next run, B, under three hosts, each reusing one VM object.
Host 1 resets everything. B’s first read of the scratch area gives the bytes
00 00 00 00, B has 100 units, and the result storage holds no result yet. B behaves exactly as on a fresh VM.Host 2 forgets the scratch area. B reads
00 00 00 09. If B’s logic treats a nonzero byte 3 as a flag it set earlier in the same run, it takes a branch that its own input never caused.Host 3 forgets the budget and the result. B starts with 0 units, so its first instruction stops it with the status budget exhausted, while the result storage still holds A’s 1. A host that reads the result without checking the status allows B. A host that checks the status rejects B, and rejects every later event too, since no run ever receives units again.
The declared inputs decide what deterministic means. A rule that alerts when a temperature reading is above 30 gives the same answer, no alert, for the reading 28 on every run, because 28 is not greater than 30. Add a second clause that alerts for any reading taken between 02:00 and 04:00, which needs a clock helper, and the time becomes an input: the reading 28 gives no alert at 01:59 and an alert at 02:00. Both runs are deterministic functions of their full inputs; they differ only because the clock is one of those inputs.
Stated precisely
Write the starting state of a run as : the program counter , the register values , the stack contents , the scratch contents , the budget and the result storage . The host keeps the contract when every run starts with , where is this run’s context and is a fixed function that reads nothing an earlier run wrote. Let the outcome of a run be its status, its returned value, its writes to maps and the helper calls it made. Then two runs of the same program with the same context , the same map contents at the start and the same sequence of helper results have the same outcome.
The statement depends on four assumptions.
Complete initialization: covers every location the guest can read before writing it. Where a location is marked unreadable instead of cleared, every path that reads guest state enforces the mark.
A deterministic VM: the interpreter §2.13 itself has no undefined behavior §4.12 and reads no uninitialized host memory. If the guest can read the numeric value of an address it receives, such as the stack address in R10, that address is the same on every run or counts as an input.
No concurrent writers: nothing else changes the maps the run reads while the run is in progress, or the inputs are taken to be the values the run actually read.
Complete inputs: every helper result that can differ between runs is counted among the inputs.
Cached VM instances
A cached VM is a VM object that the host prepares once and reuses for many runs, instead of building a new one for every event. Preparation includes checking the bytecode §2.4, by structural bytecode admission §2.26 and any verifier; decoding it into a form the interpreter runs quickly, or compiling it into machine code; allocating its stack and scratch memory; and resolving its references to maps and helpers. A cached VM moves all of that off the path that every event takes: each event pays only for setting the starting state, running the guest and mapping the result. For a short program the preparation can cost far more than the run itself.
A long-lived instance adds three risks.
Stale state. Allocating the object once avoids allocation work on every event, but nothing resets itself between runs: every item of the starting state must be reset on every run, as the three hosts in the worked example show.
Concurrency §9.1. If two threads, or a thread and an interrupt handler §6.12, run the same instance at the same time, both write the same registers, stack and status, and the results mix. Each concurrent caller needs its own run state, for example one per thread or per processor; otherwise the calls must be serialized with a lock, or a second entry while a run is in progress must be refused. The Reentrancy §9.27 entry describes the general problem.
Replacement. When a new version of the program is installed, the cached instance must be replaced as a whole by one prepared from the new program, at a moment when no run is using the old one, and nothing derived from the old program, such as its decoded instructions or its map references, may stay in use.
Limits and common mistakes
Clearing the VM’s own state does not clear state the host keeps elsewhere. Maps, buffers inside helpers and counters inside helpers survive, by design or by mistake; each must be listed as either kept or reset.
Deterministic does not mean correct or secret. A program that gives the same wrong answer every time is deterministic. If leftover bytes came from a run on behalf of another user or another program, reading them also leaks that run’s data.
Resetting too much is also a bug. State the policy needs between runs, such as a rate counter, must be kept; a reset that clears it silently changes the policy.
Determinism of each run does not by itself make a sequence of runs reproducible. Replaying recorded events reproduces the outcomes only if the replay also restores the map contents and supplies the same helper results in the same order, which is what deterministic replay §10.37 does.
Questions answered
Which persistent state §8.1 is intentionally retained outside the VM?
Only state that the design deliberately lists as surviving from one run of the guest program to the next is retained, and the host keeps it outside the virtual machine’s per-run state. A guest program is code that a host runs inside a virtual machine (VM); its per-run state is the registers, the stack, the scratch memory, the instruction budget and the result storage, all reset before every run. In a runtime of the eBPF (extended Berkeley Packet Filter) kind, the deliberately retained state is typically the following.
The loaded program and the work done to prepare it: its checked, decoded or compiled form and its table of host functions.
Maps, the key-value tables the host owns, holding data the policy needs across events, such as counters, rate-limit records or configuration. Linux also keeps a program’s global variables in maps.
Host state that helper functions read, such as clocks, random number generators and device status, which reaches the guest only through helper results.
For each retained object the design must state its owner, which runs may read and write it, when it is created and cleared, and how concurrent runs share it. Nothing outside that list may carry over, above all not leftover register, stack, scratch, budget or result values; if it does, that is a bug, not retained state.
Related entries: Scratch memory (§2.24), Guest persistent state (§2.36), Concrete state (§3.5), Fault-to-verdict mapping (§2.34), Instruction budget (fuel) (§2.32), Reentrancy (§9.27), Deterministic replay (§10.37).