[Devel] [PATCH hci-8.2 v2 2/8] dm-qcow2: fix do_qio_endio() freeing a qio into a destroyed pool
Denis V. Lunev
den at openvz.org
Mon Nov 23 18:36:34 MSK 2026
From: Denis V. Lunev <den at openvz.org>
do_qio_endio() calls the endio callback, drops the qio's inflight
reference and only then frees a QIO_FREE_ON_ENDIO_FL qio into
tgt->qio_pool. Either of the first two can end the last user of the
target: a split qio's callback completes its parent request, whose
reference goes, and a metadata page read drops its own reference.
Suspend then finishes, and a dmsetup remove destroys the pool before
the free runs from the backing file system's completion context, which
oopses in mempool_free().
Free the qio first, then call the callback, then drop the reference,
so that nothing touches the target after the last of them. Read the
qio's fields once its last completion has arrived, as children write
the status of their parent up to then.
https://virtuozzo.atlassian.net/browse/VSTOR-156036
Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
drivers/md/dm-qcow2-map.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 90e699050131..2227e06591e9 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -405,25 +405,30 @@ static void qcow2_free_qio(struct qio *qio, mempool_t *pool)
static void do_qio_endio(struct qio *qio)
{
- struct qcow2 *qcow2 = qio->qcow2;
- struct qcow2_target *tgt = qcow2->tgt;
- qcow2_endio_t endio_cb = qio->endio_cb;
- void *endio_cb_data = qio->endio_cb_data;
- unsigned int flags = qio->flags;
- u8 ref_index = qio->ref_index;
+ struct qcow2_target *tgt;
+ qcow2_endio_t endio_cb;
+ blk_status_t bi_status;
+ void *endio_cb_data;
+ u8 ref_index;
if (!atomic_dec_and_test(&qio->remaining))
return;
+ tgt = qio->qcow2->tgt;
+ endio_cb = qio->endio_cb;
+ endio_cb_data = qio->endio_cb_data;
+ bi_status = qio->bi_status;
+ ref_index = qio->ref_index;
qio->ref_index = REF_INDEX_INVALID;
- /* Note, that this may free qio or its container memory */
- if (endio_cb)
- endio_cb(tgt, endio_cb_data, qio->bi_status);
+ /* The callback and the ref drop may end the last user of tgt */
+ if (qio->flags & QIO_FREE_ON_ENDIO_FL)
+ qcow2_free_qio(qio, tgt->qio_pool);
+ /* Note, that this may free qio's container memory */
+ if (endio_cb)
+ endio_cb(tgt, endio_cb_data, bi_status);
if (ref_index < REF_INDEX_INVALID)
qcow2_ref_dec(tgt, ref_index);
- if (flags & QIO_FREE_ON_ENDIO_FL)
- qcow2_free_qio(qio, tgt->qio_pool);
}
static void qio_endio(struct qio *qio)
--
2.55.0
More information about the Devel
mailing list