From patchwork Fri Mar 1 09:56:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 208743 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp975398dyb; Fri, 1 Mar 2024 02:07:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWiZB+ZLZ9TUY0owcvZ5HWoBKRGCYeF71boUMr7VVGMaDYAWRsaHc57YbDm+25YXPZ+DKu2TYVfbioFTpjQL+Ra42huow== X-Google-Smtp-Source: AGHT+IE6PfJwOp+3SLiY8k4wy3BOcBIhpeO9gqxoYts2FYF8EVS0TG6xX4aklOqmMvMNWa1GUxxR X-Received: by 2002:a17:902:c20c:b0:1db:f389:2deb with SMTP id 12-20020a170902c20c00b001dbf3892debmr975611pll.17.1709287653111; Fri, 01 Mar 2024 02:07:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709287653; cv=pass; d=google.com; s=arc-20160816; b=lyOkFUyixVu+fz5PK0D8LtmM1iWaQ2Xp1PSPgw96cwltxU/0WIEoVoanloUH/D1e4l Tr/Oqr6KAop7sXJe+n7h5VBOfCO241stdNILUgHLhYWMnCKZYBz5REPyvx0E3FDreVTA j9W+ekkLv+nZCEvokMNp8/b2m+RsRmZKfg7SOBrNm8GyEr79IhXW54p1J9vG0BKKG8cr Kq1otwgaqdvgXoMkK0Fe6GqQ68x6a1vn4qECbVBOrUmmFMNyNzFeq6QdoKM4hxUq4Cxn lRCM5l7ASLBrvbJRKYJQlcy5YhsdBEw+9O5S2XGTfwazXF7e1wb9jlg4YBdPCeLCnzfO g5YQ== 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=FP3KjwFAhImOz6jtSE4u66/mENwsnkWhTqEXUcvghRI=; fh=D0tHjPHp+NwWiP9dALgrUrDY+JdDylAJlTP6wFQuWjg=; b=lUqF/82wt5HTuOYJzBTrE7npbzvGXSwGzrColAOzdDJyozjUapbQI9oHXYk0ak5h3r 627r+CY8DrzCgSxueJA8qC/i3yg3Z3tcwWS4KCIbH7f8nAT3XP50O8P/deqhHoqKyCT5 u9oB7XgqpzgPYxvW9BYQNQ6BBgURXzx8T24nZuUQy/YL4PpwQRihhv0AjSYZEj7ERs5q xc5v/j2CY1QL5gsMrr7c5dj+zo6Q2rHVO6HU9MDsryY/I7fNmVMghwNhuaZHP2MAuEUH KBeKQWHA8ytC24QIQvzNxc0ai9SayUvC/Tt3zNoDvUx6L549bg7JSOJN6NE0UblcvA+W 5cng==; 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-88230-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88230-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y8-20020a17090264c800b001dc6233d864si3114863pli.564.2024.03.01.02.07.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 02:07:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88230-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-88230-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88230-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8B26A284AA9 for ; Fri, 1 Mar 2024 10:07:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D57772925; Fri, 1 Mar 2024 10:03:15 +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 E92C46BFD2; Fri, 1 Mar 2024 10:03:09 +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=1709287393; cv=none; b=nd6HMPLbdjAkr+OR8Es6p8l+X6rZBxMPqOR7itTVuX3H59yPh3xJ2nwjKo62r1BTgtkLcR7vGxvVCDVZUR850GILGLsoW+UXmPa1fuSV11wsOPTJDhWtuP80/LrF+zbJ4IhAGNFjKGVUmtFV9dUYahj7NMTB5pHcOXlktaVkQp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709287393; c=relaxed/simple; bh=tzsmm4I3A6wxqwxdBMCsCEs/m98BNt/dBIkv7eT554g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IN7x8FMxAQ/4re13Pe4UmY/zBxFsrvCeoQ2ZpMFs4iIOOmEUFpJgjn+d/y8UGoJ6RI2Krs+LlLuoZ0HiLur/yZhAC6RpTgBGXVMcjHshwQ77YM4z2Ja/kZZ+J6QIGMoyClP+ylUg1ew2WWeKgJQoU5zXG8UAI2NEnxMjFoymH2k= 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 4TmNvC3Hccz4f3mWL; Fri, 1 Mar 2024 18:03:03 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D69B71A08E9; Fri, 1 Mar 2024 18:03:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBHTp+FlqmBuFg--.36874S10; Fri, 01 Mar 2024 18:03:06 +0800 (CST) From: Yu Kuai To: zkabelac@redhat.com, xni@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, neilb@suse.de, jbrassow@redhat.com Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH -next 6/9] md/dm-raid: don't call md_reap_sync_thread() directly Date: Fri, 1 Mar 2024 17:56:54 +0800 Message-Id: <20240301095657.662111-7-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240301095657.662111-1-yukuai1@huaweicloud.com> References: <20240301095657.662111-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: cCh0CgCXaBHTp+FlqmBuFg--.36874S10 X-Coremail-Antispam: 1UD129KBjvJXoW7AF1xAF18KFyDuFy5Ww48JFb_yoW8Kw4fpa yakas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horxvhhfrp/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792318010352743100 X-GMAIL-MSGID: 1792318010352743100 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 ac8b37fcf76f..766a0334460e 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 */