From nobody Thu Dec 18 23:21:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7364F2750E6; Tue, 16 Dec 2025 23:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926419; cv=none; b=h+kaBW7pXmUvorMQreJ3kGEBumkG87IZ7t9PSFMvEVIgZu8MXEhKw9XT8pzI2UVatufPvxZ6fDct+D7hCT0iPqXSL8BPtDg/kSmzNdOD0Jz61DS/w8tkWw6o1fpt557UDzl/bVOj0gr/+RtXPupCTf88eEBKO5LTVlL01LqR/Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926419; c=relaxed/simple; bh=v3TmOU2giy1M/3cEnOwsB9EsF/UiB0CAx7I0S8XvV1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHgorI/jMZA84D7YWhoprdyBECA+sj2dSwZEvAUrN21riFPAsF5eZwNNK2A4bxGzxwuZRGxKkKTUdG82IZE42IMZwdGDsSQpK60/j1wZR1y0CWXtHDAMszlamBQAudmdZG0N3UiQFVR9f17wHmII8h/4inV7S+jQmKJ6CNCXpLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nHtsNufw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nHtsNufw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE316C4CEF1; Tue, 16 Dec 2025 23:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765926419; bh=v3TmOU2giy1M/3cEnOwsB9EsF/UiB0CAx7I0S8XvV1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nHtsNufw8hrIxqB4m99cfb/UrZMtni/q1Y6tKq47eTMHzYhTd6UDEPyXK4ac026ix whFpBUsdPXiQKWANJH3L89QcP8u0+kxUeLSF1BjFogP+zNAUMWyQdc+hiKfTCUUrPq 2awhy/i9r8pfxzrOp+Xyq1bZM/JWP+ZOtOKWyDyW60aAQnGiiMnXgT++dc2l1JD5sH iLRU9ZSEmtOt/xDwdfbAmDTNnQsjLzDLZ1RaCLRBvfBv9ZOf47e/RWvcH/zo4pIBpx r+Eyywc3DfLuYG5+IK2NBKFr4+yonrMmmZI9w34IS75Bn7MsJuAVxu7F1ex4QVKTLg 7VehyUP9EAxOQ== From: Eric Biggers To: dm-devel@lists.linux.dev, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: Sami Tolvanen , Eran Messeri , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 1/7] dm-verity: move dm_verity_fec_io to mempool Date: Tue, 16 Dec 2025 15:06:08 -0800 Message-ID: <20251216230614.51779-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216230614.51779-1-ebiggers@kernel.org> References: <20251216230614.51779-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, struct dm_verity_fec_io is allocated in the front padding of struct bio using dm_target::per_io_data_size. Unfortunately, struct dm_verity_fec_io is very large: 3096 bytes when CONFIG_64BIT=3Dy && PAGE_SIZE =3D=3D 4096, or 9240 bytes when CONFIG_64BIT=3Dy && PAGE_SIZE =3D= =3D 16384. This makes the bio size very large. Moreover, most of dm_verity_fec_io gets iterated over up to three times, even on I/O requests that don't require any error correction: 1. To zero the memory on allocation, if init_on_alloc=3D1. (This happens when the bio is allocated, not in dm-verity itself.) 2. To zero the buffers array in verity_fec_init_io(). 3. To free the buffers in verity_fec_finish_io(). Fix all of these inefficiencies by moving dm_verity_fec_io to a mempool. Replace the embedded dm_verity_fec_io with a pointer dm_verity_io::fec_io. verity_fec_init_io() initializes it to NULL, verity_fec_decode() allocates it on the first call, and verity_fec_finish_io() cleans it up. The normal case is that the pointer simply stays NULL, so the overhead becomes negligible. Signed-off-by: Eric Biggers Reviewed-by: Sami Tolvanen --- drivers/md/dm-verity-fec.c | 95 +++++++++++++++----------------------- drivers/md/dm-verity-fec.h | 14 +++++- drivers/md/dm-verity.h | 4 ++ 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index c79de517afee..bf533ffa7d56 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -16,20 +16,10 @@ bool verity_fec_is_enabled(struct dm_verity *v) { return v->fec && v->fec->dev; } =20 -/* - * Return a pointer to dm_verity_fec_io after dm_verity_io and its variable - * length fields. - */ -static inline struct dm_verity_fec_io *fec_io(struct dm_verity_io *io) -{ - return (struct dm_verity_fec_io *) - ((char *)io + io->v->ti->per_io_data_size - sizeof(struct dm_verity_fec_= io)); -} - /* * Return an interleaved offset for a byte in RS block. */ static inline u64 fec_interleave(struct dm_verity *v, u64 offset) { @@ -209,11 +199,11 @@ static int fec_read_bufs(struct dm_verity *v, struct = dm_verity_io *io, { bool is_zero; int i, j, target_index =3D -1; struct dm_buffer *buf; struct dm_bufio_client *bufio; - struct dm_verity_fec_io *fio =3D fec_io(io); + struct dm_verity_fec_io *fio =3D io->fec_io; u64 block, ileaved; u8 *bbuf, *rs_block; u8 want_digest[HASH_MAX_DIGESTSIZE]; unsigned int n, k; struct bio *bio =3D dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); @@ -305,43 +295,44 @@ static int fec_read_bufs(struct dm_verity *v, struct = dm_verity_io *io, =20 return target_index; } =20 /* - * Allocate RS control structure and FEC buffers from preallocated mempool= s, - * and attempt to allocate as many extra buffers as available. + * Allocate and initialize a struct dm_verity_fec_io to use for FEC for a = bio. + * This runs the first time a block needs to be corrected for a bio. In t= he + * common case where no block needs to be corrected, this code never runs. + * + * This always succeeds, as all required allocations are done from mempool= s. + * Additional buffers are also allocated opportunistically to improve error + * correction performance, but these aren't required to succeed. */ -static int fec_alloc_bufs(struct dm_verity *v, struct dm_verity_fec_io *fi= o) +static struct dm_verity_fec_io *fec_alloc_and_init_io(struct dm_verity *v) { + struct dm_verity_fec *f =3D v->fec; + struct dm_verity_fec_io *fio; unsigned int n; =20 - if (!fio->rs) - fio->rs =3D mempool_alloc(&v->fec->rs_pool, GFP_NOIO); + fio =3D mempool_alloc(&f->fio_pool, GFP_NOIO); + fio->rs =3D mempool_alloc(&f->rs_pool, GFP_NOIO); =20 - fec_for_each_prealloc_buffer(n) { - if (fio->bufs[n]) - continue; + memset(fio->bufs, 0, sizeof(fio->bufs)); =20 - fio->bufs[n] =3D mempool_alloc(&v->fec->prealloc_pool, GFP_NOIO); - } + fec_for_each_prealloc_buffer(n) + fio->bufs[n] =3D mempool_alloc(&f->prealloc_pool, GFP_NOIO); =20 /* try to allocate the maximum number of buffers */ fec_for_each_extra_buffer(fio, n) { - if (fio->bufs[n]) - continue; - - fio->bufs[n] =3D kmem_cache_alloc(v->fec->cache, GFP_NOWAIT); + fio->bufs[n] =3D kmem_cache_alloc(f->cache, GFP_NOWAIT); /* we can manage with even one buffer if necessary */ if (unlikely(!fio->bufs[n])) break; } fio->nbufs =3D n; =20 - if (!fio->output) - fio->output =3D mempool_alloc(&v->fec->output_pool, GFP_NOIO); - - return 0; + fio->output =3D mempool_alloc(&f->output_pool, GFP_NOIO); + fio->level =3D 0; + return fio; } =20 /* * Initialize buffers and clear erasures. fec_read_bufs() assumes buffers = are * zeroed before deinterleaving. @@ -366,14 +357,10 @@ static int fec_decode_rsb(struct dm_verity *v, struct= dm_verity_io *io, const u8 *want_digest, bool use_erasures) { int r, neras =3D 0; unsigned int pos; =20 - r =3D fec_alloc_bufs(v, fio); - if (unlikely(r < 0)) - return r; - for (pos =3D 0; pos < 1 << v->data_dev_block_bits; ) { fec_init_bufs(v, fio); =20 r =3D fec_read_bufs(v, io, rsb, offset, pos, use_erasures ? &neras : NULL); @@ -406,16 +393,20 @@ static int fec_decode_rsb(struct dm_verity *v, struct= dm_verity_io *io, int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, enum verity_block_type type, const u8 *want_digest, sector_t block, u8 *dest) { int r; - struct dm_verity_fec_io *fio =3D fec_io(io); + struct dm_verity_fec_io *fio; u64 offset, res, rsb; =20 if (!verity_fec_is_enabled(v)) return -EOPNOTSUPP; =20 + fio =3D io->fec_io; + if (!fio) + fio =3D io->fec_io =3D fec_alloc_and_init_io(v); + if (fio->level) return -EIO; =20 fio->level++; =20 @@ -461,18 +452,15 @@ int verity_fec_decode(struct dm_verity *v, struct dm_= verity_io *io, } =20 /* * Clean up per-bio data. */ -void verity_fec_finish_io(struct dm_verity_io *io) +void __verity_fec_finish_io(struct dm_verity_io *io) { unsigned int n; struct dm_verity_fec *f =3D io->v->fec; - struct dm_verity_fec_io *fio =3D fec_io(io); - - if (!verity_fec_is_enabled(io->v)) - return; + struct dm_verity_fec_io *fio =3D io->fec_io; =20 mempool_free(fio->rs, &f->rs_pool); =20 fec_for_each_prealloc_buffer(n) mempool_free(fio->bufs[n], &f->prealloc_pool); @@ -480,27 +468,12 @@ void verity_fec_finish_io(struct dm_verity_io *io) fec_for_each_extra_buffer(fio, n) if (fio->bufs[n]) kmem_cache_free(f->cache, fio->bufs[n]); =20 mempool_free(fio->output, &f->output_pool); -} - -/* - * Initialize per-bio data. - */ -void verity_fec_init_io(struct dm_verity_io *io) -{ - struct dm_verity_fec_io *fio =3D fec_io(io); - - if (!verity_fec_is_enabled(io->v)) - return; =20 - fio->rs =3D NULL; - memset(fio->bufs, 0, sizeof(fio->bufs)); - fio->nbufs =3D 0; - fio->output =3D NULL; - fio->level =3D 0; + mempool_free(fio, &f->fio_pool); } =20 /* * Append feature arguments and values to the status table. */ @@ -527,10 +500,11 @@ void verity_fec_dtr(struct dm_verity *v) struct dm_verity_fec *f =3D v->fec; =20 if (!verity_fec_is_enabled(v)) goto out; =20 + mempool_exit(&f->fio_pool); mempool_exit(&f->rs_pool); mempool_exit(&f->prealloc_pool); mempool_exit(&f->output_pool); kmem_cache_destroy(f->cache); =20 @@ -756,10 +730,18 @@ int verity_fec_ctr(struct dm_verity *v) if (dm_bufio_get_device_size(f->data_bufio) < v->data_blocks) { ti->error =3D "Data device is too small"; return -E2BIG; } =20 + /* Preallocate some dm_verity_fec_io structures */ + ret =3D mempool_init_kmalloc_pool(&f->fio_pool, num_online_cpus(), + sizeof(struct dm_verity_fec_io)); + if (ret) { + ti->error =3D "Cannot allocate FEC IO pool"; + return ret; + } + /* Preallocate an rs_control structure for each worker thread */ ret =3D mempool_init(&f->rs_pool, num_online_cpus(), fec_rs_alloc, fec_rs_free, (void *) v); if (ret) { ti->error =3D "Cannot allocate RS pool"; @@ -789,10 +771,7 @@ int verity_fec_ctr(struct dm_verity *v) if (ret) { ti->error =3D "Cannot allocate FEC output pool"; return ret; } =20 - /* Reserve space for our per-bio data */ - ti->per_io_data_size +=3D sizeof(struct dm_verity_fec_io); - return 0; } diff --git a/drivers/md/dm-verity-fec.h b/drivers/md/dm-verity-fec.h index 5fd267873812..b9488d1ddf14 100644 --- a/drivers/md/dm-verity-fec.h +++ b/drivers/md/dm-verity-fec.h @@ -38,10 +38,11 @@ struct dm_verity_fec { sector_t blocks; /* number of blocks covered */ sector_t rounds; /* number of interleaving rounds */ sector_t hash_blocks; /* blocks covered after v->hash_start */ unsigned char roots; /* number of parity bytes, M-N of RS(M, N) */ unsigned char rsn; /* N of RS(M, N) */ + mempool_t fio_pool; /* mempool for dm_verity_fec_io */ mempool_t rs_pool; /* mempool for fio->rs */ mempool_t prealloc_pool; /* mempool for preallocated buffers */ mempool_t output_pool; /* mempool for output */ struct kmem_cache *cache; /* cache for buffers */ atomic64_t corrected; /* corrected errors */ @@ -69,12 +70,21 @@ extern int verity_fec_decode(struct dm_verity *v, struc= t dm_verity_io *io, sector_t block, u8 *dest); =20 extern unsigned int verity_fec_status_table(struct dm_verity *v, unsigned = int sz, char *result, unsigned int maxlen); =20 -extern void verity_fec_finish_io(struct dm_verity_io *io); -extern void verity_fec_init_io(struct dm_verity_io *io); +extern void __verity_fec_finish_io(struct dm_verity_io *io); +static inline void verity_fec_finish_io(struct dm_verity_io *io) +{ + if (unlikely(io->fec_io)) + __verity_fec_finish_io(io); +} + +static inline void verity_fec_init_io(struct dm_verity_io *io) +{ + io->fec_io =3D NULL; +} =20 extern bool verity_is_fec_opt_arg(const char *arg_name); extern int verity_fec_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v, unsigned int *argc, const char *arg_name); diff --git a/drivers/md/dm-verity.h b/drivers/md/dm-verity.h index f975a9e5c5d6..4ad7ce3dae0a 100644 --- a/drivers/md/dm-verity.h +++ b/drivers/md/dm-verity.h @@ -102,10 +102,14 @@ struct dm_verity_io { sector_t block; unsigned int n_blocks; bool in_bh; bool had_mismatch; =20 +#ifdef CONFIG_DM_VERITY_FEC + struct dm_verity_fec_io *fec_io; +#endif + struct work_struct work; struct work_struct bh_work; =20 u8 tmp_digest[HASH_MAX_DIGESTSIZE]; =20 --=20 2.52.0 From nobody Thu Dec 18 23:21:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52AD733FE10; Tue, 16 Dec 2025 23:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926420; cv=none; b=R1UVruQhNWxslfTi8j0o1L8km+Z+u9Y0mkohSlM7TMpRVEnfEe1ij3JMYGSMvIi2WTCLwsymV4bZeNCTZuS9CRDMBEBe17kVNByzAvkWPOSnGChZGBvI7QiDLhokg3IyHF/GIOso6nP4yL+ElysssP8QIQN/CWdsDS2bxjTpRog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926420; c=relaxed/simple; bh=UIh2lBlsCpMPvtCjHLE12Rw0UIMIzrvaY3f6XYfUzQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=taHZNG/3Ynauv7KivxcAcj7urPPLOg8hVhBT2XN0bXwEJsawTkbVWFkehV0V7OlDwG5Tvq/RTMO4xr4JaLtqBwX98hOOJ1SRT1ERU7eVdIV+z1dFKUN8/O1FgXZ35g/sKI0rRrP31ZeM6SRRHUZube2Vnv86rZiB8cwUU9JidWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i03WIikQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i03WIikQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DA3DC19424; Tue, 16 Dec 2025 23:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765926419; bh=UIh2lBlsCpMPvtCjHLE12Rw0UIMIzrvaY3f6XYfUzQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i03WIikQgmRlD91C0gqlY2p/Tg3h/5o2ssYupnVC10kBfnLD6lWIvtx9zPBwkwcnz 9i7apTc7QNkWlIkN9ieHntj+OPrf6ZIyxVbsImu14Ap64Q+tCXmj8UFGxuoMGXOt9v PALa2mFhVH/ibY58qRjZwClkvBuRswN/b1fqywDX23IkIXb0g0GDvoYj1HYvj2bLSA MZBvYvPYY2CbyD/JjZk8E8Bqqx3+FZWmrNTyzJeH4QHL0N9IRo1348XP9QnIL0nW9t 0SZxsy53/VwPKCnYDAdPWKTENd9saDsa5FfK2dVEPXndH3xmg4Vh8v0iT4X26GeKoU 4NiuR/RXHkstQ== From: Eric Biggers To: dm-devel@lists.linux.dev, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: Sami Tolvanen , Eran Messeri , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 2/7] dm-verity: make dm_verity_fec_io::bufs variable-length Date: Tue, 16 Dec 2025 15:06:09 -0800 Message-ID: <20251216230614.51779-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216230614.51779-1-ebiggers@kernel.org> References: <20251216230614.51779-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When correcting a data block, the FEC code performs optimally when it has enough buffers to hold all the needed RS blocks. That number of buffers is '1 << (v->data_dev_block_bits - DM_VERITY_FEC_BUF_RS_BITS)'. However, since v->data_dev_block_bits isn't a compile-time constant, the code actually used PAGE_SHIFT instead. With the traditional PAGE_SIZE =3D=3D data_block_size =3D=3D 4096, this was fine. However, when PAGE_SIZE > data_block_size, this wastes space. E.g., with data_block_size =3D=3D 4096 && PAGE_SIZE =3D=3D 16384, struct dm_verity_fec_io is 9240 bytes, when in fact only 3096 bytes are needed. Fix this by making dm_verity_fec_io::bufs a variable-length array. This makes the macros DM_VERITY_FEC_BUF_MAX and fec_for_each_extra_buffer() no longer apply, so remove them. Also remove the related macro fec_for_each_prealloc_buffer(), since DM_VERITY_FEC_BUF_PREALLOC is fixed at 1 and was already assumed to be 1 (considering that mempool_alloc() shouldn't be called in a loop). Signed-off-by: Eric Biggers --- drivers/md/dm-verity-fec.c | 41 ++++++++++++++++++++------------------ drivers/md/dm-verity-fec.h | 14 ++++++++----- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index bf533ffa7d56..7574e65c32ae 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -8,10 +8,22 @@ #include "dm-verity-fec.h" #include =20 #define DM_MSG_PREFIX "verity-fec" =20 +/* + * When correcting a data block, the FEC code performs optimally when it c= an + * collect all the associated RS blocks at the same time. As each byte is= part + * of a different RS block, there are '1 << data_dev_block_bits' RS blocks. + * There are '1 << DM_VERITY_FEC_BUF_RS_BITS' RS blocks per buffer, so that + * gives '1 << (data_dev_block_bits - DM_VERITY_FEC_BUF_RS_BITS)' buffers. + */ +static inline unsigned int fec_max_nbufs(struct dm_verity *v) +{ + return 1 << (v->data_dev_block_bits - DM_VERITY_FEC_BUF_RS_BITS); +} + /* * If error correction has been configured, returns true. */ bool verity_fec_is_enabled(struct dm_verity *v) { @@ -57,18 +69,10 @@ static u8 *fec_read_parity(struct dm_verity *v, u64 rsb= , int index, } =20 return res; } =20 -/* Loop over each preallocated buffer slot. */ -#define fec_for_each_prealloc_buffer(__i) \ - for (__i =3D 0; __i < DM_VERITY_FEC_BUF_PREALLOC; __i++) - -/* Loop over each extra buffer slot. */ -#define fec_for_each_extra_buffer(io, __i) \ - for (__i =3D DM_VERITY_FEC_BUF_PREALLOC; __i < DM_VERITY_FEC_BUF_MAX; __i= ++) - /* Loop over each allocated buffer. */ #define fec_for_each_buffer(io, __i) \ for (__i =3D 0; __i < (io)->nbufs; __i++) =20 /* Loop over each RS block in each allocated buffer. */ @@ -305,24 +309,23 @@ static int fec_read_bufs(struct dm_verity *v, struct = dm_verity_io *io, * Additional buffers are also allocated opportunistically to improve error * correction performance, but these aren't required to succeed. */ static struct dm_verity_fec_io *fec_alloc_and_init_io(struct dm_verity *v) { + const unsigned int max_nbufs =3D fec_max_nbufs(v); struct dm_verity_fec *f =3D v->fec; struct dm_verity_fec_io *fio; unsigned int n; =20 fio =3D mempool_alloc(&f->fio_pool, GFP_NOIO); fio->rs =3D mempool_alloc(&f->rs_pool, GFP_NOIO); =20 - memset(fio->bufs, 0, sizeof(fio->bufs)); - - fec_for_each_prealloc_buffer(n) - fio->bufs[n] =3D mempool_alloc(&f->prealloc_pool, GFP_NOIO); + static_assert(DM_VERITY_FEC_BUF_PREALLOC =3D=3D 1); + fio->bufs[0] =3D mempool_alloc(&f->prealloc_pool, GFP_NOIO); =20 /* try to allocate the maximum number of buffers */ - fec_for_each_extra_buffer(fio, n) { + for (n =3D 1; n < max_nbufs; n++) { fio->bufs[n] =3D kmem_cache_alloc(f->cache, GFP_NOWAIT); /* we can manage with even one buffer if necessary */ if (unlikely(!fio->bufs[n])) break; } @@ -460,16 +463,15 @@ void __verity_fec_finish_io(struct dm_verity_io *io) struct dm_verity_fec *f =3D io->v->fec; struct dm_verity_fec_io *fio =3D io->fec_io; =20 mempool_free(fio->rs, &f->rs_pool); =20 - fec_for_each_prealloc_buffer(n) - mempool_free(fio->bufs[n], &f->prealloc_pool); + static_assert(DM_VERITY_FEC_BUF_PREALLOC =3D=3D 1); + mempool_free(fio->bufs[0], &f->prealloc_pool); =20 - fec_for_each_extra_buffer(fio, n) - if (fio->bufs[n]) - kmem_cache_free(f->cache, fio->bufs[n]); + for (n =3D 1; n < fio->nbufs; n++) + kmem_cache_free(f->cache, fio->bufs[n]); =20 mempool_free(fio->output, &f->output_pool); =20 mempool_free(fio, &f->fio_pool); } @@ -732,11 +734,12 @@ int verity_fec_ctr(struct dm_verity *v) return -E2BIG; } =20 /* Preallocate some dm_verity_fec_io structures */ ret =3D mempool_init_kmalloc_pool(&f->fio_pool, num_online_cpus(), - sizeof(struct dm_verity_fec_io)); + struct_size((struct dm_verity_fec_io *)0, + bufs, fec_max_nbufs(v))); if (ret) { ti->error =3D "Cannot allocate FEC IO pool"; return ret; } =20 diff --git a/drivers/md/dm-verity-fec.h b/drivers/md/dm-verity-fec.h index b9488d1ddf14..84f8299673ff 100644 --- a/drivers/md/dm-verity-fec.h +++ b/drivers/md/dm-verity-fec.h @@ -17,13 +17,10 @@ #define DM_VERITY_FEC_MIN_RSN 231 /* ~10% space overhead */ =20 /* buffers for deinterleaving and decoding */ #define DM_VERITY_FEC_BUF_PREALLOC 1 /* buffers to preallocate */ #define DM_VERITY_FEC_BUF_RS_BITS 4 /* 1 << RS blocks per buffer */ -/* we need buffers for at most 1 << block size RS blocks */ -#define DM_VERITY_FEC_BUF_MAX \ - (1 << (PAGE_SHIFT - DM_VERITY_FEC_BUF_RS_BITS)) =20 #define DM_VERITY_OPT_FEC_DEV "use_fec_from_device" #define DM_VERITY_OPT_FEC_BLOCKS "fec_blocks" #define DM_VERITY_OPT_FEC_START "fec_start" #define DM_VERITY_OPT_FEC_ROOTS "fec_roots" @@ -50,14 +47,21 @@ struct dm_verity_fec { =20 /* per-bio data */ struct dm_verity_fec_io { struct rs_control *rs; /* Reed-Solomon state */ int erasures[DM_VERITY_FEC_MAX_RSN]; /* erasures for decode_rs8 */ - u8 *bufs[DM_VERITY_FEC_BUF_MAX]; /* bufs for deinterleaving */ - unsigned int nbufs; /* number of buffers allocated */ u8 *output; /* buffer for corrected output */ unsigned int level; /* recursion level */ + unsigned int nbufs; /* number of buffers allocated */ + /* + * Buffers for deinterleaving RS blocks. Each buffer has space for + * the data bytes of (1 << DM_VERITY_FEC_BUF_RS_BITS) RS blocks. The + * array length is fec_max_nbufs(v), and we try to allocate that many + * buffers. However, in low-memory situations we may be unable to + * allocate all buffers. 'nbufs' holds the number actually allocated. + */ + u8 *bufs[]; }; =20 #ifdef CONFIG_DM_VERITY_FEC =20 /* each feature parameter requires a value */ --=20 2.52.0 From nobody Thu Dec 18 23:21:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52A5333FE0E; Tue, 16 Dec 2025 23:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926420; cv=none; b=L/kdawQ0Gij0GFoOHsxgJCdBIBKjN5Vr5F4bOpcdRIPEbmQ/SG4UA2ygkHM83u9knwzctfUzJ2EFUyTAEBE5/2MAdLR+YfJ2w6vnkuY+1Phg5I3UllpAtWJtpW87JkoAsK4phKwbSrE6PmqXB7Qe3KPJR2W52bcKW6PVP7jLrJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926420; c=relaxed/simple; bh=SqhpEM8z1YTeqf/JpkPCTm09GUk75boOUOZMQKg9gY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W/v223sp28HM50aj+OhiVV442vXnyFABNQFxH6MCysYErVaa0Gg2w7vuoa6p4mL+x3ccVNmQLQIgPrIT8XrNbV7YmmF6gZZJnCNx4/U9dICLSO4xM3tIzkmW7PQOKZJQoFU/4JyVNZvuH7E6RzkmFPO9KABIn3LHCFAtqlXLUl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bj5TcJoG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bj5TcJoG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0E57C4CEF1; Tue, 16 Dec 2025 23:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765926419; bh=SqhpEM8z1YTeqf/JpkPCTm09GUk75boOUOZMQKg9gY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bj5TcJoGqZnq2dus3x1Pwvhi/fizO82QruYGlmI2qfFwKduxxbiK3f1wFt4k4dW8D 9CnXFZvIbJeQYSoSg8MEUi7eyW9VKLJnayYJkTCgs05T0iPEPhHzyYfEsxT8WttPB6 ihjWhdh1VFg3+cQXCxMtJFQDio09uij6qAp9CtW+FBkkyLC5ZdAC3/HHKdT/exHyml EI5+zjn5NDlpACgKtWx2RDHO05EQI62K3zU3wfY4XOnmzt4POs+Nwyo+MhIHKiz1GK 5Q59/1wL68s4R4F37CC1rmRQ+IHZBoPYRYfLXNSUwDDiTgc5KkPAp9OyQwGO0/E9XB N5LT/sHnoRJ5Q== From: Eric Biggers To: dm-devel@lists.linux.dev, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: Sami Tolvanen , Eran Messeri , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 3/7] dm-verity: remove unnecessary condition for verity_fec_finish_io() Date: Tue, 16 Dec 2025 15:06:10 -0800 Message-ID: <20251216230614.51779-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216230614.51779-1-ebiggers@kernel.org> References: <20251216230614.51779-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make verity_finish_io() call verity_fec_finish_io() unconditionally, instead of skipping it when 'in_bh' is true. Although FEC can't have been done when 'in_bh' is true, verity_fec_finish_io() is a no-op when FEC wasn't done. An earlier change also made verity_fec_finish_io() very lightweight when FEC wasn't done. So it should just be called unconditionally. Signed-off-by: Eric Biggers Reviewed-by: Sami Tolvanen --- drivers/md/dm-verity-target.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 5c17472d7896..c9f5602a42c6 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -617,12 +617,11 @@ static void verity_finish_io(struct dm_verity_io *io,= blk_status_t status) struct bio *bio =3D dm_bio_from_per_bio_data(io, v->ti->per_io_data_size); =20 bio->bi_end_io =3D io->orig_bi_end_io; bio->bi_status =3D status; =20 - if (!static_branch_unlikely(&use_bh_wq_enabled) || !io->in_bh) - verity_fec_finish_io(io); + verity_fec_finish_io(io); =20 if (unlikely(status !=3D BLK_STS_OK) && unlikely(!(bio->bi_opf & REQ_RAHEAD)) && !io->had_mismatch && !verity_is_system_shutting_down()) { --=20 2.52.0 From nobody Thu Dec 18 23:21:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC85633FE3A; Tue, 16 Dec 2025 23:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926420; cv=none; b=LABhVMVb3RmgtvobMQtlspQdDTv6QtW/VpOYH8d01vVeo4VNy86o5Ff0rmwu8H2y69T8kVW+zY1c5p2TiljhusrcWt5c8mu2sWNmqzB31FJ9rpGv+p1ow2+m7CXfaaVVrzXzMGbFvyCNrSmHzTHMq5QHTXjom5UqtkxNg71FEZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926420; c=relaxed/simple; bh=ii/pzsDkIuJnj07CZ5YWMIAJVOiHvCKyLJBcJQPA+KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SlXZamZswZThsX4C03jlqS7qP0YnSj/Ht3oNSp0yXXjwPa5T5UahJH6iqkpN1SnX7XvOqa0BNrJYj+iOHfzTnL/EnwUZkBSdW3hejk1isdKcOAkeABKtdcckO2Q+a0USmTQCiyHN6n7I3D/fu8oYZUFC/Hk3EXRA471JxbX2nCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tLqxWXqh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tLqxWXqh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FD14C19422; Tue, 16 Dec 2025 23:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765926420; bh=ii/pzsDkIuJnj07CZ5YWMIAJVOiHvCKyLJBcJQPA+KI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLqxWXqhhMKThx42HRHxsGpI0eDZQRAX+/wHNCrzV8iNEO75rmZboJjcAORI99kL3 kLvPPjlksAFHPgGEbyIQKsYJkFUeKPIv45FFOv1GzappzeehoHKjyYQXRWkTHPRekA 6gCTrAWcU+TIMmDJb6R56vpLblJ7EmZoALrohgGJlsI6fEB+4lfDKLgZjG7ZAZCwlr eWZ8bZOOpaweCwkDGysOM68XbeT4oK1dJp1pFI1LFyb6k1A9ivxQQqoxNPzT0IlRsL a6eVAnDR/B2pC5VqS2DKydGK5jpQ0iZ9AO6mDjILFMxhZUOGxHUmsB+W0ezNWUym5C HYftmqxBqcrfg== From: Eric Biggers To: dm-devel@lists.linux.dev, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: Sami Tolvanen , Eran Messeri , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 4/7] dm-verity: remove unnecessary ifdef around verity_fec_decode() Date: Tue, 16 Dec 2025 15:06:11 -0800 Message-ID: <20251216230614.51779-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216230614.51779-1-ebiggers@kernel.org> References: <20251216230614.51779-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since verity_fec_decode() has a !CONFIG_DM_VERITY_FEC stub, it can just be called unconditionally, similar to the other calls in the same file. Signed-off-by: Eric Biggers Reviewed-by: Sami Tolvanen --- drivers/md/dm-verity-target.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index c9f5602a42c6..777a0ebe8536 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -433,15 +433,13 @@ static int verity_handle_data_hash_mismatch(struct dm= _verity *v, if (verity_recheck(v, io, want_digest, blkno, data) =3D=3D 0) { if (v->validated_blocks) set_bit(blkno, v->validated_blocks); return 0; } -#if defined(CONFIG_DM_VERITY_FEC) if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_DATA, want_digest, blkno, data) =3D=3D 0) return 0; -#endif if (bio->bi_status) return -EIO; /* Error correction failed; Just return error */ =20 if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA, blkno)) { io->had_mismatch =3D true; --=20 2.52.0 From nobody Thu Dec 18 23:21:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CF02339B56; Tue, 16 Dec 2025 23:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926421; cv=none; b=u3FJFVrxterxat91P36GPCr28WzXoCpyuJLr1Z4U1bpbdk/6dJanVes6SAPFb9a350c44g8bFrOuk8KlZp0BROcY1aTmbmcJyRFnxpO+Hnt2TPWwI8ybC4MypbIDIlVxp5W7FJZt4rfDeCf1s2Sehaj3i0DHX+uz9FA0wq4jsUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926421; c=relaxed/simple; bh=4rOCzxv5aNWtsKAqZ0yqbsxZ5bMrwQ43Lj+0r+Efthc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZrjV/PFheSL5Dhi08H8eurvP4TVeA0QxPpgQWiOerva8Am7RjKBkqbO75Bm3g+nx0l6iQ0AYKW/w1csjfVYKKlTwOI6N5sbG0Rf6MCxUNtO2FABDHb17jEDajwU1j/uxf+EpEExQvjFLLNPrjCt3uVnk0RDs6atLKLDU6GoGWTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LtDXepCg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LtDXepCg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 929C5C19425; Tue, 16 Dec 2025 23:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765926420; bh=4rOCzxv5aNWtsKAqZ0yqbsxZ5bMrwQ43Lj+0r+Efthc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LtDXepCgFHTv1AqdX7AUyKdYf4YD5fc6pHUhRn0Kca6zEnHYH1jZM0/C/ZclMTH+I uQ4f6XD9RC80CbU+rQdKf/C+HRNNiRj8Bo5AP4LUbnS7zlONMVhXMON3u5rvVG4tUZ 0K8W94WT49xndr2Ri1QROMVLslr6TPpN7TC+efTmWjcUqZICPm3iKlzPXbnjLWtlLO XGCXtYwgz1IdmKvyXhCOXVe9//G5Smc/Fd/A0xy3Xy7eOVel1c/5UujJodwiEZx99T XM9el85ejXImTZ5tGdknrz3qtEEUSKJjlsvXOeXtdM9kf1w6XYVOemJB1XBgknzoAY zqdMklCGc2yXA== From: Eric Biggers To: dm-devel@lists.linux.dev, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: Sami Tolvanen , Eran Messeri , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 5/7] dm-verity: make verity_fec_is_enabled() an inline function Date: Tue, 16 Dec 2025 15:06:12 -0800 Message-ID: <20251216230614.51779-6-ebiggers@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216230614.51779-1-ebiggers@kernel.org> References: <20251216230614.51779-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" verity_fec_is_enabled() is very short and is called in quite a few places, so make it an inline function. Signed-off-by: Eric Biggers Reviewed-by: Sami Tolvanen --- drivers/md/dm-verity-fec.c | 8 -------- drivers/md/dm-verity-fec.h | 6 +++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index 7574e65c32ae..9bf93280cf33 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -20,18 +20,10 @@ static inline unsigned int fec_max_nbufs(struct dm_verity *v) { return 1 << (v->data_dev_block_bits - DM_VERITY_FEC_BUF_RS_BITS); } =20 -/* - * If error correction has been configured, returns true. - */ -bool verity_fec_is_enabled(struct dm_verity *v) -{ - return v->fec && v->fec->dev; -} - /* * Return an interleaved offset for a byte in RS block. */ static inline u64 fec_interleave(struct dm_verity *v, u64 offset) { diff --git a/drivers/md/dm-verity-fec.h b/drivers/md/dm-verity-fec.h index 84f8299673ff..a002cb5c96c5 100644 --- a/drivers/md/dm-verity-fec.h +++ b/drivers/md/dm-verity-fec.h @@ -65,11 +65,15 @@ struct dm_verity_fec_io { #ifdef CONFIG_DM_VERITY_FEC =20 /* each feature parameter requires a value */ #define DM_VERITY_OPTS_FEC 8 =20 -extern bool verity_fec_is_enabled(struct dm_verity *v); +/* Returns true if forward error correction is enabled. */ +static inline bool verity_fec_is_enabled(struct dm_verity *v) +{ + return v->fec && v->fec->dev; +} =20 extern int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, enum verity_block_type type, const u8 *want_digest, sector_t block, u8 *dest); =20 --=20 2.52.0 From nobody Thu Dec 18 23:21:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60C76340A43; Tue, 16 Dec 2025 23:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926421; cv=none; b=LC88BvYxEpnR2GsuMMI5AzVx/EWkz/msfow1OAit2Z5icMHy7kO9T/pOeQ0TJaErQ+No8tqCdNUgHN7KJ0wgRDGo8VignGm1ytwN+Z9izIdw+Nxkqrpuv0g/0kkmWOlEJQUTz9INcLlHcqc7KJbd7Cs6d/LMoDJBMFOFVBNH1jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926421; c=relaxed/simple; bh=trE6zxe2FEt8zzo/9pQ/qzrWtmL8xbEEnJ2pQ4Ti32w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R/R6eXFsIoBpk8FE9DYDenBXcG+a4Unty9UB46ZZd5HY7eiE8xqehda+3hD0oaMkrzUG9crd49yq7Uvmlu0dpjnDYlX+X95vTUT04t93Adha9UAJ2Mu9kcYVcfjCexY2uHZDjq+EuYPrPZ5k3if4fXVtnPm/c36gbR253WBchII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mzT6qM8r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mzT6qM8r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01D98C16AAE; Tue, 16 Dec 2025 23:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765926421; bh=trE6zxe2FEt8zzo/9pQ/qzrWtmL8xbEEnJ2pQ4Ti32w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mzT6qM8rw2RJCKFYMgfCLXeZQRNcWj+/PxNpYUFgiH4DxfuqIUprwuvqDtzaAQtXR 874EN4AC5SApcs4aIicsRguBc+GmNFhsfWSb7EbzaiQ7oQxPvyPh+BhrXalbRnTEvd hZi1g3+5DXAqUnUzpullvaHjxc4VxpManOrkdKObWq7vkkCII2MdwnUH1mZXDQ3z/c IpWFM3b4vJ0icAm27ALeP7Pcxif/+7YF88Xb1zdH74zKTzz8SHXRQws+XTbeTL5qUb A+F0Hm5iLBlCDxSliE92ykDfYVfaqR2dAaf7m9gjH42F1U/Vj5+YOuhZYwBRzlBQYl 63jszX7wkCGXQ== From: Eric Biggers To: dm-devel@lists.linux.dev, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: Sami Tolvanen , Eran Messeri , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 6/7] dm-verity: correctly handle dm_bufio_client_create() failure Date: Tue, 16 Dec 2025 15:06:13 -0800 Message-ID: <20251216230614.51779-7-ebiggers@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216230614.51779-1-ebiggers@kernel.org> References: <20251216230614.51779-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If either of the calls to dm_bufio_client_create() in verity_fec_ctr() fails, then dm_bufio_client_destroy() is later called with an ERR_PTR() argument. That causes a crash. Fix this. Fixes: a739ff3f543a ("dm verity: add support for forward error correction") Signed-off-by: Eric Biggers Reviewed-by: Sami Tolvanen --- drivers/md/dm-verity-fec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c index 9bf93280cf33..e8f1913f5f12 100644 --- a/drivers/md/dm-verity-fec.c +++ b/drivers/md/dm-verity-fec.c @@ -500,13 +500,13 @@ void verity_fec_dtr(struct dm_verity *v) mempool_exit(&f->rs_pool); mempool_exit(&f->prealloc_pool); mempool_exit(&f->output_pool); kmem_cache_destroy(f->cache); =20 - if (f->data_bufio) + if (!IS_ERR_OR_NULL(f->data_bufio)) dm_bufio_client_destroy(f->data_bufio); - if (f->bufio) + if (!IS_ERR_OR_NULL(f->bufio)) dm_bufio_client_destroy(f->bufio); =20 if (f->dev) dm_put_device(v->ti, f->dev); out: --=20 2.52.0 From nobody Thu Dec 18 23:21:39 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17CCB340A76; Tue, 16 Dec 2025 23:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926422; cv=none; b=OsmaHGTe8s/zTdNraNMZxRX1xVvv7xK9sXt+qQXjZRW+Pa61DLb17TnF6+KhlbZ2Oyauk3tYaDyCHIuQYOrlOsn18gepuNpkPg2kyyG42B5C5dP9ky/g/O7DLCGhIwgmEDJhdDbFH1vwpL6ksZsh4jp23kpZcYoXOeo6W7a1WbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765926422; c=relaxed/simple; bh=TePe5x8bc2SCbRZ9v/pRAuE0G51ZeD7YUoqCgC3LQ48=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QbM2HDdtoo/nEtfe5GSahjj2EcTxyo2zJaJEK9eKoK8+smxDZtG9zYqvuPCW4MstkPQ3rpTkviq5FEEBu5E+isHNQIvftaV/vGsXsjGz7YXIWVCjbYwIZYtytM6YEf7p037BZbkCXSM29zEuwkH3hVNk3FPGCzLy2aAgzK5PznI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jf+OSPkj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Jf+OSPkj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65E8BC113D0; Tue, 16 Dec 2025 23:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765926421; bh=TePe5x8bc2SCbRZ9v/pRAuE0G51ZeD7YUoqCgC3LQ48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jf+OSPkjYsWOffttmTCaFsgPSvn8S1UkZ0ZTWN7qhrUtFwtsE7KEaJI7He2rO7dpi eVBKwqrGnoDvrAdu6Z8Nov9Dp3GBV6AKUxIYfLWvBvuASgG/qssJnfUWCWdv5DegSU /vJf8SYDq+WBlFrMedeD8drUEiWPwL2Df+aFwCdN+N8tdN8S4emcvALs+Aaufc1TOW X1TrhfpWSp0ulyEtEfzTviJslWaKLLgTBNEKRiawhQ+gWGwXxKAvQ0ixUvrrb6jjhl DuD7sxcvse1MPBERmTRu+K/V579PUKXSewDUbl7l3BkQ2c5lXD5zRMEPG79JvXv1xu IJIK0WuD3cbkA== From: Eric Biggers To: dm-devel@lists.linux.dev, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: Sami Tolvanen , Eran Messeri , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 7/7] dm-verity: allow REED_SOLOMON to be 'm' if DM_VERITY is 'm' Date: Tue, 16 Dec 2025 15:06:14 -0800 Message-ID: <20251216230614.51779-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251216230614.51779-1-ebiggers@kernel.org> References: <20251216230614.51779-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The dm-verity kconfig options make the common mistake of selecting a dependency from a bool "sub-option" rather than the main tristate option. This unnecessarily forces the dependency to built-in ('y'). Fix this by moving the selections of REED_SOLOMON and REED_SOLOMON_DEC8 into DM_VERITY, conditional on DM_VERITY_FEC. This allows REED_SOLOMON to be 'm' if DM_VERITY is 'm'. Signed-off-by: Eric Biggers Reviewed-by: Sami Tolvanen --- drivers/md/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index 239c1744a926..c58a9a8ea54e 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig @@ -547,10 +547,12 @@ config DM_VERITY depends on BLK_DEV_DM select CRYPTO select CRYPTO_HASH select CRYPTO_LIB_SHA256 select DM_BUFIO + select REED_SOLOMON if DM_VERITY_FEC + select REED_SOLOMON_DEC8 if DM_VERITY_FEC help This device-mapper target creates a read-only device that transparently validates the data on one underlying device against a pre-generated tree of cryptographic checksums stored on a second device. @@ -596,12 +598,10 @@ config DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING If unsure, say N. =20 config DM_VERITY_FEC bool "Verity forward error correction support" depends on DM_VERITY - select REED_SOLOMON - select REED_SOLOMON_DEC8 help Add forward error correction support to dm-verity. This option makes it possible to use pre-generated error correction data to recover from corrupted blocks. =20 --=20 2.52.0