From patchwork Mon Feb 19 06:26:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13562202 X-Patchwork-Delegate: snitzer@redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 69CF0200A8 for ; Mon, 19 Feb 2024 06:27:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708324040; cv=none; b=D4RUzKgZwa4Prl7M6FspVRwmAEWSxJiqNlSoQA16J6t9vWBLn3P3VxHdroE4Slu4sGj3Bcs/sxqws41kHGuNLtYgbGQ0UKLsWMA0kuH0JjzNhtVU2nHXAooppt/uWpL8jDztwFH981kTv9w945tuC7D13Cc9vreBZ49Ei7ACumQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708324040; c=relaxed/simple; bh=Od8CNV1ADNzBsZEw3RmV5QRga8xdhcUYMZWd2Bz5k0I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OPJFTced6ldnn5czb56YpPO/7lV5Lgu6/Ch77zc+aLpxOLFfmRvFdHsWIJTmgT7tmLYCzTonW6YwrbLwwZREdKGpBOFZ+4egUNETYGoWwUsbebWBcLlHOIOjoZJIuJVFZNNI5Q/dtjNau/sPSXz9aKdRLR66dCxv7aYqstsZ6X8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eqoKkbTE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eqoKkbTE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708324037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+cSYOLk5T0RhspTKBTniAyv+0yvTwfvGhLqNsD6fFzw=; b=eqoKkbTEn0QyFIfSNr4JO4NeD+DthC4iQ5w9twxExBNtKrnMilx+Jt637rNri6Wi8EqeCX pW+fHGZX8HMZpvkj5Al3oh9nOcCNP0rPa5oXxHG+L7CgNskdtY/0hJeS4AW4vdUxcNpzP0 lwxxKrIJC1ecxC0HRxvHM9GdG1WUaSg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-ETT4S7M7NU6wprXATcpo2g-1; Mon, 19 Feb 2024 01:26:33 -0500 X-MC-Unique: ETT4S7M7NU6wprXATcpo2g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 687CD28C976C; Mon, 19 Feb 2024 06:26:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1D84AC0C; Mon, 19 Feb 2024 06:26:28 +0000 (UTC) From: Xiao Ni To: song@kernel.org Cc: yukuai1@huaweicloud.com, bmarzins@redhat.com, heinzm@redhat.com, snitzer@kernel.org, ncroxon@redhat.com, neilb@suse.de, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev Subject: [PATCH RFC 1/2] dm-raid/md: Clear MD_RECOVERY_WAIT when stopping dmraid Date: Mon, 19 Feb 2024 14:26:19 +0800 Message-Id: <20240219062621.92960-2-xni@redhat.com> In-Reply-To: <20240219062621.92960-1-xni@redhat.com> References: <20240219062621.92960-1-xni@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 MD_RECOVERY_WAIT is used by dmraid to delay reshape process by patch commit 644e2537fdc7 ("dm raid: fix stripe adding reshape deadlock"). Before patch commit f52f5c71f3d4b ("md: fix stopping sync thread") dmraid stopped sync thread directy by calling md_reap_sync_thread. After this patch dmraid stops sync thread asynchronously as md does. This is right. Now the dmraid stop process is like this: 1. raid_postsuspend->md_stop_writes->__md_stop_writes->stop_sync_thread. stop_sync_thread sets MD_RECOVERY_INTR and wait until MD_RECOVERY_RUNNING is cleared 2. md_do_sync finds MD_RECOVERY_WAIT is set and return. (This is the root cause for this deadlock. We hope md_do_sync can set MD_RECOVERY_DONE) 3. md thread calls md_check_recovery (This is the place to reap sync thread. Because MD_RECOVERY_DONE is not set. md thread can't reap sync thread) 4. raid_dtr stops/free struct mddev and release dmraid related resources dmraid only sets MD_RECOVERY_WAIT but doesn't clear it. It needs to clear this bit when stopping the dmraid before stopping sync thread. But the deadlock still can happen sometimes even MD_RECOVERY_WAIT is cleared before stopping sync thread. It's the reason stop_sync_thread only wakes up task. If the task isn't running, it still needs to wake up sync thread too. This deadlock can be reproduced 100% by these commands: modprobe brd rd_size=34816 rd_nr=5 while [ 1 ]; do vgcreate test_vg /dev/ram* lvcreate --type raid5 -L 16M -n test_lv test_vg lvconvert -y --stripes 4 /dev/test_vg/test_lv vgremove test_vg -ff sleep 1 done Fixes: 644e2537fdc7 ("dm raid: fix stripe adding reshape deadlock") Fixes: f52f5c71f3d4 ("md: fix stopping sync thread") Signed-off-by: Xiao Ni --- drivers/md/dm-raid.c | 2 ++ drivers/md/md.c | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index eb009d6bb03a..325767c1140f 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -3796,6 +3796,8 @@ 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)) { + if (test_bit(MD_RECOVERY_WAIT, &rs->md.recovery)) + clear_bit(MD_RECOVERY_WAIT, &rs->md.recovery); /* Writes have to be stopped before suspending to avoid deadlocks. */ if (!test_bit(MD_RECOVERY_FROZEN, &rs->md.recovery)) md_stop_writes(&rs->md); diff --git a/drivers/md/md.c b/drivers/md/md.c index 2266358d8074..54790261254d 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4904,6 +4904,7 @@ static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq) * never happen */ md_wakeup_thread_directly(mddev->sync_thread); + md_wakeup_thread(mddev->sync_thread); if (work_pending(&mddev->sync_work)) flush_work(&mddev->sync_work); From patchwork Mon Feb 19 06:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13562200 X-Patchwork-Delegate: snitzer@redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 E24BC200A8 for ; Mon, 19 Feb 2024 06:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708324005; cv=none; b=DKwgGNywfAVhdKoehUOIUUXUb/E1pKT42csqexWI2h6zxs7uj7w2cO/PE3r5aj95g/c+kSQloqU4bshhmi+kQ2F73naL10AxRgCea9cwbb9xjwhoM88MKYs27YG6W1JnAcaXW5gfISACetzzzbAijHoCHwJEfmOxGugMIm0+7Zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708324005; c=relaxed/simple; bh=p3zF3ZqBApEKi6a/GhK0dmTJTW+SmZ/mHlGibr6LBm0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZiWscwRFzaJrceFSQihXBh1ktpYAb0MUDgGv0JlSy0kl/245zDx/xvdP6EuYPYSVWCAq2lat1UYpj4f9Q81UGqRuBYHHjUPQyXqabgpZO4YuOdlkNWVjQe/uSLki/ltYAN12CkLVq86FAOWNRVoknUVzF1rnMd0UMjPNXcBQ8NM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UWmeEdO+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UWmeEdO+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708324002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rR6JN4gU7y3tOWM/kqUBGRZmH6XeMtMRLTOjNJqe0CU=; b=UWmeEdO+3tsuYXGDfBJNITUhNXQ8Czouzlw3/w/jzzlc3OigCzbxZiV0Vn0O9IZFVOuha0 ujNVTTgK4oUczg0Yb56fPTWvpXadCyMTmYapEBxHOWQXCrh0LNCIxhR37GeFwkCqkYs1Hy ZkNXJGe95ClwXbAg2kOnfUA0yRv3MZI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-9qAQDWPuP8WJxXpc_iyWiw-1; Mon, 19 Feb 2024 01:26:39 -0500 X-MC-Unique: 9qAQDWPuP8WJxXpc_iyWiw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABDCB185A781; Mon, 19 Feb 2024 06:26:38 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29C1548B; Mon, 19 Feb 2024 06:26:33 +0000 (UTC) From: Xiao Ni To: song@kernel.org Cc: yukuai1@huaweicloud.com, bmarzins@redhat.com, heinzm@redhat.com, snitzer@kernel.org, ncroxon@redhat.com, neilb@suse.de, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev Subject: [PATCH RFC 2/2] md: Set MD_RECOVERY_FROZEN before stop sync thread Date: Mon, 19 Feb 2024 14:26:20 +0800 Message-Id: <20240219062621.92960-3-xni@redhat.com> In-Reply-To: <20240219062621.92960-1-xni@redhat.com> References: <20240219062621.92960-1-xni@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 After patch commit f52f5c71f3d4b ("md: fix stopping sync thread"), dmraid stops sync thread asynchronously. The calling process is: dev_remove->dm_destroy->__dm_destroy->raid_postsuspend->raid_dtr raid_postsuspend does two jobs. First, it stops sync thread. Then it suspend array. Now it can stop sync thread successfully. But it doesn't set MD_RECOVERY_FROZEN. It's introduced by patch f52f5c71f3d4b. So after raid_postsuspend, the sync thread starts again. raid_dtr can't stop the sync thread because the array is already suspended. This can be reproduced easily by those commands: while [ 1 ]; do vgcreate test_vg /dev/loop0 /dev/loop1 lvcreate --type raid1 -L 400M -m 1 -n test_lv test_vg lvchange -an test_vg vgremove test_vg -ff done Fixes: f52f5c71f3d4 ("md: fix stopping sync thread") Signed-off-by: Xiao Ni --- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/md/md.c b/drivers/md/md.c index 54790261254d..77e3af7cf6bb 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -6337,6 +6337,7 @@ static void __md_stop_writes(struct mddev *mddev) void md_stop_writes(struct mddev *mddev) { mddev_lock_nointr(mddev); + set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); __md_stop_writes(mddev); mddev_unlock(mddev); } From patchwork Mon Feb 19 06:26:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Ni X-Patchwork-Id: 13562201 X-Patchwork-Delegate: snitzer@redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 664AD2030A for ; Mon, 19 Feb 2024 06:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708324011; cv=none; b=lgpZmfOdiwd9690a4yKg/rODq91z5Ln2S0JRrzGx/X6cz3EFD/+CU0/gkc9Em2cLutJLefE/9OS+3YGXSgspCn94C4mxMbskzX7bApPfi1YdtUpE2W3xSeBXLiuDQdqZd+5CuObo4zyL41JxoeFMlbjJl/kquqnLWy17KU64cZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708324011; c=relaxed/simple; bh=oSgRYGTEf/dulFhIkSuOVRWdtR0hwQ2/A/X0d3W4ilk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lij6JR36bUglw5QlRfLiiXz7IhLD4ta0kjM5U4N/YatcF/mfrmSarPpWry/NqQvEcpcJysxyUpAGJzJe29d4xTDtTTsc55HbbWc5usYWDHb0juotd4g8IvSm5R16N2dcWt7YLPTQ8Wt7BHnIgCxFHzlO/2VcQoPkKb7qYiJDws0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WskCv5mL; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WskCv5mL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708324009; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CiRXDnsLJGZiZ2myApdsnHktPfLZueKk1fT0FIW8PV0=; b=WskCv5mLAxaPz67kBS2wtYJgSZ7KJEs+vWg/led9nXn0KHaCz1tEd4WFMNWrSX8gRP+lbe GGiNpRK+80MMcRjx9jfNCih4+9f8ICqzH4oMXHpn4hKMcF8InGYTAWNubLuAIC03Ry+0gh +OsCYUs3NsaJe85ga5l8X94ayvPP7no= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-eNBJgSPyPyKwNWhGaj5YUg-1; Mon, 19 Feb 2024 01:26:44 -0500 X-MC-Unique: eNBJgSPyPyKwNWhGaj5YUg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2D5D85A58E; Mon, 19 Feb 2024 06:26:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BBEB48B; Mon, 19 Feb 2024 06:26:39 +0000 (UTC) From: Xiao Ni To: song@kernel.org Cc: yukuai1@huaweicloud.com, bmarzins@redhat.com, heinzm@redhat.com, snitzer@kernel.org, ncroxon@redhat.com, neilb@suse.de, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev Subject: [PATCH RFC 3/3] md: Missing decrease active_io for flush io Date: Mon, 19 Feb 2024 14:26:21 +0800 Message-Id: <20240219062621.92960-4-xni@redhat.com> In-Reply-To: <20240219062621.92960-1-xni@redhat.com> References: <20240219062621.92960-1-xni@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 If all flush bios finish fast, it doesn't decrease active_io. And it will stuck when stopping array. This can be reproduced by lvm2 test shell/integrity-caching.sh. But it can't reproduce 100%. Fixes: fa2bbff7b0b4 ("md: synchronize flush io with array reconfiguration") Signed-off-by: Xiao Ni --- drivers/md/md.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 77e3af7cf6bb..a41bed286fd2 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -579,8 +579,12 @@ static void submit_flushes(struct work_struct *ws) rcu_read_lock(); } rcu_read_unlock(); - if (atomic_dec_and_test(&mddev->flush_pending)) + if (atomic_dec_and_test(&mddev->flush_pending)) { + /* The pair is percpu_ref_get() from md_flush_request() */ + percpu_ref_put(&mddev->active_io); + queue_work(md_wq, &mddev->flush_work); + } } static void md_submit_flush_data(struct work_struct *ws)