Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp524414rdb; Sat, 17 Feb 2024 22:34:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcigdltP+4REDBg0Hyftq9mPDW+orLT27PmS0YWuFcEWfLYjhYTCDHNDIPRCcsA1ti3FeSRcHPEEvX0skbo7Z+TuBpEpyT16C3M52cWw== X-Google-Smtp-Source: AGHT+IHXloTQN+XMsYzGJdo3LFLlxN5kJXGN0aTKIlCDJe2LuJhDAzrbhGCxlkKUL+04Z64dHurV X-Received: by 2002:a05:6808:1296:b0:3c1:3659:1e9e with SMTP id a22-20020a056808129600b003c136591e9emr13275345oiw.1.1708238063145; Sat, 17 Feb 2024 22:34:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708238063; cv=pass; d=google.com; s=arc-20160816; b=ccsRrlYuGwAY9sycgYEGLeul0IzsqB+ULhd9ls47nkvxvLNcjay3afi+lGggsYuwSd j2Zj2liIBA4gJ4RvoEsD+mUK8YcPNOZF6V/cY3AvfmMq1xDRWkp4xd2U7bqClTrH/oUu YqvZ77GrrMruKrshodD+b6J10dYJsVskXwdqYWiA7Sw0Snu2sFTykcpCs40i7xzmHWr4 U9suFDttKEm9nqZPhHFTIaOV9dJcCjG4iZCVVfY4ZTJiJg+o3r5eSAtqZWld9NAxufvC xT7CkQjpDLVCZLKCzrrJBkEjtlmr4Fu5Urvhp2ODjg++FORAd/CklwzN1UyP/43BG+00 Icog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=iDfbmoBYQtxTNlSi081M3Deu0eBPrgHJdXesgxZPutc=; fh=hpgXmDcHmoAP7QiZFPl4dBcSK4LHxEp3OCRhZY9sl74=; b=Phs2TG2hSdgx9HsnLI/IFLFHEN0RbrVnhbYQqi8bsJRf/gxY9q0o13SATP9LabmdeP pZxR8o4oqiGyrxCRUbK3ueeDt6n/vGZ9niLoccmEStEvlQT1WsZfzdbe5sGYuj+0s7hy V/vs93yA6b/WfJO5A+Isz+4lxpW77YXW2tUpDpiAyrfNRdOngLB53k31FuesrPmpeYDO BkcxU08QdiJs7CoQx8i7050A1E9kYJNhvk3Tvq9v2HWfLqDFezBnjDvnBguMAU85Ez+S pBSDiUs5jYl3O8zkzTCJDgfNiycwA286uDPDaSZ1v2WC+Pzu3X3KWppNQvP5nl7Svgyn CVLQ==; 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-70229-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70229-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 y12-20020aa79e0c000000b006e3d5f8ed57si1087311pfq.217.2024.02.17.22.34.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 22:34:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70229-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-70229-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70229-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 CB11A283BAC for ; Sun, 18 Feb 2024 06:34:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F9936AD7; Sun, 18 Feb 2024 06:34:14 +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 D2A35EAC5; Sun, 18 Feb 2024 06:34:10 +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=1708238053; cv=none; b=qPRLF/vMXIoTs/7NIGVaxIC1tlQLvd6sbElO9zr2fmli1Cii88s215f3YTlr2WUi+crt/Uf2YHD8BitcTcjWPuuGz92DryzlRpdjto/2vmuy+14Hf7Gqp5N3TuNzdNRJ558wVMEro+4vAbuHPfnnhDkK5WGZlacCVvrer+6cSrg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708238053; c=relaxed/simple; bh=7f1xn1gCJBLFzBJg9ICJ3pAtn5BxCirwIB0dE9mDWXc=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=Gst5pM9hzNyWM4UKleJsLdx48iKpNkkgzAdP9JKua7DDn0j3FvK/6NdHf3A89u+bBRFgO7urJWzJtbjdTwJCgH2lS8mHZpkasLX1SGFHKFIruqRPjyI7lMEUHWABu9VrKUqxRC8KGKB56KZ/tPNKJRifbz/14y/HxpF/EYrCk4I= 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.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TcwqZ1Zbgz4f3jd3; Sun, 18 Feb 2024 14:34:02 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 140281A0175; Sun, 18 Feb 2024 14:34:07 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP1 (Coremail) with SMTP id cCh0CgAn9g7YpNFl+Ot7EQ--.33296S3; Sun, 18 Feb 2024 14:34:02 +0800 (CST) Subject: Re: [PATCH v5 09/14] dm-raid: really frozen sync_thread during suspend To: Xiao Ni , Yu Kuai Cc: mpatocka@redhat.com, heinzm@redhat.com, blazej.kucman@linux.intel.com, agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev, song@kernel.org, jbrassow@f14.redhat.com, neilb@suse.de, shli@fb.com, akpm@osdl.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, "yukuai (C)" References: <20240201092559.910982-1-yukuai1@huaweicloud.com> <20240201092559.910982-10-yukuai1@huaweicloud.com> From: Yu Kuai Message-ID: <3c062731-3b74-2b3e-94c8-ffdf940df014@huaweicloud.com> Date: Sun, 18 Feb 2024 14:34:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAn9g7YpNFl+Ot7EQ--.33296S3 X-Coremail-Antispam: 1UD129KBjvJXoW3Jw15Cr4fWFyDCFyrZw1rtFb_yoWxGw4Upa y8tFs0yr4UJrW7AFZFv3WvvFWYvw1aqrWjyr93GayrJ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30 PM Yu Kuai wrote: >> >> From: Yu Kuai >> >> 1) The flag MD_RECOVERY_FROZEN doesn't mean that sync thread is frozen, >> it only prevent new sync_thread to start, and it can't stop the >> running sync thread; > > Agree with this > >> 2) The flag MD_RECOVERY_FROZEN doesn't mean that writes are stopped, use >> it as condition for md_stop_writes() in raid_postsuspend() doesn't >> look correct. > > I don't agree with it. __md_stop_writes stops sync thread, so it needs > to check this flag. And It looks like the name __md_stop_writes is not > right. Does it really stop write io? mddev_suspend should be the > function that stop write request. From my understanding, > raid_postsuspend does two jobs. One is stopping sync thread. Two is > suspending array. MD_RECOVERY_FROZEN is not just used in __md_stop_writes(), so I think it's not correct to to check this. For example, if MD_RECOVERY_FROZEN is set by raid_message(), then __md_stop_writes() will be skipped. > >> 3) raid_message can set/clear the flag MD_RECOVERY_FROZEN at anytime, >> and if MD_RECOVERY_FROZEN is cleared while the array is suspended, >> new sync_thread can start unexpected. > > md_action_store doesn't check this either. If the array is suspended > and MD_RECOVERY_FROZEN is cleared, before patch01, sync thread can't > happen. So it looks like patch01 breaks the logic. The difference is that md/raid doen't need to frozen sync_thread while suspending the array for now. And I don't understand at all why sync thread can't happed before patch01. Thanks, Kuai > > Regards > Xiao > > >> >> Fix above problems by using the new helper to suspend the array during >> suspend, also disallow raid_message() to change sync_thread status >> during suspend. >> >> Note that after commit f52f5c71f3d4 ("md: fix stopping sync thread"), the >> test shell/lvconvert-raid-reshape.sh start to hang in stop_sync_thread(), >> and with previous fixes, the test won't hang there anymore, however, the >> test will still fail and complain that ext4 is corrupted. And with this >> patch, the test won't hang due to stop_sync_thread() or fail due to ext4 >> is corrupted anymore. However, there is still a deadlock related to >> dm-raid456 that will be fixed in following patches. >> >> Reported-by: Mikulas Patocka >> Closes: https://lore.kernel.org/all/e5e8afe2-e9a8-49a2-5ab0-958d4065c55e@redhat.com/ >> Fixes: 1af2048a3e87 ("dm raid: fix deadlock caused by premature md_stop_writes()") >> Fixes: 9dbd1aa3a81c ("dm raid: add reshaping support to the target") >> Fixes: f52f5c71f3d4 ("md: fix stopping sync thread") >> Signed-off-by: Yu Kuai >> --- >> drivers/md/dm-raid.c | 38 +++++++++++++++++++++++++++++--------- >> 1 file changed, 29 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c >> index eb009d6bb03a..5ce3c6020b1b 100644 >> --- a/drivers/md/dm-raid.c >> +++ b/drivers/md/dm-raid.c >> @@ -3240,11 +3240,12 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv) >> rs->md.ro = 1; >> rs->md.in_sync = 1; >> >> - /* Keep array frozen until resume. */ >> - set_bit(MD_RECOVERY_FROZEN, &rs->md.recovery); >> - >> /* Has to be held on running the array */ >> mddev_suspend_and_lock_nointr(&rs->md); >> + >> + /* Keep array frozen until resume. */ >> + md_frozen_sync_thread(&rs->md); >> + >> r = md_run(&rs->md); >> rs->md.in_sync = 0; /* Assume already marked dirty */ >> if (r) { >> @@ -3722,6 +3723,9 @@ static int raid_message(struct dm_target *ti, unsigned int argc, char **argv, >> if (!mddev->pers || !mddev->pers->sync_request) >> return -EINVAL; >> >> + 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 >> @@ -3791,15 +3795,31 @@ static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits) >> blk_limits_io_opt(limits, chunk_size_bytes * mddev_data_stripes(rs)); >> } >> >> +static void raid_presuspend(struct dm_target *ti) >> +{ >> + struct raid_set *rs = ti->private; >> + >> + mddev_lock_nointr(&rs->md); >> + md_frozen_sync_thread(&rs->md); >> + mddev_unlock(&rs->md); >> +} >> + >> +static void raid_presuspend_undo(struct dm_target *ti) >> +{ >> + struct raid_set *rs = ti->private; >> + >> + mddev_lock_nointr(&rs->md); >> + md_unfrozen_sync_thread(&rs->md); >> + mddev_unlock(&rs->md); >> +} >> + >> static void raid_postsuspend(struct dm_target *ti) >> { >> struct raid_set *rs = ti->private; >> >> if (!test_and_set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { >> /* Writes have to be stopped before suspending to avoid deadlocks. */ >> - if (!test_bit(MD_RECOVERY_FROZEN, &rs->md.recovery)) >> - md_stop_writes(&rs->md); >> - >> + md_stop_writes(&rs->md); >> mddev_suspend(&rs->md, false); >> } >> } >> @@ -4012,8 +4032,6 @@ static int raid_preresume(struct dm_target *ti) >> } >> >> /* Check for any resize/reshape on @rs and adjust/initiate */ >> - /* Be prepared for mddev_resume() in raid_resume() */ >> - set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); >> if (mddev->recovery_cp && mddev->recovery_cp < MaxSector) { >> set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); >> mddev->resync_min = mddev->recovery_cp; >> @@ -4056,9 +4074,9 @@ static void raid_resume(struct dm_target *ti) >> rs_set_capacity(rs); >> >> mddev_lock_nointr(mddev); >> - clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); >> mddev->ro = 0; >> mddev->in_sync = 0; >> + md_unfrozen_sync_thread(mddev); >> mddev_unlock_and_resume(mddev); >> } >> } >> @@ -4074,6 +4092,8 @@ static struct target_type raid_target = { >> .message = raid_message, >> .iterate_devices = raid_iterate_devices, >> .io_hints = raid_io_hints, >> + .presuspend = raid_presuspend, >> + .presuspend_undo = raid_presuspend_undo, >> .postsuspend = raid_postsuspend, >> .preresume = raid_preresume, >> .resume = raid_resume, >> -- >> 2.39.2 >> > > . >