Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp232380lqs; Mon, 4 Mar 2024 23:30:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/kJYJUlfSk6qvncHBPcfcF6XFNA/MbqNjzF+0Kw0eEqWbqn3y/97T9qmWpr6iet1jb7QKpeEf5QlSLKzl2yz3stuL4JUOdSCQxrUxig== X-Google-Smtp-Source: AGHT+IFcKQUm393fOa9CXsFypJKLZjotaT/ZvcBWGdi0Q1GlC8RF31LummSSC03cO8fO01n7MaIy X-Received: by 2002:a05:6808:148e:b0:3c1:de41:9b2f with SMTP id e14-20020a056808148e00b003c1de419b2fmr1325181oiw.21.1709623840091; Mon, 04 Mar 2024 23:30:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709623840; cv=pass; d=google.com; s=arc-20160816; b=uITsFLfmEnkLca/IQWXiNO0AHZq9nrAKOWOmxjORnRBl5JcAJtriYd5x8NIA29jeQg a+9lW8fGhjcHHNIAFet/hduDQX4Wmg6XAh/7Xo+fxEvAulxJvnrK/JQoolPeZFk7DCMP qxbY51fA9Orv5C2C6g9RK9FIwKyq9AEOtjQeDA7odbZ12LD4x3kPR/F4DTSLXooV7AKG cnvARTZKd3lqIhHt8gspfx+uD7rW3pbuyxD61OsZbk/vN+88OXuOMgG+3p/Ome/lhcI8 wmOTylEKidfeAhr4KHpHPDxwrA5+9OzCr+uUnDZLt6LGzJNkiley4t8DXEdVlA4VEbCG FPsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=a/kfOpeVbLLWbTk1MRniqaBJb7L70FKbCbhnwZZlUxM=; fh=YoyvrhSFX/gomruhs8E5v3LJBIcHojMCK8eMDUDpafQ=; b=nEu3JJiwKlhTZGqR7icvaCQpZimy+1Z9iTG4Jss9LZaFVDuSteimvJS45ojnfwovnt zKNWsPc2BRoKGgSQgM1PpikUH+iaEEmrU7OEzjLw+T2ylt2yLGXXJOKXeVSxWQIG8bKZ khBsKO/SWZulTktkpVb1cmyAs7C1yZfKdQYWrxePqoVRtSRRtxd5xfsWWqesPYoYyxLP bc16peTWJsURkZtMOk8vAUCduqzScVpKohp9i/QM6NSifyCWrIWKwpqot2L/04StuemO eA4cy/AuQ5kUM+Gha48QsdBU2iNRJrrPxCFICGDGery8a2hg/EXCkKbfi8Lu486g0O8a wuhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-91801-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91801-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 32-20020a631960000000b005dc97d88897si9698692pgz.698.2024.03.04.23.30.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 23:30:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91801-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-91801-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91801-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B5F1A282F82 for ; Tue, 5 Mar 2024 07:30:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41E277FBAC; Tue, 5 Mar 2024 07:29:35 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 541BA7E59D; Tue, 5 Mar 2024 07:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709623774; cv=none; b=s6D1rejJecjiposQNfvouLvr3Q1MLCzmeDTGZe6HrU/T4T9NLSuNXSeuQPlRislFXsNrsXnjAqI6YKK9q9pyJ31aQI7F28X+NScsZKCvUnBs+oBW8YK3WfuwzMfH9ZIvK3iqHjPrdB0TLTo7RhmQRQB+jIq1BOPIgZi2ErGsT7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709623774; c=relaxed/simple; bh=wdrKCSawGx8VEqyGWfPkhEjDBA0pBVGNi+vB2GWEzzE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LAjbNKq+ZT02FO58LVO3VdqhQjIL/uJNnvcUpnp3h3Yk96mlGE1Ioh+HfYXSZ68j/yHGTZaUxYJw86f6WHT2L8R8RCpvXzOsvHDUGkOlsu+lL+3Ce4U0x+X5TeEbJzlGkjZWbOUzuRUymZEO2JGtBtqfu0FxBO9DsjH5WmjEPeY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TpnJ16xlpz4f3m6n; Tue, 5 Mar 2024 15:29:21 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 71BF31A0C2A; Tue, 5 Mar 2024 15:29:29 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBHRyeZlGnf+Fw--.17927S10; Tue, 05 Mar 2024 15:29:29 +0800 (CST) From: Yu Kuai To: xni@redhat.com, zkabelac@redhat.com, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, heinzm@redhat.com, jbrassow@redhat.com, neilb@suse.de Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH md-6.8 v2 6/9] md/dm-raid: don't call md_reap_sync_thread() directly Date: Tue, 5 Mar 2024 15:23:03 +0800 Message-Id: <20240305072306.2562024-7-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240305072306.2562024-1-yukuai1@huaweicloud.com> References: <20240305072306.2562024-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBHGBHRyeZlGnf+Fw--.17927S10 X-Coremail-Antispam: 1UD129KBjvJXoW7AF1xAF18KFyDZF15tw4UXFb_yoW5JFWrpa yakas8Ar48JrW3ZFsrt3Wq9ayFv3ZFgrWqyrWfG343JF1fKr13Wryj9a17ZFWDXFWrta45 XFZ8tF45uF4YqFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQ SdkUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ From: Yu Kuai Currently md_reap_sync_thread() is called from raid_message() directly without holding 'reconfig_mutex', this is definitely unsafe because md_reap_sync_thread() can change many fields that is protected by 'reconfig_mutex'. However, hold 'reconfig_mutex' here is still problematic because this will cause deadlock, for example, commit 130443d60b1b ("md: refactor idle/frozen_sync_thread() to fix deadlock"). Fix this problem by using stop_sync_thread() to unregister sync_thread, like md/raid did. Fixes: be83651f0050 ("DM RAID: Add message/status support for changing sync action") Signed-off-by: Yu Kuai Signed-off-by: Xiao Ni Acked-by: Mike Snitzer --- drivers/md/dm-raid.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index e2d7a73c0f87..47c4b1b6e532 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -3719,6 +3719,7 @@ static int raid_message(struct dm_target *ti, unsigned int argc, char **argv, { struct raid_set *rs = ti->private; struct mddev *mddev = &rs->md; + int ret = 0; if (!mddev->pers || !mddev->pers->sync_request) return -EINVAL; @@ -3726,17 +3727,24 @@ static int raid_message(struct dm_target *ti, unsigned int argc, char **argv, if (test_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) return -EBUSY; - if (!strcasecmp(argv[0], "frozen")) - set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); - else - clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); + if (!strcasecmp(argv[0], "frozen")) { + ret = mddev_lock(mddev); + if (ret) + return ret; - if (!strcasecmp(argv[0], "idle") || !strcasecmp(argv[0], "frozen")) { - if (mddev->sync_thread) { - set_bit(MD_RECOVERY_INTR, &mddev->recovery); - md_reap_sync_thread(mddev); - } - } else if (decipher_sync_action(mddev, mddev->recovery) != st_idle) + md_frozen_sync_thread(mddev); + mddev_unlock(mddev); + } else if (!strcasecmp(argv[0], "idle")) { + ret = mddev_lock(mddev); + if (ret) + return ret; + + md_idle_sync_thread(mddev); + mddev_unlock(mddev); + } + + clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); + if (decipher_sync_action(mddev, mddev->recovery) != st_idle) return -EBUSY; else if (!strcasecmp(argv[0], "resync")) ; /* MD_RECOVERY_NEEDED set below */ -- 2.39.2