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 35F4480031 for ; Mon, 23 Nov 2026 15:38:08 +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 6ANFauA6021194; Mon, 23 Nov 2026 18:36:57 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ANFauA6021194 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1795448219; bh=akrfb/wBxvbjFOoEqejZOG8/3UMScnXCz5SEFMwLYjo=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=ace/uyMQRkOP96VI3WfpTy9xjwwSPg5WW25tCrPePwGnej00EAsE4QnVmHxgD6BF1 qqp2CCaQO9uOPOyr4lxApBAlxTargbdjhEhXY2W8lXVouCGrBBdEPvcb8lHMa5LufI 8xhFMRoelS6oz7T1O6OuRGpmLKcBvOAHhIUJ3DXagrV3JhKx5CWAQqIa8ga5qRdULQ reVXl0ntSxEAAwqRlzxje8eG+rjJ69ajMl7yTPlMxl4v5RCcZafoeFSmV0ybCT4wNN QLWpxMM7924A6fPJ74c4NgjPepzqzlcwwHVop12KMN7jwzG2c780/pejf7rSkT4VV5 X+xc0Zmfqd7Tg== Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6ANFamlH021141 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 23 Nov 2026 18:36:48 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ANFamlH021141 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="dZAdl45f" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a35e1d2dddso30537595e9.0 for ; Mon, 23 Nov 2026 07:36:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFfyffiDvMB5cDuwdk/YYfZfMrZqZaCqcePzC0Fkki/ngKpUMpp6BWoRg/Z7JqF0y4MejTaGQ==@openvz.org X-Gm-Message-State: APuU4Z8rYNaayV682Tjph2i44Pg9+sMAKmUX7mqmesCH4l1q/g6NZbRD cJUiPgwqh5zGJyl2QXWQLO5J2Rtl6enYEVExfgCfjghUdQcZrPs2kN2d0NhJjA8HQUWxH6Faoqh QyURe+yRkaqGWbRoLsJJWNPnx+hJimq1BUVJ4IuAG3vWNpb0sMoquOA== X-Gm-Gg: AZFdTZdWokbMRoitmgy50lzO+psAU+aBWQ9s3W8IuW/h7ZfKJepv7dSPG9VweUERH+Y B3D4P1t6GfnzVhASD1WpBBrCxMQaqMN/1UrUFD0fG4RvXaa/IR/sqQjrvfWq8xFY5YEwWFEFUV3 YWNLrTs+7c3XV9TsudOEwIefMXyvfF3xd45WE090ETVqSdOalEaJD5dFiBZ/xOeHIKfDhuo61Ij ov4/PozMgoCFP1LHPE8HMJKicut02yCR2bRNWFF++XUdcKDF9vOmiFIqp+S84kVXccdfi1L83tw xMOvq6wElA== X-Received: by 2002:a05:600c:1c21:b0:4bb:52bd:a3c7 with SMTP id 5b1f17b1804b1-4bb88804d41mr311270235e9.6.1795448208484; Mon, 23 Nov 2026 07:36:48 -0800 (PST) X-Received: by 2002:a05:600c:1c21:b0:4bb:52bd:a3c7 with SMTP id 5b1f17b1804b1-4bb88804d41mr311269725e9.6.1795448208050; Mon, 23 Nov 2026 07:36:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795448208; cv=none; d=google.com; s=arc-20260327; b=oGd53eNJHW1UkbRjDwPwi4dqjijV9KIVD91f48C9dCa40rYXivN2R37hsj5e1Sz/Ho yaiwXdnQXBvCuoQseb2Rw+NxdATAfv7y1Jkicw4R78c2CiowXDkF6WHtaWLL//Edb0bY zRWSrfIvkAKipbFwcmtZxa1KxJQSuDFRFVPtA4TH1EiBtz1y2iVVS3+OjKhJWp+TKvU1 HQQViywypTvHU1iZV9nJVDj0LBLnlsLaD3Ry8QWIEa1VYsx6SfH44ndaa+yyo/z4190Q 6iXvwKW7hOWlrp0tdU68Op+uoYoBxtyJTVsNIiqMK4TyfxymSQIaxHpkOTTQ588wGvkH i6jw== 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=PGreO9e2dz5J0WRKRangmaoFlwMNtnqX52ES6RLfUBo=; fh=PTCJiO6+nVD6F5dg6TrV6C+HUS0WkIoVep7tWSx0uMs=; b=Dw0/DDs8fsoWJtuLePzzDHazhEQn6D2bEgeFO+zz+Ebb6iDEh9f2tfmvK80h/PLVNW ZnYKi2unNDEtTXKZKrx3Pk3sutN9sGa9EEzZfBgWsAQ6s9i9Gtc0opOHrHSmutLiiNI1 4b6bGhD1OjEGDEVkkt/7fPVQIBRZE5SI1ljPpT6fbu/OA632XKzNnVj3nH/DrPcw+8XJ CsXmAbDIQK07KaTZGuUiwvWZAPMfO1ajmmSWN4/dKCs2mQvc0fvFF63a7cZbU7Qq7QiK /xh+AGurUW7MSjGJ0IUVXZoJAmyyYf5MI1LRn3USBVI3fz1H8JE1JJwq8I+RZKQrMtr5 nigw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=dZAdl45f; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:62d2:2eda:8655:4219 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 5b1f17b1804b1-4bb88787b94sor27308545e9.12.2026.11.23.07.36.48 for (Google Transport Security); Mon, 23 Nov 2026 07:36:48 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:62d2:2eda:8655:4219 as permitted sender) client-ip=2a06:5b06:b600:300:62d2:2eda:8655:4219; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=dZAdl45f; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:62d2:2eda:8655:4219 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=1795448207; x=1796053007; 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=PGreO9e2dz5J0WRKRangmaoFlwMNtnqX52ES6RLfUBo=; b=dZAdl45ffSr2GaDYJJ6gHfyBXtO49vs3tcd2jWa6MeDsHt4PW2WUjAAMNBCNXjmDy7 jYUk7pVA2MotSQpz7l0eVShsTPyYqVsCc0Difq1x5KbbD8UBQRzfARHQyLHYi38u7/Y4 Wwd1dmC3x9wOHesZ4ZBSyy/aHiFZ41PKC8RkiWoi8yf9qy+nZLiU//kEh01/nPE/Vm1r l6VLNVDikbKtQPNgKgvQp1ObwyrzXyp6H0d1rs2ZIFlbyGG5ugkb7LuG/kuze+/TeN+S E36OIeE6iFqoDF/Z+yS65jybqnObFxFJzdTjYHbaGUtOICa+oLyxf1TzMnqeGdujxmiI vudQ== X-Forwarded-Encrypted: i=1; AL+hErGdr+vQ5KfWlltwD9SHrMvAGLjizyOu3wQVku4u61cPn1ZqWKNqmQr3b2+m8cMj9hDuN64WqQ==@openvz.org X-Received: by 2002:a05:600c:4584:b0:4b8:4af2:88b3 with SMTP id 5b1f17b1804b1-4bb88817aa2mr244823715e9.22.1795448207559; Mon, 23 Nov 2026 07:36:47 -0800 (PST) Received: from artemis.sw.ru ([2a06:5b06:b600:300:62d2:2eda:8655:4219]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884b7515sm491797455e9.13.2026.11.23.07.36.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2026 07:36:47 -0800 (PST) From: "Denis V. Lunev" To: andrey.zhadchenko@virtuozzo.com, alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Mon, 23 Nov 2026 16:36:35 +0100 Message-ID: <20261123153640.128227-4-den@openvz.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261123153640.128227-1-den@openvz.org> References: <20261123153640.128227-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 3/8] dm-qcow2: fix queue_work() after the target or image is freed 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 qcow2_dispatch_qios(), qcow2_queue_resubmit() and md_page_write_complete() add a qio to a worker list under deferred_lock, drop the lock and only then queue the worker. Called from an image I/O completion, they let the worker take the qio in that gap and end it, and suspend and a dmsetup remove can then destroy tgt->wq before queue_work() runs on it. A backward merge has the same gap without a remove: qcow2_merge_backward_complete() frees the merged image, and with it the qcow2->worker that the late queue_work() uses. Queue the worker before dropping the lock, through a helper that asserts deferred_lock is held. The worker takes its lists under the same lock, so the qio, and the reference that keeps the target, outlive the queue_work() call. Do the same in qcow2_submit_embedded_qio(), where only the pattern changes: its qios belong to DM requests, and its timer and merge callers are stopped before the target is destroyed. 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-map.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 2227e06591e9..397738351b07 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -447,6 +447,14 @@ static void qcow2_dispatch_qio(struct qcow2 *qcow2, struct qio *qio) list_add_tail(&qio->link, &qcow2->qios[qio->queue_list_id]); } +/* Queued before deferred_lock drops, so the published qio pins tgt */ +static void qcow2_queue_work_locked(struct qcow2 *qcow2, + struct work_struct *work) +{ + lockdep_assert_held(&qcow2->deferred_lock); + queue_work(qcow2->tgt->wq, work); +} + void qcow2_dispatch_qios(struct qcow2 *qcow2, struct qio *qio, struct list_head *qio_list) { @@ -463,9 +471,8 @@ void qcow2_dispatch_qios(struct qcow2 *qcow2, struct qio *qio, qcow2_dispatch_qio(qcow2, qio); } + qcow2_queue_work_locked(qcow2, &qcow2->worker); spin_unlock_irqrestore(&qcow2->deferred_lock, flags); - - queue_work(qcow2->tgt->wq, &qcow2->worker); } static void end_qios(struct list_head *qio_list, blk_status_t status) @@ -1584,8 +1591,8 @@ static void md_page_write_complete(struct qio *qio) qio->queue_list_id = QLIST_COMPLETED_WB; spin_lock_irqsave(&qcow2->deferred_lock, flags); list_add_tail(&qio->link, &qcow2->qios[QLIST_COMPLETED_WB]); + qcow2_queue_work_locked(qcow2, &qcow2->fsync_worker); spin_unlock_irqrestore(&qcow2->deferred_lock, flags); - queue_work(qcow2->tgt->wq, &qcow2->fsync_worker); } static void submit_rw_md_page(unsigned int rw, struct qcow2 *qcow2, @@ -3013,8 +3020,8 @@ static void qcow2_queue_resubmit(struct qio *qio) spin_lock_irqsave(&qcow2->deferred_lock, flags); list_add_tail(&qio->link, &qcow2->resubmit_qios); + qcow2_queue_work_locked(qcow2, &qcow2->worker); spin_unlock_irqrestore(&qcow2->deferred_lock, flags); - queue_work(qcow2->tgt->wq, &qcow2->worker); } static void data_rw_complete(struct qio *qio) @@ -4706,7 +4713,6 @@ static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio) struct work_struct *worker; struct qcow2 *qcow2; unsigned long flags; - bool queue = true; qcow2 = qcow2_ref_inc(tgt, &ref_index); @@ -4723,17 +4729,14 @@ static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio) if (unlikely(qcow2->pause_submitting_qios)) { qcow2_ref_dec(tgt, ref_index); list_add_tail(&qio->link, &qcow2->paused_qios); - queue = false; } else { qio->qcow2 = qcow2; qio->queue_list_id = queue_list_id; qio->ref_index = ref_index; list_add_tail(&qio->link, &qcow2->qios[qio->queue_list_id]); + qcow2_queue_work_locked(qcow2, worker); } spin_unlock_irqrestore(&qcow2->deferred_lock, flags); - - if (queue) - queue_work(tgt->wq, worker); } void qcow2_submit_embedded_qios(struct qcow2_target *tgt, struct list_head *list) -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel