From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id C65C28002A for ; Thu, 19 Nov 2026 11:50:32 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJBnMaT021489; Thu, 19 Nov 2026 14:49:22 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJBnMaT021489 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1795088963; bh=GMriqSVaI6RC6xtDHxIxVAX4z07limSGRp+dDvMYqRU=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=c2LlFjpGkaALJZIrEfOQvaAVliEyoGFw0XRXZNEVD6fSlTdLdbkmhELGmBD/a9hVR Lh9zK4FujChSBtbaupC90U4HdUDPL2zdoA9RIfBDuQ4WIwEblTj54D+QvXnoifEn4t YgdMqZQwNjkxJ9ykttaZj3FIarta0fy3/wnJOaueYhB4EtQg2E5KrYQOIevbV3OD03 XCwWBXKQadRGTd1exPSvhwHxYHAwNydNarA9KB4VSX3f8LOlX9R1F9kw1STtqhryZ/ OUOwPaJPLLRflALmcMrXoZpvx54pN1HyAWcEhwYKDJ7GbcSupGqMUtxMtkrOzWcM35 4kye9SnS60RJg== Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJBnId5021465 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 14:49:19 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJBnId5021465 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="ljYPoN0X" Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4925ef75fc4so1634055f8f.1 for ; Thu, 19 Nov 2026 03:49:19 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGSnvCdTIeFmNWkqWvFCuodQoQYDbCwgLO7rSHU99PgC1aeof/r8acccsTe58FSi9/jM3OXyA==@openvz.org X-Gm-Message-State: APuU4Z/20wzAGzkY5nsoNtlCF4fL4MPtluALHCBBKc0m1RovVKFMR6Rp EqqQBOKjmQ67QpHAt9PLiarkvfO9KJ5D9fkpY4YS2yQW3uImr+zayzfG1LqVNhycQ5Vq4dp50kZ aONTd8VhmcI40fm6/MRKM973vj46n6J8y97T5455WXrbT0htbw/XTVw== X-Gm-Gg: AZFdTZcujaW/nQtqQizG7syA6iK5WWyYTFpYjNQJgT1nyBkixtgfEsTHBcrjmvj6kg/ rHlXGrNM/URBYUXRTo83wunVIdi1/qbx4q948hqQNwSpNRevHTfOYQ6SwL48WJuIAA6UB29oUA/ dBJ+0icX033aBRi+kpAFf3nSmUSu/cOcau6Qdcu77i9Lyfa61W4cgUQlgodUprHcQYWF5peGtQW dJPR/jTnlet/qyisS69Q5CFbR3qZh2ow0EptO18R6JjAR7ScypUrl9bTj9K5LihtmSCY7vq0KOT GXDNTWKb/w== X-Received: by 2002:a05:6000:240c:b0:4aa:8396:96c with SMTP id ffacd0b85a97d-4aa839609f6mr1687662f8f.33.1795088958679; Thu, 19 Nov 2026 03:49:18 -0800 (PST) X-Received: by 2002:a05:6000:240c:b0:4aa:8396:96c with SMTP id ffacd0b85a97d-4aa839609f6mr1687623f8f.33.1795088958245; Thu, 19 Nov 2026 03:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795088958; cv=none; d=google.com; s=arc-20260327; b=DIgTcuMOggIClzl5D22GdrKZro6LUnQcEJMh8hSqJ6PSWOmihAEkmFkPx+ZrdvPbEN Mo8SlO76+nIlUmYATxXM08th/MGj8dWt2/BaWdLe12fsRhn0hdBJ5H4alHzooxxJqOZG d5UOzySHyfPMzLuIbl7o+xVSzDfNW0NIpLVxSH95yZ5u5Dkf0REuIop1BZ8vxRE2rFWa wUo9V3yOyG05m3fM5hF7rqF2XJDJvDM6ywZ6olpAz9fQOt/b/LAj2qgPL8ZH83FjlAuO wWFIgDLLlT5wz4Rv8lYwjHxsuA6LBKyqEPA1yRZqHHP6HIWPQPDFTOZh27kq/PMPxCMO Zh4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=n4ylA9V7lNaC+kzYlLg398ehrYJRp/myOANbYeza5o4=; fh=93/yALTjmvG5iVIiu1lYQkzj/jhQyg3qR5zV2pMkpTA=; b=HhgbJQ+hCu+koPrV32swwf77W4eFj4bv17xcjUem9Y0AndjmjwHn6u3fwxc3ZXm1fc 6cnIPtGK4XnIoQ0IqG0fNMt0nMx/tuoxedctzZHSceCHHxYUDy1CDG+xYRpD2NJaOMhe TzlE0kwpphm6DIT9AgywN4VkF6Jo1plCmDmqVtNOWPW10zJH0xLXgUxsECe0oX2U0jUA Jahb/chI0ldb+rbhxZXLOK/70/phrvcyYMenL+eHsP2jmsyOmvROzCcdEfS+7Z5C8l5r M5wZXb4D2OOvHqTHQ3TFCbE9uj9WMahXoizj3QnzhTv/ciI05atPPm8HNo1w2zzFaDYi CPbg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=ljYPoN0X; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:989f:a206:d03d:c3d5 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-4a8a9c21ad2sor701962f8f.1.2026.11.19.03.49.18 for (Google Transport Security); Thu, 19 Nov 2026 03:49:18 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:989f:a206:d03d:c3d5 as permitted sender) client-ip=2a06:5b06:b600:300:989f:a206:d03d:c3d5; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=ljYPoN0X; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:989f:a206:d03d:c3d5 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1795088958; x=1795693758; darn=openvz.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=n4ylA9V7lNaC+kzYlLg398ehrYJRp/myOANbYeza5o4=; b=ljYPoN0XuzafkZ/aYw0+CsdlBXmAD0kfKLRwnCwGJ/ol6SFssv2NKH+BbfgkpXuwJ8 /6h1Y2NW2fUWIi5fwU3+7O4LX/dV4vaJ3BSw1NpaaS6MkwTX7qPUuUt60oqRZHYzVGjN 8FXxdocS2MIkOP0Lz4DRPNAecJRodXMbjgX3qwcsDECAAxVlZFne79TXkZK0QYk4rd9c 5qipCY69cu2X4lDFMlOMqEQfs5rDqmBZ5Y+5E+6fiOdTxd6Ay8Dt7al9u80le2RtopXn jmpHp0p/hc5WWM7a6HhWhgkVsr2BXBNcC1GXzKdXF6QrFyEYxJlS56s3g23y9Hvyy0PT fRVA== X-Forwarded-Encrypted: i=1; AL+hErGy03RHG/Q4hD2WhdiV/JkOPwAbZlKDzowbw505mIBRfugLFFeU0JGtGPyfh9O4R8xSl63SZQ==@openvz.org X-Received: by 2002:a05:6000:240c:b0:4aa:8396:96c with SMTP id ffacd0b85a97d-4aa839609f6mr1687572f8f.33.1795088957718; Thu, 19 Nov 2026 03:49:17 -0800 (PST) Received: from artemis.sw.ru ([2a06:5b06:b600:300:989f:a206:d03d:c3d5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a65560b1ddsm9973486f8f.28.2026.11.19.03.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 03:49:17 -0800 (PST) From: "Denis V. Lunev" To: alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Thu, 19 Nov 2026 12:49:13 +0100 Message-ID: <20261119114914.767536-2-den@openvz.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261119114914.767536-1-den@openvz.org> References: <20261119114914.767536-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 1/2] dm-qcow2: fix image I/O completions running on a freed target X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Denis V. Lunev Nothing keeps the qcow2 target alive while an image file I/O completion runs. Suspend waits only for the inflight references, and a completion can end the qio that holds the last one and then still use the target: - a qio freed on endio that holds no reference of its own goes into tgt->qio_pool after its callback has ended its owner, e.g. a split qio after its parent, or a COW, compressed read or merge helper qio; - a metadata page read drops its own reference and then frees its qio into tgt->qio_pool. These run in the completion context of the backing file system, which dm-qcow2 does not own, and a dmsetup remove in that window destroys the pool under them. Take a percpu reference in qcow2_call_rw_iter() for every image file I/O and drop it after the completion handler returns. qcow2_tgt_destroy() kills it once nothing can submit and waits for the last completion before it frees the pools. The wait comes after destroy_workqueue(), because the drained worker may still submit image I/O. 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 --- drivers/md/dm-qcow2-target.c | 25 +++++++++++++++++++++++++ drivers/md/dm-qcow2.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c index 2f792d823e7b..2394e9d8ad3b 100644 --- a/drivers/md/dm-qcow2-target.c +++ b/drivers/md/dm-qcow2-target.c @@ -108,9 +108,12 @@ static bool should_fail_rw(struct qcow2 *qcow2) static void qcow2_aio_do_completion(struct qio *qio) { + struct qcow2_target *tgt = qio->qcow2->tgt; + if (!atomic_dec_and_test(&qio->aio_ref)) return; qio->complete(qio); + percpu_ref_put(&tgt->file_io_ref); } static void qcow2_aio_complete(struct kiocb *iocb, long ret) @@ -133,6 +136,7 @@ void qcow2_call_rw_iter(struct qcow2 *qcow2, loff_t pos, unsigned int rw, iocb->ki_pos = pos; iocb->ki_complete = qcow2_aio_complete; + percpu_ref_get(&qcow2->tgt->file_io_ref); atomic_set(&qio->aio_ref, 2); if (unlikely(should_fail_rw(qcow2))) @@ -258,9 +262,13 @@ static void qcow2_tgt_destroy(struct qcow2_target *tgt) cancel_work_sync(&tgt->event_work); qcow2_merge_backward_cancel(tgt); + percpu_ref_kill(&tgt->file_io_ref); + wait_for_completion(&tgt->file_io_comp); + mempool_destroy(tgt->qio_pool); mempool_destroy(tgt->qrq_pool); + percpu_ref_exit(&tgt->file_io_ref); for (i = 0; i < 2; i++) percpu_ref_exit(&tgt->inflight_ref[i]); @@ -501,6 +509,14 @@ static void qcow2_event_work(struct work_struct *ws) dm_table_event(tgt->ti->table); } +static void file_io_ref_release(struct percpu_ref *ref) +{ + struct qcow2_target *tgt = container_of(ref, struct qcow2_target, + file_io_ref); + + complete(&tgt->file_io_comp); +} + static struct qcow2_target *alloc_qcow2_target(struct dm_target *ti) { percpu_ref_func_t *release; @@ -537,6 +553,15 @@ static struct qcow2_target *alloc_qcow2_target(struct dm_target *ti) } } + init_completion(&tgt->file_io_comp); + if (percpu_ref_init(&tgt->file_io_ref, file_io_ref_release, 0, + GFP_KERNEL)) { + for (i = 0; i < 2; i++) + percpu_ref_exit(&tgt->inflight_ref[i]); + ti->error = "could not alloc percpu_ref"; + goto out_wq; + } + init_completion(&tgt->inflight_ref_comp); spin_lock_init(&tgt->event_lock); mutex_init(&tgt->ctl_mutex); diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h index 3f1d5b5eef26..411d9a6eb04d 100644 --- a/drivers/md/dm-qcow2.h +++ b/drivers/md/dm-qcow2.h @@ -202,6 +202,8 @@ struct qcow2_target { struct completion inflight_ref_comp; struct percpu_ref inflight_ref[2]; + struct completion file_io_comp; + struct percpu_ref file_io_ref; unsigned int inflight_ref_index:1; bool service_operations_allowed; -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel