Skip to content

Commit a739ff3

Browse files
samitolvanensnitm
authored andcommitted
dm verity: add support for forward error correction
Add support for correcting corrupted blocks using Reed-Solomon. This code uses RS(255, N) interleaved across data and hash blocks. Each error-correcting block covers N bytes evenly distributed across the combined total data, so that each byte is a maximum distance away from the others. This makes it possible to recover from several consecutive corrupted blocks with relatively small space overhead. In addition, using verity hashes to locate erasures nearly doubles the effectiveness of error correction. Being able to detect corrupted blocks also improves performance, because only corrupted blocks need to corrected. For a 2 GiB partition, RS(255, 253) (two parity bytes for each 253-byte block) can correct up to 16 MiB of consecutive corrupted blocks if erasures can be located, and 8 MiB if they cannot, with 16 MiB space overhead. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent bb4d73a commit a739ff3

File tree

7 files changed

+1071
-9
lines changed

7 files changed

+1071
-9
lines changed

Documentation/device-mapper/verity.txt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Construction Parameters
1818

1919
0 is the original format used in the Chromium OS.
2020
The salt is appended when hashing, digests are stored continuously and
21-
the rest of the block is padded with zeros.
21+
the rest of the block is padded with zeroes.
2222

2323
1 is the current format that should be used for new devices.
2424
The salt is prepended when hashing and each digest is
25-
padded with zeros to the power of two.
25+
padded with zeroes to the power of two.
2626

2727
<dev>
2828
This is the device containing data, the integrity of which needs to be
@@ -79,6 +79,32 @@ restart_on_corruption
7979
not compatible with ignore_corruption and requires user space support to
8080
avoid restart loops.
8181

82+
use_fec_from_device <fec_dev>
83+
Use forward error correction (FEC) to recover from corruption if hash
84+
verification fails. Use encoding data from the specified device. This
85+
may be the same device where data and hash blocks reside, in which case
86+
fec_start must be outside data and hash areas.
87+
88+
If the encoding data covers additional metadata, it must be accessible
89+
on the hash device after the hash blocks.
90+
91+
Note: block sizes for data and hash devices must match. Also, if the
92+
verity <dev> is encrypted the <fec_dev> should be too.
93+
94+
fec_roots <num>
95+
Number of generator roots. This equals to the number of parity bytes in
96+
the encoding data. For example, in RS(M, N) encoding, the number of roots
97+
is M-N.
98+
99+
fec_blocks <num>
100+
The number of encoding data blocks on the FEC device. The block size for
101+
the FEC device is <data_block_size>.
102+
103+
fec_start <offset>
104+
This is the offset, in <data_block_size> blocks, from the start of the
105+
FEC device to the beginning of the encoding data.
106+
107+
82108
Theory of operation
83109
===================
84110

@@ -98,6 +124,11 @@ per-block basis. This allows for a lightweight hash computation on first read
98124
into the page cache. Block hashes are stored linearly, aligned to the nearest
99125
block size.
100126

127+
If forward error correction (FEC) support is enabled any recovery of
128+
corrupted data will be verified using the cryptographic hash of the
129+
corresponding data. This is why combining error correction with
130+
integrity checking is essential.
131+
101132
Hash Tree
102133
---------
103134

drivers/md/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,18 @@ config DM_VERITY
467467

468468
If unsure, say N.
469469

470+
config DM_VERITY_FEC
471+
bool "Verity forward error correction support"
472+
depends on DM_VERITY
473+
select REED_SOLOMON
474+
select REED_SOLOMON_DEC8
475+
---help---
476+
Add forward error correction support to dm-verity. This option
477+
makes it possible to use pre-generated error correction data to
478+
recover from corrupted blocks.
479+
480+
If unsure, say N.
481+
470482
config DM_SWITCH
471483
tristate "Switch target support (EXPERIMENTAL)"
472484
depends on BLK_DEV_DM

drivers/md/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ obj-$(CONFIG_DM_LOG_WRITES) += dm-log-writes.o
6464
ifeq ($(CONFIG_DM_UEVENT),y)
6565
dm-mod-objs += dm-uevent.o
6666
endif
67+
68+
ifeq ($(CONFIG_DM_VERITY_FEC),y)
69+
dm-verity-objs += dm-verity-fec.o
70+
endif

0 commit comments

Comments
 (0)