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 35E918045D for ; Tue, 3 Nov 2026 08:09:54 +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 6A388f1A002204; Tue, 3 Nov 2026 11:08:42 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A388f1A002204 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="l6uZ0ERV" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A388Jfp002155 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 3 Nov 2026 11:08:19 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A388Jfp002155 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48dff112181so3388408f8f.3 for ; Tue, 03 Nov 2026 00:08:19 -0800 (PST) X-Gm-Message-State: APuU4Z8nroGranS8jamEbKcYcLGUpD+70y/MwHIeQOPs2W4wHsEkMfl7 imvxgazobmlImlipe58yVhuzs0iNcpZEjtFMwqp2ZZB4tt08vSQ3C125QC4pOYSSUvNsl5x6kng /tLeOsib6DZ4Pja/amdeRoDF8SqHlh0cjTUlVI+DW3E/pAvEk8Tl24g== X-Gm-Gg: AYBFou3S7BAZkIPo74Ct/z+H3a/Oozu2kJRGZEudtonpEuIFgo3x0w28NSNdd7w+qf9 /qJ4qQ/voQSszj+tTrE/ST9RdmVZf3Dw6UnmbAU7EmqjAFBw+StPvGgLvXFUHsyROCvKFHPw7XC m8qKjZf1oWoZzc2GTJP7XcmgFCwBwgZ74VAjPQS4MjPOUgE3hIVaUgS9nBxWbykM/REN1fJOAGr 0sLTSs5iAgDecNz7O0RaBZ/3pvxVQyOHXiMU46XhnOR9nMnue0mJ3pxWhgCpvsx4otWkbp07LAf VmHaJPXoCphWND0KvbPH6WyEO+Y0i7xkLGQm6yx9eigfdEnUX8f4nywmDd8Oqe6QF+dJbgzv4JB F7OcpP6tNh4nnTn5KrafiKQEppxIS X-Received: by 2002:a05:6000:4a0a:b0:48e:2448:ea23 with SMTP id ffacd0b85a97d-48e6e307864mr27911663f8f.55.1793693298983; Tue, 03 Nov 2026 00:08:18 -0800 (PST) X-Received: by 2002:a05:6000:4a0a:b0:48e:2448:ea23 with SMTP id ffacd0b85a97d-48e6e307864mr27911622f8f.55.1793693298443; Tue, 03 Nov 2026 00:08:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1793693298; cv=none; d=google.com; s=arc-20260327; b=Mlo6UrUmX7go4beVGb1RkwwzXTOJZ0UEEmrlyMcln5YUvuCENhyt/af0IUk1BoP0HI DOv0enx6DXmdGEbAYsYH43DbzI5iW7wLN7HS6AWJwbmbH5e55u1xYAXg4kj1wkuO5ZkF WjKDk6c7shfsTd9XD7Rri2njC7XN/uZnBRzpBlkf+6dDhhvsshh/4GpRDGcFj1mTincB iArr2a+btsKSXTuPYfJSgLftPxTqRGhcvapJnct9NCqOpgvrcBTnACQA6PgowfyaE0na fuNCiP3LEGioYkIsuqTjM93Lfcu1mdhmhBFBIp77ONeAgcxCmpn/oAm23tHwUIL5ds8z JvVw== 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=E2JPKVZkEPRdLhLKksHwvXlUyfecmfrDnFz0lE7Bwu4=; fh=ElTTnnNtphHTCCOZ+58STyaWac7y7ytLDJZIF4HMMJ4=; b=ZXBlRGKG0moyqjHvtaI8d4TR7k2MX0PMKubtfxFptJzqQJdgH/tcP7uppxv/zqwbGK VDz1FOEow2xZIuzHtWHRpwqPS8xg6Wgo12Hg5L78sq53XliWFxmjidpnR7jjvjMDvWIl 4ErrAZFeOOH3GjXl9glm2ByRiawPau6jv/Lb4r5/D0+7UIaveMduldQSp3+QYmw3nbza j38znfnpXC1rDThqtUNiOvbIQJZ1oSrvO80/ETtXNvR/mVm3Pli6n45usPRDi5EFgQHk Uv3X5eyCiX5x61wQtwdkoMPAlrtASGBi+Gr6so/o+a9tPCpWn+jBdoxG17w33HGDjukj vmvw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=l6uZ0ERV; spf=pass (google.com: domain of andrey.zhadchenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=andrey.zhadchenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48e71bb1303si22912421f8f.212.2026.11.03.00.08.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 00:08:18 -0800 (PST) Received-SPF: pass (google.com: domain of andrey.zhadchenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=l6uZ0ERV; spf=pass (google.com: domain of andrey.zhadchenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=andrey.zhadchenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=E2JPKVZkEPRdLhLKksHwvXlUyfecmfrDnFz0lE7Bwu4=; b=l6uZ0ERVXoRG ie6JMAdqti9md8amypFEOISqisLRkv1jnIYm0rfDV5c0WGQBSo5ZGZRH5LzlQlOy+qNmG2oAYWnSk CwQZ/mZIMt/g3DmLRhOh9Z3fpfm6x5c6hcF5PfOuQl8dHP2/qfwjkBwzoslWCzFB27831Tb0hWalR rWXNlFbyV3kzRXkfqY95b1GFXQMz1snHP+dtW+MsuiZufFngRNZmcnunFFff0PDX1UYs06fWSWoeY qN4cQHGrWqBex41uxNEDlQibcaSDy+CFa5Q0knKhYCE187iIETmOF9QQ5ETuVnAzrhsduYZba5NXI qYHcoPkCCKH94ORLBh8BlA==; Received: from [130.117.225.5] (helo=vz9-demens-1.aci.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xO9V9-0086OY-0d; Tue, 03 Nov 2026 09:08:08 +0100 From: Andrey Zhadchenko To: khorenko@virtuozzo.com, alexander.ivanov@virtuozzo.com Date: Tue, 3 Nov 2026 11:03:57 +0300 Message-ID: <20261103080358.723186-6-andrey.zhadchenko@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20261103080358.723186-1-andrey.zhadchenko@virtuozzo.com> References: <20261103080358.723186-1-andrey.zhadchenko@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v4 5/6] drivers/md/push_backup: arm deadline timer under pb->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 When push_backup_write acks last delayed request it sets deadline_jiffies = S64_MAX and the next fired timer uses this for mod_timer(): expiry is set to some very distant future. Previously a later push_backup_write() would accidentally repair the expiry; since it no longer touches the timer, nothing does until stop. Make the decision and the arming atomic: call mod_timer() under pb->lock at both sites, and do not re-arm when nothing is delayed or the backup is not alive. mod_timer() and queue_work() are fine under a spinlock, and the timer base lock is dropped while the callback runs, so there is no lock inversion. The callback racing with push_backup_stop() was never handled either: timer_delete_sync_try() is try_to_del_timer_sync(), it returns -1 without waiting when the callback is running, and we only WARN on that. A callback blocked on pb->lock could thus outlive stop and re-arm the timer or queue do_pb_work() after flush_workqueue(), expiring a later session. Use timer_delete_sync() in push_backup_stop() and timer_shutdown_sync() in pb_destroy() to wait for it; the work it may have queued is flushed by flush_workqueue()/destroy_workqueue() which follow. As a bonus the rcu_read_lock()/synchronize_rcu() dance between postpone_if_required_for_backup() and push_backup_stop() is no longer needed: cleanup_backup() clears pb->alive under pb->lock, the timer is only armed under pb->lock while pb->alive is set, and the callback itself is waited for. Drop it. https://virtuozzo.atlassian.net/browse/VSTOR-152912 Signed-off-by: Andrey Zhadchenko Reviewed-by: Alexander Ivanov --- v2: new patch v3: bail out of pb_timer_func() when !pb->alive; wait for a running callback with timer_delete_sync() in push_backup_stop() and timer_shutdown_sync() in pb_destroy() instead of WARNing on timer_delete_sync_try() < 0; fixed the commit message claim about it v4: no changes drivers/md/dm-push-backup.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/md/dm-push-backup.c b/drivers/md/dm-push-backup.c index b1861204f6e3e..6951e3fcdbfbf 100644 --- a/drivers/md/dm-push-backup.c +++ b/drivers/md/dm-push-backup.c @@ -241,23 +241,24 @@ static void pb_timer_func(struct timer_list *timer) spin_lock_irqsave(&pb->lock, flags); deadline = pb->deadline_jiffies; - spin_unlock_irqrestore(&pb->lock, flags); - + if (!pb->alive || deadline == S64_MAX) + goto unlock; if (unlikely(time_before64(now, deadline))) mod_timer(timer, jiffies + (deadline - now) + 1); else queue_work(pb->wq, &pb->worker); +unlock: + spin_unlock_irqrestore(&pb->lock, flags); } static int postpone_if_required_for_backup(struct push_backup *pb, struct request *rq) { - bool queue_timer = false; struct pb_bio *pbio; unsigned long flags; + bool wake = false; int ret = 0; - rcu_read_lock(); /* See push_backup_stop() */ spin_lock_irqsave(&pb->lock, flags); if (!pb->alive) goto unlock; @@ -272,16 +273,13 @@ static int postpone_if_required_for_backup(struct push_backup *pb, pb->nr_delayed += 1; if (pb->nr_delayed == 1) { pb->deadline_jiffies = get_jiffies_64() + pb->timeout_in_jiffies; - queue_timer = true; + mod_timer(&pb->deadline_timer, jiffies + pb->timeout_in_jiffies + 1); + wake = true; } unlock: spin_unlock_irqrestore(&pb->lock, flags); - if (queue_timer) - mod_timer(&pb->deadline_timer, jiffies + pb->timeout_in_jiffies + 1); - rcu_read_unlock(); - - if (queue_timer) + if (wake) wake_up_interruptible(&pb->waitq); return ret; @@ -400,9 +398,7 @@ static int push_backup_stop(struct push_backup *pb, return -EBADF; cleanup_backup(pb); - /* Wait postpone_if_required_for_backup() starts timer */ - synchronize_rcu(); - WARN_ON_ONCE(timer_delete_sync_try(&pb->deadline_timer) < 0); + timer_delete_sync(&pb->deadline_timer); flush_workqueue(pb->wq); spin_lock_irq(&pb->lock); @@ -628,7 +624,7 @@ static void pb_destroy(struct push_backup *pb) { WARN_ON_ONCE(pb->nr_delayed); - WARN_ON_ONCE(timer_delete_sync_try(&pb->deadline_timer) < 0); + timer_shutdown_sync(&pb->deadline_timer); if (pb->wq) destroy_workqueue(pb->wq); kvfree(pb->map); /* Is's not zero if stop was not called */ -- 2.43.5 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel