]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dm verity fec: Expose corrected block count via status
authorShubhankar Mishra <shubhankarm@google.com>
Wed, 5 Nov 2025 14:06:44 +0000 (14:06 +0000)
committerMikulas Patocka <mpatocka@redhat.com>
Tue, 18 Nov 2025 17:24:26 +0000 (18:24 +0100)
Enhance visibility into dm-verity Forward Error Correction (FEC)
activity. While FEC can correct on-disk corruptions, the number of
successful correction events is not readily exposed through a standard
interface.

This change integrates FEC statistics into the verity target's
.status handler for STATUSTYPE_INFO. The info output now
includes count of corrected block by FEC.

The counter is a per-device instance atomic64_t, maintained within
the struct dm_verity_fec, tracking blocks successfully repaired by FEC
on this specific device instance since it was created.

This approach aligns with the standard Device Mapper mechanism for
targets to report runtime information, as used by other targets like
dm-integrity.

This patch also updates Documentation/admin-guide/device-mapper/verity.rst
to reflect the new status information.

Tested:
  Induced single-bit errors on a block device protected by dm-verity
  with FEC on android phone. Confirmed 'dmctl status <device>' on Android
  reports an incrementing 'fec_corrected_blocks' count after the
  corrupted blocks were accessed.

Signed-off-by: Shubhankar Mishra <shubhankarm@google.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Documentation/admin-guide/device-mapper/verity.rst
drivers/md/dm-verity-fec.c
drivers/md/dm-verity-fec.h
drivers/md/dm-verity-target.c

index 8c3f1f967a3cdf0883ef95cf5f60ccab2977e7c9..3ecab1cff9c64c0feae1327ee6d98a6b2e0052c6 100644 (file)
@@ -236,8 +236,10 @@ is available at the cryptsetup project's wiki page
 
 Status
 ======
-V (for Valid) is returned if every check performed so far was valid.
-If any check failed, C (for Corruption) is returned.
+1. V (for Valid) is returned if every check performed so far was valid.
+   If any check failed, C (for Corruption) is returned.
+2. Number of corrected blocks by Forward Error Correction.
+   '-' if Forward Error Correction is not enabled.
 
 Example
 =======
index 301a9c01bf865b02a0f64840fc2cf7594b031a46..d792eaed079265d44d0abd66abf725383ce2432a 100644 (file)
@@ -177,9 +177,11 @@ error:
        if (r < 0 && neras)
                DMERR_LIMIT("%s: FEC %llu: failed to correct: %d",
                            v->data_dev->name, (unsigned long long)rsb, r);
-       else if (r > 0)
+       else if (r > 0) {
                DMWARN_LIMIT("%s: FEC %llu: corrected %d errors",
                             v->data_dev->name, (unsigned long long)rsb, r);
+               atomic64_inc(&v->fec->corrected);
+       }
 
        return r;
 }
index a6689cdc489dbcffcc08156bfa38fbc59597bec5..dd55037377b6d7a2e4d8fd8c0b8113eae2d9238d 100644 (file)
@@ -48,6 +48,7 @@ struct dm_verity_fec {
        mempool_t extra_pool;   /* mempool for extra buffers */
        mempool_t output_pool;  /* mempool for output */
        struct kmem_cache *cache;       /* cache for buffers */
+       atomic64_t corrected; /* corrected errors */
 };
 
 /* per-bio data */
index bf0aee73b074cd4f2a6afec771085193c3013ed6..52a0e052a5e8526cf45e4f6b1b56783cb13dddff 100644 (file)
@@ -848,6 +848,10 @@ static void verity_status(struct dm_target *ti, status_type_t type,
        switch (type) {
        case STATUSTYPE_INFO:
                DMEMIT("%c", v->hash_failed ? 'C' : 'V');
+               if (verity_fec_is_enabled(v))
+                       DMEMIT(" %lld", atomic64_read(&v->fec->corrected));
+               else
+                       DMEMIT(" -");
                break;
        case STATUSTYPE_TABLE:
                DMEMIT("%u %s %s %u %u %llu %llu %s ",