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: replace io_size with block_size

dm-verity's FEC implementation assumes that data_block_size ==
hash_block_size, and it accesses the FEC device in units of the same
size. Many places in the code want that size and compute it on-demand
as '1 << v->data_dev_block_bits'. However, it's actually already
available in v->fec->io_size. Rename that field to block_size,
initialize it a bit earlier, and use it in the appropriate places.

Note that while these sizes could in principle be different, that case
is not supported. So there's no need to complicate the code for it.

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
e75d5546 9b6098ad

+14 -18
+13 -17
drivers/md/dm-verity-fec.c
··· 84 84 * Compute the index of the first parity block that will be needed and 85 85 * the starting position in that block. Then read that block. 86 86 * 87 - * io_size is always a power of 2, but roots might not be. Note that 87 + * block_size is always a power of 2, but roots might not be. Note that 88 88 * when it's not, a codeword's parity bytes can span a block boundary. 89 89 */ 90 90 parity_block = (rsb + block_offset) * v->fec->roots; 91 - parity_pos = parity_block & (v->fec->io_size - 1); 91 + parity_pos = parity_block & (v->fec->block_size - 1); 92 92 parity_block >>= v->data_dev_block_bits; 93 93 par = dm_bufio_read_with_ioprio(v->fec->bufio, parity_block, &buf, 94 94 bio->bi_ioprio); ··· 110 110 * Copy the next 'roots' parity bytes to 'par_buf', reading 111 111 * another parity block if needed. 112 112 */ 113 - to_copy = min(v->fec->io_size - parity_pos, v->fec->roots); 113 + to_copy = min(v->fec->block_size - parity_pos, v->fec->roots); 114 114 for (j = 0; j < to_copy; j++) 115 115 par_buf[j] = par[parity_pos++]; 116 116 if (to_copy < v->fec->roots) { ··· 143 143 fio->output[block_offset] = msg_buf[byte_index]; 144 144 145 145 block_offset++; 146 - if (block_offset >= 1 << v->data_dev_block_bits) 146 + if (block_offset >= v->fec->block_size) 147 147 goto done; 148 148 } 149 149 done: ··· 167 167 static int fec_is_erasure(struct dm_verity *v, struct dm_verity_io *io, 168 168 const u8 *want_digest, const u8 *data) 169 169 { 170 - if (unlikely(verity_hash(v, io, data, 1 << v->data_dev_block_bits, 170 + if (unlikely(verity_hash(v, io, data, v->fec->block_size, 171 171 io->tmp_digest))) 172 172 return 0; 173 173 ··· 268 268 fec_for_each_buffer_rs_message(fio, n, j) { 269 269 k = fec_buffer_rs_index(n, j) + block_offset; 270 270 271 - if (k >= 1 << v->data_dev_block_bits) 271 + if (k >= v->fec->block_size) 272 272 goto done; 273 273 274 274 fec_buffer_rs_message(v, fio, n, j)[i] = bbuf[k]; ··· 341 341 int r, neras = 0; 342 342 unsigned int pos; 343 343 344 - for (pos = 0; pos < 1 << v->data_dev_block_bits; ) { 344 + for (pos = 0; pos < v->fec->block_size;) { 345 345 fec_init_bufs(v, fio); 346 346 347 347 r = fec_read_bufs(v, io, rsb, offset, pos, ··· 357 357 } 358 358 359 359 /* Always re-validate the corrected block against the expected hash */ 360 - r = verity_hash(v, io, fio->output, 1 << v->data_dev_block_bits, 361 - io->tmp_digest); 360 + r = verity_hash(v, io, fio->output, v->fec->block_size, io->tmp_digest); 362 361 if (unlikely(r < 0)) 363 362 return r; 364 363 ··· 425 426 goto done; 426 427 } 427 428 428 - memcpy(dest, fio->output, 1 << v->data_dev_block_bits); 429 + memcpy(dest, fio->output, v->fec->block_size); 429 430 atomic64_inc(&v->fec->corrected); 430 431 431 432 done: ··· 646 647 ti->error = "Block sizes must match to use FEC"; 647 648 return -EINVAL; 648 649 } 650 + f->block_size = 1 << v->data_dev_block_bits; 649 651 650 652 if (!f->roots) { 651 653 ti->error = "Missing " DM_VERITY_OPT_FEC_ROOTS; ··· 684 684 return -E2BIG; 685 685 } 686 686 687 - f->io_size = 1 << v->data_dev_block_bits; 688 - 689 - f->bufio = dm_bufio_client_create(f->dev->bdev, 690 - f->io_size, 687 + f->bufio = dm_bufio_client_create(f->dev->bdev, f->block_size, 691 688 1, 0, NULL, NULL, 0); 692 689 if (IS_ERR(f->bufio)) { 693 690 ti->error = "Cannot initialize FEC bufio client"; ··· 698 701 return -E2BIG; 699 702 } 700 703 701 - f->data_bufio = dm_bufio_client_create(v->data_dev->bdev, 702 - 1 << v->data_dev_block_bits, 704 + f->data_bufio = dm_bufio_client_create(v->data_dev->bdev, f->block_size, 703 705 1, 0, NULL, NULL, 0); 704 706 if (IS_ERR(f->data_bufio)) { 705 707 ti->error = "Cannot initialize FEC data bufio client"; ··· 745 749 746 750 /* Preallocate an output buffer for each thread */ 747 751 ret = mempool_init_kmalloc_pool(&f->output_pool, num_online_cpus(), 748 - 1 << v->data_dev_block_bits); 752 + f->block_size); 749 753 if (ret) { 750 754 ti->error = "Cannot allocate FEC output pool"; 751 755 return ret;
+1 -1
drivers/md/dm-verity-fec.h
··· 29 29 struct dm_dev *dev; /* parity data device */ 30 30 struct dm_bufio_client *data_bufio; /* for data dev access */ 31 31 struct dm_bufio_client *bufio; /* for parity data access */ 32 - size_t io_size; /* IO size for roots */ 32 + size_t block_size; /* size of data, hash, and parity blocks in bytes */ 33 33 sector_t start; /* parity data start in blocks */ 34 34 sector_t blocks; /* number of blocks covered */ 35 35 sector_t rounds; /* number of interleaving rounds */