Revert "Revert "dm verity: fix FEC for RS roots unaligned to blo..."

Revert submission 1672946

Reason for revert: getting back to mainline with a proper fix
Reverted Changes:
I96ee9a0a8:Revert "dm bufio: subtract the number of initial s...
I23d4da47b:Revert "dm verity: fix FEC for RS roots unaligned ...

Change-Id: I976307e4f85fc6e13286f4305ef0eb945d9467ce
This commit is contained in:
Jaegeuk Kim
2021-04-14 18:47:28 +00:00
parent fc503912fd
commit 5ef36bda8f

View File

@@ -61,19 +61,18 @@ static int fec_decode_rs8(struct dm_verity *v, struct dm_verity_fec_io *fio,
static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index, static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index,
unsigned *offset, struct dm_buffer **buf) unsigned *offset, struct dm_buffer **buf)
{ {
u64 position, block; u64 position, block, rem;
u8 *res; u8 *res;
position = (index + rsb) * v->fec->roots; position = (index + rsb) * v->fec->roots;
block = position >> v->data_dev_block_bits; block = div64_u64_rem(position, v->fec->roots << SECTOR_SHIFT, &rem);
*offset = (unsigned)(position - (block << v->data_dev_block_bits)); *offset = (unsigned)rem;
res = dm_bufio_read(v->fec->bufio, v->fec->start + block, buf); res = dm_bufio_read(v->fec->bufio, block, buf);
if (IS_ERR(res)) { if (IS_ERR(res)) {
DMERR("%s: FEC %llu: parity read failed (block %llu): %ld", DMERR("%s: FEC %llu: parity read failed (block %llu): %ld",
v->data_dev->name, (unsigned long long)rsb, v->data_dev->name, (unsigned long long)rsb,
(unsigned long long)(v->fec->start + block), (unsigned long long)block, PTR_ERR(res));
PTR_ERR(res));
*buf = NULL; *buf = NULL;
} }
@@ -155,7 +154,7 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio,
/* read the next block when we run out of parity bytes */ /* read the next block when we run out of parity bytes */
offset += v->fec->roots; offset += v->fec->roots;
if (offset >= 1 << v->data_dev_block_bits) { if (offset >= v->fec->roots << SECTOR_SHIFT) {
dm_bufio_release(buf); dm_bufio_release(buf);
par = fec_read_parity(v, rsb, block_offset, &offset, &buf); par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
@@ -674,7 +673,7 @@ int verity_fec_ctr(struct dm_verity *v)
{ {
struct dm_verity_fec *f = v->fec; struct dm_verity_fec *f = v->fec;
struct dm_target *ti = v->ti; struct dm_target *ti = v->ti;
u64 hash_blocks; u64 hash_blocks, fec_blocks;
int ret; int ret;
if (!verity_fec_is_enabled(v)) { if (!verity_fec_is_enabled(v)) {
@@ -744,15 +743,17 @@ int verity_fec_ctr(struct dm_verity *v)
} }
f->bufio = dm_bufio_client_create(f->dev->bdev, f->bufio = dm_bufio_client_create(f->dev->bdev,
1 << v->data_dev_block_bits, f->roots << SECTOR_SHIFT,
1, 0, NULL, NULL); 1, 0, NULL, NULL);
if (IS_ERR(f->bufio)) { if (IS_ERR(f->bufio)) {
ti->error = "Cannot initialize FEC bufio client"; ti->error = "Cannot initialize FEC bufio client";
return PTR_ERR(f->bufio); return PTR_ERR(f->bufio);
} }
if (dm_bufio_get_device_size(f->bufio) < dm_bufio_set_sector_offset(f->bufio, f->start << (v->data_dev_block_bits - SECTOR_SHIFT));
((f->start + f->rounds * f->roots) >> v->data_dev_block_bits)) {
fec_blocks = div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT);
if (dm_bufio_get_device_size(f->bufio) < fec_blocks) {
ti->error = "FEC device is too small"; ti->error = "FEC device is too small";
return -E2BIG; return -E2BIG;
} }