Skip to content

Commit 63dcd69

Browse files
committed
Merge tag 'for-5.12/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: "Fix DM verity target's optional Forward Error Correction (FEC) for Reed-Solomon roots that are unaligned to block size" * tag 'for-5.12/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm verity: fix FEC for RS roots unaligned to block size dm bufio: subtract the number of initial sectors in dm_bufio_get_device_size
2 parents 47454ca + df7b59b commit 63dcd69

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

drivers/md/dm-bufio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,10 @@ EXPORT_SYMBOL_GPL(dm_bufio_get_block_size);
15261526
sector_t dm_bufio_get_device_size(struct dm_bufio_client *c)
15271527
{
15281528
sector_t s = i_size_read(c->bdev->bd_inode) >> SECTOR_SHIFT;
1529+
if (s >= c->start)
1530+
s -= c->start;
1531+
else
1532+
s = 0;
15291533
if (likely(c->sectors_per_block_bits >= 0))
15301534
s >>= c->sectors_per_block_bits;
15311535
else

drivers/md/dm-verity-fec.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,18 @@ static int fec_decode_rs8(struct dm_verity *v, struct dm_verity_fec_io *fio,
6161
static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index,
6262
unsigned *offset, struct dm_buffer **buf)
6363
{
64-
u64 position, block;
64+
u64 position, block, rem;
6565
u8 *res;
6666

6767
position = (index + rsb) * v->fec->roots;
68-
block = position >> v->data_dev_block_bits;
69-
*offset = (unsigned)(position - (block << v->data_dev_block_bits));
68+
block = div64_u64_rem(position, v->fec->roots << SECTOR_SHIFT, &rem);
69+
*offset = (unsigned)rem;
7070

71-
res = dm_bufio_read(v->fec->bufio, v->fec->start + block, buf);
71+
res = dm_bufio_read(v->fec->bufio, block, buf);
7272
if (IS_ERR(res)) {
7373
DMERR("%s: FEC %llu: parity read failed (block %llu): %ld",
7474
v->data_dev->name, (unsigned long long)rsb,
75-
(unsigned long long)(v->fec->start + block),
76-
PTR_ERR(res));
75+
(unsigned long long)block, PTR_ERR(res));
7776
*buf = NULL;
7877
}
7978

@@ -155,7 +154,7 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio,
155154

156155
/* read the next block when we run out of parity bytes */
157156
offset += v->fec->roots;
158-
if (offset >= 1 << v->data_dev_block_bits) {
157+
if (offset >= v->fec->roots << SECTOR_SHIFT) {
159158
dm_bufio_release(buf);
160159

161160
par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
@@ -674,7 +673,7 @@ int verity_fec_ctr(struct dm_verity *v)
674673
{
675674
struct dm_verity_fec *f = v->fec;
676675
struct dm_target *ti = v->ti;
677-
u64 hash_blocks;
676+
u64 hash_blocks, fec_blocks;
678677
int ret;
679678

680679
if (!verity_fec_is_enabled(v)) {
@@ -744,15 +743,17 @@ int verity_fec_ctr(struct dm_verity *v)
744743
}
745744

746745
f->bufio = dm_bufio_client_create(f->dev->bdev,
747-
1 << v->data_dev_block_bits,
746+
f->roots << SECTOR_SHIFT,
748747
1, 0, NULL, NULL);
749748
if (IS_ERR(f->bufio)) {
750749
ti->error = "Cannot initialize FEC bufio client";
751750
return PTR_ERR(f->bufio);
752751
}
753752

754-
if (dm_bufio_get_device_size(f->bufio) <
755-
((f->start + f->rounds * f->roots) >> v->data_dev_block_bits)) {
753+
dm_bufio_set_sector_offset(f->bufio, f->start << (v->data_dev_block_bits - SECTOR_SHIFT));
754+
755+
fec_blocks = div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT);
756+
if (dm_bufio_get_device_size(f->bufio) < fec_blocks) {
756757
ti->error = "FEC device is too small";
757758
return -E2BIG;
758759
}

0 commit comments

Comments
 (0)