Skip to contentSkip to conversation

dm-verity: skip verity_handle_error on I/O errors

PATCH In review Akilesh Kailash 2 participants 2 messages Sep 13, 2021 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-verity: skip verity_handle_error on I/O errors

If there is an I/O error and FEC correction fails, return an error instead of calling verity_handle_error().

---
This was discussed in [1] by Sami Tolvanen but was never implemented.

[1] https://lore.kernel.org/dm-devel/[email protected]/T/#mec4df1ba3f3cb63846875fb2bfc1f8b3100f31f1

 drivers/md/dm-verity-target.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/md/dm-verity-target.c +11 -2
index 22a5ac82446a..a6f7c452ee80 100644
@@ -475,6 +475,7 @@ static int verity_verify_io(struct dm_verity_io *io)
 	struct bvec_iter start;
 	unsigned b;
 	struct crypto_wait wait;
+	struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
 
 	for (b = 0; b < io->n_blocks; b++) {
 		int r;
@@ -529,9 +530,17 @@ static int verity_verify_io(struct dm_verity_io *io)
 		else if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_DATA,
 					   cur_block, NULL, &start) == 0)
 			continue;
-		else if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA,
+		else {
+			if (bio->bi_status) {
+				/*
+				 * Error correction failed; Just return error
+				 */
+				return -EIO;
+			}
+			if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA,
 					   cur_block))
-			return -EIO;
+				return -EIO;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.33.0.309.g3052b89438-goog
Reviewed-by on v1 1/1
#1 lore raw

Hi Akilesh,

Quoted 11 lines · Akilesh Kailash

If there is an I/O error and FEC correction fails, return an error instead of calling verity_handle_error().

---
This was discussed in [1] by Sami Tolvanen but was never implemented.

[1] https://lore.kernel.org/dm-devel/[email protected]/T/#mec4df1ba3f3cb63846875fb2bfc1f8b3100f31f1

Great, thanks for the patch!

Quoted 25 lines
 drivers/md/dm-verity-target.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/md/dm-verity-target.c +6 -1
index 22a5ac82446a..a6f7c452ee80 100644
@@ -475,6 +475,7 @@ static int verity_verify_io(struct dm_verity_io *io)
        struct bvec_iter start;
        unsigned b;
        struct crypto_wait wait;
+       struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
 
        for (b = 0; b < io->n_blocks; b++) {
                int r;
@@ -529,9 +530,17 @@ static int verity_verify_io(struct dm_verity_io *io)
                else if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_DATA,
                                           cur_block, NULL, &start) == 0)
                        continue;
-               else if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA,
+               else {
+                       if (bio->bi_status) {
+                               /*
+                                * Error correction failed; Just return error
+                                */

drivers/md/dm-verity-target.c static int verity_verify_io(struct dm_verity_io *io) · line 546

Quoted 10 lines
drivers/md/dm-verity-target.c +5 -1
+                               return -EIO;
+                       }
+                       if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA,
                                           cur_block))
-                       return -EIO;
+                               return -EIO;
+               }
        }
 
        return 0;

This looks correct to me. A non-zero bio->bi_status here means that FEC must be enabled because otherwise we wouldn't have ended up in verity_verify_io() in the first place, and returning -EIO when verity_fec_decode() fails after attempting to correct an I/O error is consistent with the non-FEC behavior of dm-verity.

Sami