From nobody Thu May 23 17:42:06 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Vlb8Z4Smpz5Kxtb; Thu, 23 May 2024 17:42:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vlb8Z3pJ9z4rSD; Thu, 23 May 2024 17:42:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716486126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=u5VkYq5r8JejhsZf2gECWaykt3YMrZXT4G6s5dL4gqc=; b=S8jPBVa6ntDq0hvJwAyb9AzuSoyR2ppgiwFZ65JkDZG6+5X/TAl8ytf3vL0AAq1KhNlRi8 OXiKf/bqJXlbP8eOvsQenOjBR22nh2pMxuXque6qvm4XMzfAtAbegrhs0hxzByQxJqstQw +Sk3o9snP3+4H2ubuTREBuK/F4ZnGedQ0k9aHOiYYO2zqgT17Tax6cJotKgExDOsgHRDW6 DJGfGncbGcSGAb7wPpot7jhZBy2IKG/pzrsocPYIIAmHULpDznNblc1EwX+s+Q9WNzk392 U5nM9NuzRHmDexY02c7251m/KTq8g1BHR6zXRUJoG7nzz00y+MiZ+SxiJewt7w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716486126; a=rsa-sha256; cv=none; b=n9utmUZYQM2ESgB6SkW07lSBauIph9fKB9BeQ42gfSJrjYiot0ehTbm8DlTtVGbjbuJfX5 jIKGJ3E2UP7kSrhN0vDZCEVfwh/SR83afrR952NTML8mCTYfE6NdvedEpYwOD0DlFvjSwh gCv2qHDb4PzktqhbLzRXU9hYg0IJZ3MJNZeT2nLFCfui91fhhebNXCKTek4+YVFQfeTk82 K8Onj9nBbdCYJdW23h3slK922gH4raT60NrefsoDO2t5Maflw0iiz+WE/Ynb+YLLnJitby hkuncLm2yStIuIH39/wVVwDNCFa9BMXvMaR4YEHFz/ApDSjnlcTHOSCSo+q+6w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716486126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=u5VkYq5r8JejhsZf2gECWaykt3YMrZXT4G6s5dL4gqc=; b=ZGvDEv1AbchieOJ8yNmZSBuo7WriyLHiyb1JdFOm205IVsa+w53oa9CXN+U7ylMvrdAoIC P+rA/GfpzQqYiAdP23Kfzt/gNGZTODbC1cJCK2qMGm2IM1LMqTDsnrlMRpvjk8ttRxnq+5 PJmynNaF5S3+lV2ARYJ3QdixsH1vPSs27Yoe5gUXbgVQ0Up9yYrCVz2pT4FK+m2x8NradW g998feJCz+nH30L5/wH9yr0IiaLobCINyXrazOxbKXQA2II4uhhHlVgj9KnwsrwPHPx+QX IZGFaAbmdvdcNeiGt1WjEQMrXv8Rt0AKhTHsTQGRQyd4+Tl41UwiP0g0CNKnLQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Vlb8Z3PwWzyrN; Thu, 23 May 2024 17:42:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44NHg6um081525; Thu, 23 May 2024 17:42:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44NHg6WV081522; Thu, 23 May 2024 17:42:06 GMT (envelope-from git) Date: Thu, 23 May 2024 17:42:06 GMT Message-Id: <202405231742.44NHg6WV081522@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 455ce1729353 - stable/14 - Fix scn_queue races on very old pools List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 455ce1729353f2ffce9713ccc3574e73186a22f0 Auto-Submitted: auto-generated The branch stable/14 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=455ce1729353f2ffce9713ccc3574e73186a22f0 commit 455ce1729353f2ffce9713ccc3574e73186a22f0 Author: Alexander Motin AuthorDate: 2024-05-23 16:20:37 +0000 Commit: Alexander Motin CommitDate: 2024-05-23 16:24:55 +0000 Fix scn_queue races on very old pools Code for pools before version 11 uses dmu_objset_find_dp() to scan for children datasets/clones. It calls enqueue_clones_cb() and enqueue_cb() callbacks in parallel from multiple taskq threads. It ends up bad for scan_ds_queue_insert(), corrupting scn_queue AVL-tree. Fix it by introducing a mutex to protect those two scan_ds_queue_insert() calls. All other calls are done from the sync thread and so serialized. Reviewed-by: Brian Behlendorf Reviewed-by: Brian Atkinson Signed-off-by: Alexander Motin Sponsored by: iXsystems, Inc. Closes #16162 PR: 278414 (cherry picked from commit 49086aa35d987b78dbc3c9ec94814fe338e07164) --- sys/contrib/openzfs/include/sys/dsl_scan.h | 1 + sys/contrib/openzfs/module/zfs/dsl_scan.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/sys/contrib/openzfs/include/sys/dsl_scan.h b/sys/contrib/openzfs/include/sys/dsl_scan.h index 2e3452e5ebaa..f32f59a2bedf 100644 --- a/sys/contrib/openzfs/include/sys/dsl_scan.h +++ b/sys/contrib/openzfs/include/sys/dsl_scan.h @@ -173,6 +173,7 @@ typedef struct dsl_scan { dsl_scan_phys_t scn_phys; /* on disk representation of scan */ dsl_scan_phys_t scn_phys_cached; avl_tree_t scn_queue; /* queue of datasets to scan */ + kmutex_t scn_queue_lock; /* serializes scn_queue inserts */ uint64_t scn_queues_pending; /* outstanding data to issue */ /* members needed for syncing error scrub status to disk */ dsl_errorscrub_phys_t errorscrub_phys; diff --git a/sys/contrib/openzfs/module/zfs/dsl_scan.c b/sys/contrib/openzfs/module/zfs/dsl_scan.c index 34012db82dee..c509f402c44a 100644 --- a/sys/contrib/openzfs/module/zfs/dsl_scan.c +++ b/sys/contrib/openzfs/module/zfs/dsl_scan.c @@ -491,6 +491,7 @@ dsl_scan_init(dsl_pool_t *dp, uint64_t txg) avl_create(&scn->scn_queue, scan_ds_queue_compare, sizeof (scan_ds_t), offsetof(scan_ds_t, sds_node)); + mutex_init(&scn->scn_queue_lock, NULL, MUTEX_DEFAULT, NULL); avl_create(&scn->scn_prefetch_queue, scan_prefetch_queue_compare, sizeof (scan_prefetch_issue_ctx_t), offsetof(scan_prefetch_issue_ctx_t, spic_avl_node)); @@ -646,6 +647,7 @@ dsl_scan_fini(dsl_pool_t *dp) scan_ds_queue_clear(scn); avl_destroy(&scn->scn_queue); + mutex_destroy(&scn->scn_queue_lock); scan_ds_prefetch_queue_clear(scn); avl_destroy(&scn->scn_prefetch_queue); @@ -2727,8 +2729,10 @@ enqueue_clones_cb(dsl_pool_t *dp, dsl_dataset_t *hds, void *arg) return (err); ds = prev; } + mutex_enter(&scn->scn_queue_lock); scan_ds_queue_insert(scn, ds->ds_object, dsl_dataset_phys(ds)->ds_prev_snap_txg); + mutex_exit(&scn->scn_queue_lock); dsl_dataset_rele(ds, FTAG); return (0); } @@ -2919,8 +2923,10 @@ enqueue_cb(dsl_pool_t *dp, dsl_dataset_t *hds, void *arg) ds = prev; } + mutex_enter(&scn->scn_queue_lock); scan_ds_queue_insert(scn, ds->ds_object, dsl_dataset_phys(ds)->ds_prev_snap_txg); + mutex_exit(&scn->scn_queue_lock); dsl_dataset_rele(ds, FTAG); return (0); }