Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1008497rdb; Wed, 24 Jan 2024 01:49:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaeAVBaG9FnAGVC5pZNXtM22LRRpZmPuCSrYDZTJCTlzhmqJZmVlsvqOZItq0YHIpsgS3b X-Received: by 2002:a17:902:9a85:b0:1d4:5268:27ed with SMTP id w5-20020a1709029a8500b001d4526827edmr512848plp.21.1706089744837; Wed, 24 Jan 2024 01:49:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706089744; cv=pass; d=google.com; s=arc-20160816; b=eMD5lfUkHo+9BQS5UCshXOehcRA1taCS0r6Dk0/9Zke6aJR6mxLr5lwXR1oy3fndPi L8fZH/6ismmq5vt/ryemDkSyVO4txKnKYpNdrb4UCeAhBmZXy9PH+4/ACm6jfGF1KedM Nd1V2fKDUWOGoOD/xWIgSBbyo+Gku+f3avK9RWsbniRfTZ94dvWSOqIZNXjGzQw8BTHA QR1MFGQOptFPO2YZ8LNTtX6oU5DDoJt8nqKcQ+SKWC7FOu1XujPJcj+BzwASXJBYIK7M JVhHDuh72LIkSoK7jc+ypl5S6fTkl8esjCqbIoidL9FUi85LG7BOg7VWlzFDwrBE08V/ 8CHQ== 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=yFsM2eAQnXUT8kruvaM0Sts9BcAsH2f90nOuZnqYVDE=; fh=SaJ9rWjnsGFI+7ibUS2Ywr9D7BSRvW01ZC90UJpOFqs=; b=dr5k0Mv6R3myeR8qINk2xg+K/3lsrLghMoamyyp+6WgdAgma/tLg3OXigyOJiDcumA ohLWPocL8VvddyoQ1UZ1+AgdCnJnUApNw9x3oxmnkd6C5C2HzTHNQm84EH7AmFnOOrKH Tl+9AJKjd8P/MwZJSeexfsCnjMDhYRK9XLJgsyi94a+q3fzxnZ3QeBlQcYL/n1xI+mRH 470D/uwqJCfVI2eMlNp13yljzH0pVMQ3+gJc77DeFCaM1JWWhs+/UcIhdoMv6MDyLayB MV3VgxmYBcq03n/7acUsugfT8/+iEhRgHusGG6B9rMtrXYadz+jLtcoUi4+SEVkJBo/B txOA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-36700-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36700-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l7-20020a170903244700b001d7354ba1aasi1974475pls.119.2024.01.24.01.49.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 01:49:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36700-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-36700-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36700-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0F66DB2BA84 for ; Wed, 24 Jan 2024 09:22:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB4F619477; Wed, 24 Jan 2024 09:20:21 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 B21DD1946B; Wed, 24 Jan 2024 09:20:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706088021; cv=none; b=p58wKP0zntS+Hq/qP1feSwWm5lkzhvO4sM4gh9BKe0maP14wyuq4oKSuYK4B7xreKyqPoM1UlrOhdleO6bXwyrrH5RJ+I1dHuSmnLfga2WZ0E/y+/O7kHXeO7zc0IyUKilysK5kykPo+SRY2+PndvxCFMiESip9lOoZF5c5Pf8o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706088021; c=relaxed/simple; bh=kJ1nYmW4cicbBwQfSgo5X6zUUeLx3T+g5jG9se6tsaM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m75eKYQdjrhjGTt9Yn6xguJyfeI1jhahqwRM0PYL7AtDuc6b3O91jrT8MNhL2YVhBMvMxJd63kBJNAzcyB5F0mkMK2J9phIeJkQUbMlg5jUru9u94ogVFChVWflgTA+/yBKBE3OkfdEaPVOoOPzx/3x4ZW/mXpq+MfymYOe4844= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TKdfx2jxGz29kj6; Wed, 24 Jan 2024 17:18:33 +0800 (CST) Received: from kwepemm600009.china.huawei.com (unknown [7.193.23.164]) by mail.maildlp.com (Postfix) with ESMTPS id 987251A0172; Wed, 24 Jan 2024 17:20:02 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 24 Jan 2024 17:18:24 +0800 From: Yu Kuai To: , , , , , , , , , , , CC: , , , , Subject: [PATCH v2 07/11] md/dm-raid: don't call md_reap_sync_thread() directly Date: Wed, 24 Jan 2024 17:14:17 +0800 Message-ID: <20240124091421.1261579-8-yukuai3@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240124091421.1261579-1-yukuai3@huawei.com> References: <20240124091421.1261579-1-yukuai3@huawei.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 Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600009.china.huawei.com (7.193.23.164) 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 --- 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 5ce3c6020b1b..6b6c011d9f69 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