From patchwork Thu Feb 1 09:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 195224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp30765dyb; Thu, 1 Feb 2024 01:34:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdRLmBh9iYrjsamChyAixhxaTUdkOSDgNbM0JiGhD17UK40Q0+g8A9AkYNh30c16cgf7dr X-Received: by 2002:a17:906:3d52:b0:a35:d69f:e4e2 with SMTP id q18-20020a1709063d5200b00a35d69fe4e2mr3002208ejf.30.1706780055556; Thu, 01 Feb 2024 01:34:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706780055; cv=pass; d=google.com; s=arc-20160816; b=VDJA6vTntW0pRPjS10u6/kN8zIkuUicdgS9MnavplqB8PO5JFrl6DmXtiXhtpCSgqD 1MTWifl9lhtqv4noztx4yiETpHB6V6xdxRc8iSJimaiIzcYNQJIqshQFZfOCfypAf/xI HlcDx+kyHMh5bUqx/2cdbbOPZfYPT0WTK819qJpD1AKjagOQ+inWLCVzMH1/JxKwOy1j GiN4V5GtbcgknV2pMEilijhoZe+0m7ZU77oO0Uj+cuhyOw+fsq8bfsWYTg6zih8KiNP4 bWsy+OJbAIm06Eh7lXHrnCZG0+QUXCkkO60+3Chj/pgCW+MTlf8O44CF8D8Yiv/29hbJ 130w== 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=0h6sLTtSXWd4NNSNFaiFXDbIJAObc1SgGd1OcMYigCo=; fh=eur1kFM2Dhm4janP2ic2m3Us4wQ7RR6bf+Xr5KV4Gdo=; b=P5PFamepDXW7rc6wUF2MxMxxzAEZb4n7kWnK3FX0uRKyQm9BHtITD5KNfEAgQmMMTZ ml5ZA06gX+yiKqOvat4yggC4zjz45x7iw+xsCA+T/pRurU2L5TmI3teQh/kv0B+Tbbq4 SG94hkx0rQTjoQrMrv4Wzcf7LZw5o9L6cKFtBwSVWTiRe0YOT63/jQG8Ip4uA80BY9J9 hBH812wWnx60/3uwDAcnthoF7k20b+9kgVKRZtNa78AFlty0KpCFVbBFzpBnZu0C/+by F1FX1gfFpxSMrrjiSv2sc/AVLXWkwxxuREQa8d9vkw1yIZtjGYnvEf293jFKdNB7828J XJhA==; 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-47874-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47874-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVEG+wuQcm8q3huL6xDjmJVTG093YItW2QmaB7+gIeYcG/2gvUkbtZ0FoFn4udmoGn/TJGxVK1LZuCoe/+5zUoGtfavcg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t13-20020a170906064d00b00a31898cdf7bsi6628075ejb.136.2024.02.01.01.34.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 01:34:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47874-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-47874-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47874-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id D983B1F266FD for ; Thu, 1 Feb 2024 09:34:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC552163A87; Thu, 1 Feb 2024 09:30:39 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (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 010A815F30D; Thu, 1 Feb 2024 09:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706779837; cv=none; b=Yqfu25Wv87L3iQFJovSnOoE/LE38pBmcFBQl+r0/LYcmGg+oTOvB95pB4LdhwTMOaPIulGT2j+F+oZRHK62QEul4wXone4tidUxls6qtskldh43IaqCZiZtmsvtzoyoqqWZw3tE9oFZFa0QeUXI8zcnw8EV6OijcersUpqr73U0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706779837; c=relaxed/simple; bh=orTUf8OIgVO5EnJ8e56Og6bXoRyUdV4mYFLO+shF788=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EHdzCpQLEF8onvf7f2R2WU7u97oj7Zzzedhaqbm/eOoGZaFZipdCLCCPllpKA3wphonzvvKq2zXi4hMZxsTeKi0TE9DsyROHGgGCiHDr4JyISgvOt8+k3KEP2dUc61aiLtyiTIRZo0cxf+/V8UBfe1og5epDghhB734dVopI5k0= 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.56 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.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TQYY06qCgz4f3l7f; Thu, 1 Feb 2024 17:30:28 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 2A1781A0232; Thu, 1 Feb 2024 17:30:33 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBGtZLtl8V6KCg--.33515S14; Thu, 01 Feb 2024 17:30:32 +0800 (CST) From: Yu Kuai To: mpatocka@redhat.com, heinzm@redhat.com, xni@redhat.com, blazej.kucman@linux.intel.com, agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, jbrassow@f14.redhat.com, neilb@suse.de, shli@fb.com, akpm@osdl.org Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH v5 10/14] md/dm-raid: don't call md_reap_sync_thread() directly Date: Thu, 1 Feb 2024 17:25:55 +0800 Message-Id: <20240201092559.910982-11-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240201092559.910982-1-yukuai1@huaweicloud.com> References: <20240201092559.910982-1-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgCXaBGtZLtl8V6KCg--.33515S14 X-Coremail-Antispam: 1UD129KBjvJXoW7AF1xAF18KFyDuFy5Ww48JFb_yoW8Kw4fpa yakas8Ar48JrW3ZFsrt3WDWayFv3ZFq3yqyFWfG3y3JF1fKF43W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AIL-THRID: 1789688603466514060 X-GMAIL-MSGID: 1789688603466514060 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 --- 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 */