Fix DM verity target FEC support's RS roots IO to always be

aligned. This fixes a previous stable@ fix that overcorrected for a
 different configuration that also resulted in misaligned roots IO.
 -----BEGIN PGP SIGNATURE-----
 
 iQFHBAABCAAxFiEEJfWUX4UqZ4x1O2wixSPxCi2dA1oFAmB3NaITHHNuaXR6ZXJA
 cmVkaGF0LmNvbQAKCRDFI/EKLZ0DWi/zCACuvIs74tVsHz9o1j6M6kJ2hUYkfThv
 dRIt4p5Qb5Rd5TCN0KwosRRVZopuI/doDX92ORmsyqx1XhY6x6WOrMxCv/3F+/xw
 Bf3Rflhy0q+6ZlLM6tQZvYApFlpxZLMDOxc+VMxldGKHqU5D+Tid4tZ99YJMwbj/
 7tKNi7oiil96CaqQfsvm+UgckIIxZVf+RTcdc6LH9W5gd4X1RmuGOoy/LKK8AeY+
 PKIWjzflF/CQobUM/pVRbgSqUi2ZtzhbYBBKb5dndnjSNoHn3atZzvcAvhtuvkoB
 KhjGY4PwK2PGO6QIgkJBLxg04g2AuxOqfB27AVGYVvO0ELp66sawMLxO
 =B600
 -----END PGP SIGNATURE-----

Merge tag 'for-5.12/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm

Pull device mapper fix from Mike Snitzer:
 "Fix DM verity target FEC support's RS roots IO to always be aligned.

  This fixes a previous stable@ fix that overcorrected for a different
  configuration that also resulted in misaligned roots IO"

* tag 'for-5.12/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm:
  dm verity fec: fix misaligned RS roots IO
This commit is contained in:
Linus Torvalds 2021-04-14 13:23:54 -07:00
commit 7f75285ca5
2 changed files with 9 additions and 3 deletions

View file

@ -65,7 +65,7 @@ static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index,
u8 *res;
position = (index + rsb) * v->fec->roots;
block = div64_u64_rem(position, v->fec->roots << SECTOR_SHIFT, &rem);
block = div64_u64_rem(position, v->fec->io_size, &rem);
*offset = (unsigned)rem;
res = dm_bufio_read(v->fec->bufio, block, buf);
@ -154,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 */
offset += v->fec->roots;
if (offset >= v->fec->roots << SECTOR_SHIFT) {
if (offset >= v->fec->io_size) {
dm_bufio_release(buf);
par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
@ -742,8 +742,13 @@ int verity_fec_ctr(struct dm_verity *v)
return -E2BIG;
}
if ((f->roots << SECTOR_SHIFT) & ((1 << v->data_dev_block_bits) - 1))
f->io_size = 1 << v->data_dev_block_bits;
else
f->io_size = v->fec->roots << SECTOR_SHIFT;
f->bufio = dm_bufio_client_create(f->dev->bdev,
f->roots << SECTOR_SHIFT,
f->io_size,
1, 0, NULL, NULL);
if (IS_ERR(f->bufio)) {
ti->error = "Cannot initialize FEC bufio client";

View file

@ -36,6 +36,7 @@ struct dm_verity_fec {
struct dm_dev *dev; /* parity data device */
struct dm_bufio_client *data_bufio; /* for data dev access */
struct dm_bufio_client *bufio; /* for parity data access */
size_t io_size; /* IO size for roots */
sector_t start; /* parity data start in blocks */
sector_t blocks; /* number of blocks covered */
sector_t rounds; /* number of interleaving rounds */