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 A446D80031 for ; Wed, 25 Nov 2026 01:27:00 +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 6AP1PkHl002570; Wed, 25 Nov 2026 04:25:47 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP1PkHl002570 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1795569948; bh=RLh7iRP5yfVNX7b8GAobtyrjj3x0+/CPyki0PZkHJCU=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=JMqZIGd5xY4lq+IigmaYIp4iPTYIoZaQFWS9emD4tTV01+eCsM1cyJLs/3o7sElgl sNmYAcYy7EYil25T5j7Q2o7pf9ffvG5xOs9T1vEn3FifQuoRni/DNcWNiwO3mQaksR TMYWS8QtP9XOzGsAvy0C+Bd6O+Wd7tWLEDCVGXdqp5zUEVAhdF2JlQ8Kb2XIbFjO98 KodEDYfN3lgufUGVlrULZezmqdzXZc06EGY3b8EstrnY8t/HxCx7vOG4r9drEstfep PG3vjwKGAisp+dIY34syf1S1+s3NzPASDQzLT9x5GXOKvySySn/Bo1Cc1P59F7NZM+ 1mOM3dfBijE+A== 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 6AP1PahX002496 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 04:25:36 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP1PahX002496 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="HNAqIs/I" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4bb66fc3aa6so44730215e9.2 for ; Tue, 24 Nov 2026 17:25:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFZCrcIX9vvThNjLQyYvFqk5H4TgG4Kh303zB7wdGIIcpritPE6CVUOwW/S1g3e+7YO93BKqw==@openvz.org X-Gm-Message-State: APuU4Z+tu9eCyHrelYzpXGGKHeWGfJXgkhSaYK2hm3po/NuEzIJ/pFn/ lmrbOoXll9IVeVcZYcHFOy/R1lAV1hZpfZtG7LlQnH57sqliqG7LgUzpbUeoR8U09xrIbkjd/WP RXH3O0aHXcyXFztodyNCgD6Q3AzYHXZ0HrxEzCLw34Dtg3yyI56OUDA== X-Gm-Gg: AZFdTZf55YdU8UrBTK0PRCTvdHVrRpBWw6o8m9WkUqAuG4EGxT/btEZdBLZn28X3yZy bRyxiMUnDfAP4hH7JJ2SLy5kKsMMfYzqlb7QEapDbYBK3pjUgfCb49ZP56yKt/l1TKY1ZYfA/Tg IFysHFV2iC9k8OpqsAlGl4u9bRpQiYmOAfwOmX32upY6xMKitNMc6oOvQH1duynrmSyUShoDr4y bzvD380wD5Ey8W932WqNpZdgHLe7yv8OOearPt3f4bREwoSYw2udTTkH85+2pIRV5ccnWUaRE0u H7MbaJQS/A== X-Received: by 2002:a05:600c:3b8c:b0:4b7:6c16:7b43 with SMTP id 5b1f17b1804b1-4bb8881d019mr326280295e9.10.1795569936304; Tue, 24 Nov 2026 17:25:36 -0800 (PST) X-Received: by 2002:a05:600c:3b8c:b0:4b7:6c16:7b43 with SMTP id 5b1f17b1804b1-4bb8881d019mr326280145e9.10.1795569935966; Tue, 24 Nov 2026 17:25:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795569935; cv=none; d=google.com; s=arc-20260327; b=AnW5O5F6Ha4l/YOGQiowu0kxi0PHFj8qrSvDZyVyH/t1vzdOcwg5fD9KQb4CR9vsLC h2iTc6Zo74U3LIIvT3GG7B2lj7EeTOBT3oFT1NEZMqVcAnMnTfiSwFV7eoA3I4QsjFPi nx0ZEWk78x0RrZBm7zs4zBvJVLfsJB0uNYbjRqPvabydsGaUvJT6nKHdV4W5ert/vfKZ 0EFfyeAaIKgV79xUX+Mt3u9hF708euSSGlC6Sr9Zb9tKgD09AX1QP8b15bf0yBLuMN+0 Px6y0FvU/PPXwvx67db9fQTUOuUtrAtP0W0pGew3kMBPtRQe5GgUFm/1KfEVXze7KN2s 58/A== 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=Tiehdg4IHkQxAg8YGfHyAQ1E8pN1hmHUvcLfb1TErMY=; fh=dDAfY8NE/As74onrR5B9hut/R1NK1o3/LlFG9/muJFg=; b=dIYTrDUjjBAvSBoyZhPz4c0CwbEtWrWfSLKmvVejvXW+pmZx8UmmDUV+D88XfJtVBR qoHPE1T3SlAu7R4ZDruGuQoTJ/ZfpdYlrDfxchcJAf/awURi6JUMIMl1cOeVuuo2mhip eWASfFlzQrAQW9jj+i7i7iSN0RHcOwogaTBXV8Q1g+6lAUCvmrXZiwhMaRYm8bzNM20a gqUimPth2yaysYmhwHMAPEhecrSZpP7xUpnYwt7vGk+5kotb/mOf1YvAT+blHkOMufU5 whPx8gQxS6SDArNXP8wwWc8Uy/fmuOjWLdFHUKaQgFIuCO53BLxAvUeF/Z+0Nj1tlZLW wmTg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b="HNAqIs/I"; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:fc:665c:9984:4e97 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-4bb884ddc9csor30714155e9.17.2026.11.24.17.25.35 for (Google Transport Security); Tue, 24 Nov 2026 17:25:35 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:fc:665c:9984:4e97 as permitted sender) client-ip=2a06:5b06:b600:300:fc:665c:9984:4e97; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b="HNAqIs/I"; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:fc:665c:9984:4e97 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=1795569935; x=1796174735; 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=Tiehdg4IHkQxAg8YGfHyAQ1E8pN1hmHUvcLfb1TErMY=; b=HNAqIs/IN/lIjNaQUOIiVy8iHOVJB+j4kixav05KPqZb+LkKCun2qecWtQLpeuDq6W +DXmXsDEeJI5Cp0PhA2HI7HE4lMrltc74d4fiIcmMb4UnpdtCeNbOdoZ0TnjwcYCGPIA 49wp3FISW/81msa6UxyMwI/7yxWh4w4PXvf+S/THRlnXwxlbYy/JrqB/E1qv6mDPt4t3 9WU3f7BZwVycuTMGclnsM9G/Xj83S9an8Wy1+PpHDjww3m3fKytiKYVVOu8Yj+OqGeg8 e8xSC1ozPdb9uMzcm1IpRBbV48XKvTRMVslC+aIPeipGtQte+iSfXsBS17eYTsaNH1cz rMIg== X-Forwarded-Encrypted: i=1; AL+hErE/uMdSAVdOhq+fv7QB4m90ZVTzVJdmACrNVa6Q5aFuZ5RME83f8W61n9iQ3hRpqPjJAClfMw==@openvz.org X-Received: by 2002:a05:600c:8b83:b0:4bb:60da:56af with SMTP id 5b1f17b1804b1-4bb8893053dmr294630375e9.25.1795569935572; Tue, 24 Nov 2026 17:25:35 -0800 (PST) Received: from artemis.sw.ru ([2a06:5b06:b600:300:fc:665c:9984:4e97]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb8526cbd0sm623632195e9.0.2026.11.24.17.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 17:25:34 -0800 (PST) From: "Denis V. Lunev" To: andrey.zhadchenko@virtuozzo.com, alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Wed, 25 Nov 2026 02:25:21 +0100 Message-ID: <20261125012525.681662-6-den@openvz.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261125012525.681662-1-den@openvz.org> References: <20261125012525.681662-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 5/9] dm-qcow2: submit fast path qios without deferred_lock 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_submit_embedded_qio() takes deferred_lock for every request only to check pause_submitting_qios: an embedded qio is put on no list under the lock, it goes to the per-cpu fast path list. With metadata parsing off md_pages_lock, this is the next lock all submitting CPUs share. Check the pause without the lock. A submitter holds an inflight_ref reference before it looks at the flag: - one that misses a pause holds a reference of the old index, which set_backward_merge_in_process() waits for in qcow2_inflight_ref_switch(). qcow2_ref_inc() takes it inside rcu_read_lock(), so it either lands before the grace period of percpu_ref_kill() ends and is waited for, or the tryget fails and the submitter retries on the new index; - one that gets a reference of the new index must see the pause, so order the flag before the index switch with smp_wmb(), paired with the smp_rmb() in qcow2_ref_inc(); - one that sees the pause cleared must see the new backward_merge_in_process, so clear it with release semantics and read it with acquire. A paused or flush qio still takes the lock and the old path. https://virtuozzo.atlassian.net/browse/VSTOR-95494 Feature: dm-qcow2: block device over QCOW2 files driver Signed-off-by: Denis V. Lunev --- drivers/md/dm-qcow2-cmd.c | 10 ++++++++-- drivers/md/dm-qcow2-map.c | 36 +++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c index 00b33ccaab10..02c0e0d8104e 100644 --- a/drivers/md/dm-qcow2-cmd.c +++ b/drivers/md/dm-qcow2-cmd.c @@ -160,15 +160,21 @@ static void set_backward_merge_in_process(struct qcow2_target *tgt, * qios of the top one, so stop the top image even then. */ spin_lock_irq(&top->deferred_lock); - top->pause_submitting_qios = true; + WRITE_ONCE(top->pause_submitting_qios, true); spin_unlock_irq(&top->deferred_lock); + /* + * A submitter that gets a reference of the new inflight_ref index + * must see the pause. Pairs with smp_rmb() in qcow2_ref_inc(). + */ + smp_wmb(); qcow2_inflight_ref_switch(tgt); /* queue is stopped */ spin_lock_irq(&top->deferred_lock); WARN_ON_ONCE(qcow2->backward_merge_in_process == set); qcow2->backward_merge_in_process = set; - top->pause_submitting_qios = false; + /* A submitter that sees the pause gone sees the new merge state */ + smp_store_release(&top->pause_submitting_qios, false); list_splice_init(&top->paused_qios, &list); spin_unlock_irq(&top->deferred_lock); diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 9d68d713ec3b..17487f52c33e 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -266,7 +266,11 @@ struct qcow2 *qcow2_ref_inc(struct qcow2_target *tgt, u8 *ref_index) rcu_read_lock(); do { *ref_index = tgt->inflight_ref_index; - smp_rmb(); /* Pairs with qcow2_merge_backward() */ + /* + * Pairs with qcow2_merge_backward_complete() and + * set_backward_merge_in_process() + */ + smp_rmb(); qcow2 = tgt->top; ref = &tgt->inflight_ref[*ref_index]; } while (unlikely(!percpu_ref_tryget(ref))); @@ -4849,6 +4853,16 @@ static void init_qrq_and_embedded_qio(struct qcow2_target *tgt, struct request * qio->endio_cb_data = qrq; } +static void prepare_submitted_qio(struct qio *qio, struct qcow2 *qcow2, + u8 queue_list_id, u8 ref_index) +{ + qio->qcow2 = qcow2; + qio->queue_list_id = queue_list_id; + qio->ref_index = ref_index; + if (queue_list_id == QLIST_EMBEDDED) + qio->state = QIO_STATE_START; +} + static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio) { struct qcow2_rq *qrq = qio->endio_cb_data; @@ -4870,18 +4884,26 @@ static void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio) worker = &qcow2->fsync_worker; } + /* + * A submitter that misses a concurrent pause holds a reference of + * the old inflight_ref index, which the pause waits for. Pairs with + * smp_store_release() in set_backward_merge_in_process(). + */ + if (queue_list_id == QLIST_EMBEDDED && + likely(!smp_load_acquire(&qcow2->pause_submitting_qios))) { + prepare_submitted_qio(qio, qcow2, queue_list_id, ref_index); + qcow2_fast_submit(tgt, qio); + return; + } + spin_lock_irqsave(&qcow2->deferred_lock, flags); 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; - if (queue_list_id == QLIST_EMBEDDED) - qio->state = QIO_STATE_START; - else + prepare_submitted_qio(qio, qcow2, queue_list_id, ref_index); + if (queue_list_id != QLIST_EMBEDDED) list_add_tail(&qio->link, &qcow2->qios[qio->queue_list_id]); } spin_unlock_irqrestore(&qcow2->deferred_lock, flags); -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel