Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dm-verity-fec: rename "RS block" to "RS codeword"

The literature refers to the unit of a Reed-Solomon (RS) code as either
a "block" or a "codeword".

dm-verity's source code uses "RS block". Unfortunately, that's really
confusing because "block" already means something else in dm-verity.
Especially problematic is the fact that dm-verity sometimes uses "RS
block" to mean an RS codeword and sometimes to mean some dm-verity block
that's related to the RS decoding process, for example one of the blocks
that shares its RS codewords with the target block.

Let's use "RS codeword" instead, or "RS message" when referring to just
the message part of the codeword. Update some comments, function names,
macro names, and variable names accordingly. No functional change.

There are still some remaining comments where "RS block" refers to a
dm-verity block. Later commits will handle these cases.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

authored by

Eric Biggers and committed by
Mikulas Patocka
9b6098ad f34ebde1

+35 -33
+30 -28
drivers/md/dm-verity-fec.c
··· 11 11 #define DM_MSG_PREFIX "verity-fec" 12 12 13 13 /* 14 - * When correcting a data block, the FEC code performs optimally when it can 15 - * collect all the associated RS blocks at the same time. As each byte is part 16 - * of a different RS block, there are '1 << data_dev_block_bits' RS blocks. 17 - * There are '1 << DM_VERITY_FEC_BUF_RS_BITS' RS blocks per buffer, so that 18 - * gives '1 << (data_dev_block_bits - DM_VERITY_FEC_BUF_RS_BITS)' buffers. 14 + * When correcting a block, the FEC implementation performs optimally when it 15 + * can collect all the associated RS codewords at the same time. As each byte 16 + * is part of a different codeword, there are '1 << data_dev_block_bits' 17 + * codewords. Each buffer has space for the message bytes for 18 + * '1 << DM_VERITY_FEC_BUF_RS_BITS' codewords, so that gives 19 + * '1 << (data_dev_block_bits - DM_VERITY_FEC_BUF_RS_BITS)' buffers. 19 20 */ 20 21 static inline unsigned int fec_max_nbufs(struct dm_verity *v) 21 22 { ··· 38 37 #define fec_for_each_buffer(io, __i) \ 39 38 for (__i = 0; __i < (io)->nbufs; __i++) 40 39 41 - /* Loop over each RS block in each allocated buffer. */ 42 - #define fec_for_each_buffer_rs_block(io, __i, __j) \ 40 + /* Loop over each RS message in each allocated buffer. */ 41 + /* To stop early, use 'goto', not 'break' (since this uses nested loops). */ 42 + #define fec_for_each_buffer_rs_message(io, __i, __j) \ 43 43 fec_for_each_buffer(io, __i) \ 44 44 for (__j = 0; __j < 1 << DM_VERITY_FEC_BUF_RS_BITS; __j++) 45 45 46 46 /* 47 - * Return a pointer to the current RS block when called inside 48 - * fec_for_each_buffer_rs_block. 47 + * Return a pointer to the current RS message when called inside 48 + * fec_for_each_buffer_rs_message. 49 49 */ 50 - static inline u8 *fec_buffer_rs_block(struct dm_verity *v, 51 - struct dm_verity_fec_io *fio, 52 - unsigned int i, unsigned int j) 50 + static inline u8 *fec_buffer_rs_message(struct dm_verity *v, 51 + struct dm_verity_fec_io *fio, 52 + unsigned int i, unsigned int j) 53 53 { 54 54 return &fio->bufs[i][j * v->fec->rs_k]; 55 55 } 56 56 57 57 /* 58 - * Return an index to the current RS block when called inside 59 - * fec_for_each_buffer_rs_block. 58 + * Return the index of the current RS message when called inside 59 + * fec_for_each_buffer_rs_message. 60 60 */ 61 61 static inline unsigned int fec_buffer_rs_index(unsigned int i, unsigned int j) 62 62 { ··· 65 63 } 66 64 67 65 /* 68 - * Decode all RS blocks from buffers and copy corrected bytes into fio->output 69 - * starting from block_offset. 66 + * Decode all RS codewords whose message bytes were loaded into fio->bufs. Copy 67 + * the corrected bytes into fio->output starting from block_offset. 70 68 */ 71 69 static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_io *io, 72 70 struct dm_verity_fec_io *fio, u64 rsb, int byte_index, ··· 76 74 struct dm_buffer *buf; 77 75 unsigned int n, i, j, parity_pos, to_copy; 78 76 uint16_t par_buf[DM_VERITY_FEC_MAX_ROOTS]; 79 - u8 *par, *block; 77 + u8 *par, *msg_buf; 80 78 u64 parity_block; 81 79 struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); 82 80 ··· 99 97 } 100 98 101 99 /* 102 - * Decode the RS blocks we have in bufs. Each RS block results in 103 - * one corrected target byte and consumes fec->roots parity bytes. 100 + * Decode the RS codewords whose message bytes are in bufs. Each RS 101 + * codeword results in one corrected target byte and consumes fec->roots 102 + * parity bytes. 104 103 */ 105 - fec_for_each_buffer_rs_block(fio, n, i) { 106 - block = fec_buffer_rs_block(v, fio, n, i); 104 + fec_for_each_buffer_rs_message(fio, n, i) { 105 + msg_buf = fec_buffer_rs_message(v, fio, n, i); 107 106 108 107 /* 109 108 * Copy the next 'roots' parity bytes to 'par_buf', reading ··· 131 128 par_buf[j] = par[parity_pos++]; 132 129 } 133 130 134 - /* Decode an RS block using Reed-Solomon */ 135 - res = decode_rs8(fio->rs, block, par_buf, v->fec->rs_k, 131 + /* Decode an RS codeword using the Reed-Solomon library. */ 132 + res = decode_rs8(fio->rs, msg_buf, par_buf, v->fec->rs_k, 136 133 NULL, neras, fio->erasures, 0, NULL); 137 134 if (res < 0) { 138 135 r = res; ··· 140 137 } 141 138 142 139 corrected += res; 143 - fio->output[block_offset] = block[byte_index]; 140 + fio->output[block_offset] = msg_buf[byte_index]; 144 141 145 142 block_offset++; 146 143 if (block_offset >= 1 << v->data_dev_block_bits) ··· 188 185 struct dm_bufio_client *bufio; 189 186 struct dm_verity_fec_io *fio = io->fec_io; 190 187 u64 block, ileaved; 191 - u8 *bbuf, *rs_block; 188 + u8 *bbuf; 192 189 u8 want_digest[HASH_MAX_DIGESTSIZE]; 193 190 unsigned int n, k; 194 191 struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); ··· 265 262 * deinterleave and copy the bytes that fit into bufs, 266 263 * starting from block_offset 267 264 */ 268 - fec_for_each_buffer_rs_block(fio, n, j) { 265 + fec_for_each_buffer_rs_message(fio, n, j) { 269 266 k = fec_buffer_rs_index(n, j) + block_offset; 270 267 271 268 if (k >= 1 << v->data_dev_block_bits) 272 269 goto done; 273 270 274 - rs_block = fec_buffer_rs_block(v, fio, n, j); 275 - rs_block[i] = bbuf[k]; 271 + fec_buffer_rs_message(v, fio, n, j)[i] = bbuf[k]; 276 272 } 277 273 done: 278 274 dm_bufio_release(buf);
+5 -5
drivers/md/dm-verity-fec.h
··· 17 17 #define DM_VERITY_FEC_MAX_ROOTS 24 /* RS(255, 231): ~10% space overhead */ 18 18 19 19 /* buffers for deinterleaving and decoding */ 20 - #define DM_VERITY_FEC_BUF_RS_BITS 4 /* 1 << RS blocks per buffer */ 20 + #define DM_VERITY_FEC_BUF_RS_BITS 4 /* log2(RS messages per buffer) */ 21 21 22 22 #define DM_VERITY_OPT_FEC_DEV "use_fec_from_device" 23 23 #define DM_VERITY_OPT_FEC_BLOCKS "fec_blocks" ··· 52 52 unsigned int level; /* recursion level */ 53 53 unsigned int nbufs; /* number of buffers allocated */ 54 54 /* 55 - * Buffers for deinterleaving RS blocks. Each buffer has space for 56 - * the data bytes of (1 << DM_VERITY_FEC_BUF_RS_BITS) RS blocks. The 57 - * array length is fec_max_nbufs(v), and we try to allocate that many 58 - * buffers. However, in low-memory situations we may be unable to 55 + * Buffers for deinterleaving RS codewords. Each buffer has space for 56 + * the message bytes of (1 << DM_VERITY_FEC_BUF_RS_BITS) RS codewords. 57 + * The array length is fec_max_nbufs(v), and we try to allocate that 58 + * many buffers. However, in low-memory situations we may be unable to 59 59 * allocate all buffers. 'nbufs' holds the number actually allocated. 60 60 */ 61 61 u8 *bufs[];