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: pass down index_in_region instead of rsb

Replace 'rsb', which is a byte index, with 'index_in_region' which is a
block index. The block index is slightly easier to compute, it matches
what fec_read_bufs() wants, and it avoids the mismatch between the name
and the units of the variable. ('rsb' stood for "Reed-Solomon block",
but its units were bytes, not blocks.)

fec_decode_bufs() does want it as a byte index when computing
parity_block, but that's easily handled locally.

As long as the parameters to the log messages are being adjusted, also
eliminate the unnecessary casts to 'unsigned long long'. %llu is the
correct way to print a u64 in the Linux kernel, as documented in
printk-formats.rst. There's no PRIu64 macro like there is in userspace.

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
b39b3c81 ca21ed40

+26 -21
+26 -21
drivers/md/dm-verity-fec.c
··· 49 49 * the corrected bytes into fio->output starting from out_pos. 50 50 */ 51 51 static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_io *io, 52 - struct dm_verity_fec_io *fio, u64 rsb, 52 + struct dm_verity_fec_io *fio, u64 index_in_region, 53 53 int target_region, unsigned int out_pos, int neras) 54 54 { 55 55 int r, corrected = 0, res; ··· 67 67 * block_size is always a power of 2, but roots might not be. Note that 68 68 * when it's not, a codeword's parity bytes can span a block boundary. 69 69 */ 70 - parity_block = (rsb + out_pos) * v->fec->roots; 70 + parity_block = ((index_in_region << v->data_dev_block_bits) + out_pos) * 71 + v->fec->roots; 71 72 parity_pos = parity_block & (v->fec->block_size - 1); 72 73 parity_block >>= v->data_dev_block_bits; 73 74 par = dm_bufio_read_with_ioprio(v->fec->bufio, parity_block, &buf, 74 75 bio->bi_ioprio); 75 76 if (IS_ERR(par)) { 76 77 DMERR("%s: FEC %llu: parity read failed (block %llu): %ld", 77 - v->data_dev->name, rsb, parity_block, PTR_ERR(par)); 78 + v->data_dev->name, index_in_region, parity_block, 79 + PTR_ERR(par)); 78 80 return PTR_ERR(par); 79 81 } 80 82 ··· 105 103 bio->bi_ioprio); 106 104 if (IS_ERR(par)) { 107 105 DMERR("%s: FEC %llu: parity read failed (block %llu): %ld", 108 - v->data_dev->name, rsb, parity_block, 109 - PTR_ERR(par)); 106 + v->data_dev->name, index_in_region, 107 + parity_block, PTR_ERR(par)); 110 108 return PTR_ERR(par); 111 109 } 112 110 for (; j < v->fec->roots; j++) ··· 134 132 135 133 if (r < 0 && neras) 136 134 DMERR_LIMIT("%s: FEC %llu: failed to correct: %d", 137 - v->data_dev->name, (unsigned long long)rsb, r); 135 + v->data_dev->name, index_in_region, r); 138 136 else if (r > 0) 139 137 DMWARN_LIMIT("%s: FEC %llu: corrected %d errors", 140 - v->data_dev->name, (unsigned long long)rsb, r); 138 + v->data_dev->name, index_in_region, r); 141 139 142 140 return r; 143 141 } ··· 160 158 * fits into buffers. Check for erasure locations if @neras is non-NULL. 161 159 */ 162 160 static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io, 163 - u64 rsb, unsigned int out_pos, int *neras) 161 + u64 index_in_region, unsigned int out_pos, int *neras) 164 162 { 165 163 bool is_zero; 166 164 int i, j; 167 165 struct dm_buffer *buf; 168 166 struct dm_bufio_client *bufio; 169 167 struct dm_verity_fec_io *fio = io->fec_io; 170 - u64 block, ileaved; 168 + u64 block; 171 169 u8 *bbuf; 172 170 u8 want_digest[HASH_MAX_DIGESTSIZE]; 173 171 unsigned int n, src_pos; ··· 184 182 * interleave contents to available bufs 185 183 */ 186 184 for (i = 0; i < v->fec->rs_k; i++) { 187 - ileaved = rsb + i * (v->fec->region_blocks << v->data_dev_block_bits); 188 - block = ileaved >> v->data_dev_block_bits; 185 + block = i * v->fec->region_blocks + index_in_region; 189 186 bufio = v->fec->data_bufio; 190 187 191 188 if (block >= v->data_blocks) { ··· 204 203 bbuf = dm_bufio_read_with_ioprio(bufio, block, &buf, bio->bi_ioprio); 205 204 if (IS_ERR(bbuf)) { 206 205 DMWARN_LIMIT("%s: FEC %llu: read failed (%llu): %ld", 207 - v->data_dev->name, 208 - (unsigned long long)rsb, 209 - (unsigned long long)block, PTR_ERR(bbuf)); 206 + v->data_dev->name, index_in_region, block, 207 + PTR_ERR(bbuf)); 210 208 211 209 /* assume the block is corrupted */ 212 210 if (neras && *neras <= v->fec->roots) ··· 312 312 { 313 313 int r, neras = 0; 314 314 unsigned int target_region, out_pos; 315 - u64 rsb; 315 + u64 index_in_region; 316 316 317 - target_region = div64_u64_rem( 318 - target_block << v->data_dev_block_bits, 319 - v->fec->region_blocks << v->data_dev_block_bits, &rsb); 317 + /* 318 + * Compute 'target_region', the index of the region the target block is 319 + * in; and 'index_in_region', the index of the target block within its 320 + * region. The latter value is also the index within its region of each 321 + * message block that shares its RS codewords with the target block. 322 + */ 323 + target_region = div64_u64_rem(target_block, v->fec->region_blocks, 324 + &index_in_region); 320 325 if (WARN_ON_ONCE(target_region >= v->fec->rs_k)) 321 326 /* target_block is out-of-bounds. Should never happen. */ 322 327 return -EIO; ··· 329 324 for (out_pos = 0; out_pos < v->fec->block_size;) { 330 325 fec_init_bufs(v, fio); 331 326 332 - r = fec_read_bufs(v, io, rsb, out_pos, 327 + r = fec_read_bufs(v, io, index_in_region, out_pos, 333 328 use_erasures ? &neras : NULL); 334 329 if (unlikely(r < 0)) 335 330 return r; 336 331 337 - r = fec_decode_bufs(v, io, fio, rsb, target_region, 332 + r = fec_decode_bufs(v, io, fio, index_in_region, target_region, 338 333 out_pos, neras); 339 334 if (r < 0) 340 335 return r; ··· 349 344 350 345 if (memcmp(io->tmp_digest, want_digest, v->digest_size)) { 351 346 DMERR_LIMIT("%s: FEC %llu: failed to correct (%d erasures)", 352 - v->data_dev->name, (unsigned long long)rsb, neras); 347 + v->data_dev->name, index_in_region, neras); 353 348 return -EILSEQ; 354 349 } 355 350