# dm-era: a writeset cache must follow its input

This synthetic model illustrates the defect described in Linux commit
2524933307fd0036d5c32357c693c021ab09a0b0. It is not kernel execution,
a block-device test, an era_invalidate implementation or a restore experiment.

Run with Node.js: `node --test model.test.mjs`.

For four tracked blocks, era 7 writes block 0 and era 8 writes block 1.
Resetting the one-word cache for each archived writeset yields last-era values
[7, 8, 0, 0]. Retaining the first word yields [8, 0, 0, 0]: block 1's change is
missed while block 0 is incorrectly assigned to the newer era. Zero means no
write represented in this constructed history, not a disk-content value.

The independent direct-bit oracle covers all 256 ordered pairs of four-bit
masks; stale-cache behavior differs for 240 pairs. This is an exhaustive count
for a toy input space, not a failure probability. Boundary tests cover 64/65
blocks, input rejection, empty histories and the uint32 upper endpoint.

Assumptions: equal-sized writesets, ascending positive era labels, complete
sequential digestion, at most 256 blocks and 256 writesets, no counter wrap,
no concurrent insertion, resizing, I/O errors or partial metadata commits.
The fixed model reloads at each writeset. The old model reloads only when the
64-bit word index changes. Neither stores or copies payload bytes.

Sources:
- https://github.com/torvalds/linux/commit/2524933307fd0036d5c32357c693c021ab09a0b0
- https://github.com/torvalds/linux/blob/adc218676eef25575469234709c2d87185ca223a/drivers/md/dm-era-target.c
- https://www.kernel.org/doc/html/v6.12/admin-guide/device-mapper/era.html

The correction already exists upstream and in the reviewed v6.12 source.
No claim about installed distribution kernels or vulnerability prevalence.
