From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185998; b=iG12HswZx6wbVk8/2xkkvEpNzphljcTDO9ikGqczjsLhidocRc7/jDMLzHtdX64gj7jG MvvX7wIgEfjYG7+EsZ+XUByfhKdpEE3yZq+oBKhYSyimS+FrwtDE/58FSVAkMPyoHSUbY YoFN3FGROEKW5mzEQqZ21FwkZ4qzknI3w05Fd3gOXCTfjbjmIT7NSI8f0GzRbW8yJKc9t KR10eqenjJX6rmZRiQHdHco7wkHkfjLhHupKP2P4zCc4Gtl38MBHuZ+BaA2yz96hW1qIS N2ETd6r42UVsHrYMI0iiAxmcXcALEA0s8dFrKbS3zr2nRX/rUSuSIjUBK+qfs6AVe3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796185998; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=LRIZHFKWeI06nzbh9MbYvRDEkTs9CEvFBI5y/Y/eJxg=; b=RfDfaNqgkTyjQ12QUguatBsCEmjiCkCm+NjqntOl1QhBTOP68rP8rCwTBDOxXyumYhZh +BayOSxGf8Yo9UV2RuR8HWpUnCBvtmmhg85fZlUCK2zt2IyGr+FAybyty8s/y4m7u+T8R ISEBrGlKoU/3lcn1u4ihfXaCB6XJqThsjjbgfEaqxkmviTvMwzHHJOAB8XIcNbfZLvmsW N1fd34Ao+SEi4zK4cEeD4u+uZRC2AcF3foWuoSqiqlyTgeeEWbbKkX1vvoGMiFRGyVRkc hQuwNOFa+sUidgjbncL1Grsj8A8gx1n9RDmK5L6hAh5Sjqvb8idM1dDdARxRLd/EJGQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Yd+ag9tF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B5CE606A322 for ; Wed, 2 Dec 2026 04:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Yd+ag9tF Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8B611F00896; Wed, 2 Dec 2026 04:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796185997; bh=LRIZHFKWeI06nzbh9MbYvRDEkTs9CEvFBI5y/Y/eJxg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Yd+ag9tFjFkj/L774+tEalSnBKv6SymSFgCmJvisxLXnxPbc0AAAKKeVq89H8nUfN zW+/hCtH8eOYLxVphI+2ACN8zjxmihXCLXWxHuzWwTZG6y6zS43GURgh/QJmBg5D1X 5gplQacefo5XuxeB5j00ADqTFMemFRH838+9KVTpfGASICmrTVM++dX4Ty3qPuMdni GUQnNtmK4PnF4uuFljXWeEZ4mU/VLFM+hTyggDde9O4vLalO6SZkuk2kR00JanYGz/ 0oYF46kf7Z96p9Q9B3VXqATls1W+WUzZ999mzrTsvJTmcMytzMah18pkopZXtxnDMJ zU6XEvMwr7lFA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] md: flush running sync_work in stop_sync_thread() Reply-To: sashiko-reviews@lists.linux.dev To: "Thanh Nguyen" Cc: linux-raid@vger.kernel.org, yukuai@fygo.io In-Reply-To: <20261202041327.616-1-thanhnguyentuan2007@gmail.com> References: <20261201084150.1120-1-thanhnguyxntester@gmail.com> <20261202041327.616-1-thanhnguyentuan2007@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 04:33:17 +0000 X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] md: stop_sync_thread() retry interrupts new sync in md_idle_sync_thread() -- commit 71abb1be4745952743263f8a77a5e5ef3f06af23 Author: Thanh Nguyen md: flush running sync_work in stop_sync_thread() This commit updates stop_sync_thread() to check work_busy() instead of work_pending(), flush mddev->sync_work even when MD_RECOVERY_RUNNING is already cleared, and retry after re-acquiring reconfig_mutex if a new sync_work was queued while unlocked. > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 47da9edc1c606..6be40840b8499 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -5210,10 +5210,16 @@ static void stop_sync_thread(struct mddev *mddev,= bool locked) > { > int sync_seq =3D atomic_read(&mddev->sync_seq); > =20 > +retry: > if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { > - if (!locked) > - mddev_unlock(mddev); > - return; > + if (!work_busy(&mddev->sync_work)) { > + if (!locked) > + mddev_unlock(mddev); > + return; > + } > + mddev_unlock(mddev); > + flush_work(&mddev->sync_work); > + goto relock; > } > =20 > mddev_unlock(mddev); > @@ -5224,7 +5230,7 @@ static void stop_sync_thread(struct mddev *mddev, b= ool locked) > * never happen > */ > md_wakeup_thread_directly(&mddev->sync_thread); > - if (work_pending(&mddev->sync_work)) > + if (work_busy(&mddev->sync_work)) > flush_work(&mddev->sync_work); > =20 > wait_event(resync_wait, > @@ -5232,8 +5238,14 @@ static void stop_sync_thread(struct mddev *mddev, = bool locked) > (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery) && > sync_seq !=3D atomic_read(&mddev->sync_seq))); > =20 > - if (locked) > +relock: > + if (locked) { > mddev_lock_nointr(mddev); > + if (work_busy(&mddev->sync_work) || > + (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery) && > + test_bit(MD_RECOVERY_RUNNING, &mddev->recovery))) > + goto retry; > + } > } > =20 > void md_idle_sync_thread(struct mddev *mddev) [Severity: Medium] When called from md_idle_sync_thread(), can the unconditional work_busy(&mddev->sync_work) check at relock cause stop_sync_thread() to abort the newly started sync cycle and return while it is still running? md_idle_sync_thread() clears MD_RECOVERY_FROZEN to stop the current sync thread while allowing a subsequent sync operation to start. Once the first sync thread is reaped, mddev->thread can queue mddev->sync_work for the next sync cycle before stop_sync_thread() re-acquires reconfig_mutex: CPU0 (md_idle_sync_thread) CPU1 (mddev->thread) stop_sync_thread(mddev, true) sync_seq =3D atomic_read(...) mddev_unlock(mddev) set_bit(MD_RECOVERY_INTR, ...) wait_event(resync_wait, ...) md_check_recovery() md_reap_sync_thread() atomic_inc(&mddev->sync_seq) clear_bit(MD_RECOVERY_RUNNING, ...) set_bit(MD_RECOVERY_NEEDED, ...) wake_up(&resync_wait) mddev_unlock(mddev) md_check_recovery() set_bit(MD_RECOVERY_RUNNING, ...) clear_bit(MD_RECOVERY_INTR, ...) queue_work(..., &mddev->sync_work) mddev_lock_nointr(mddev) work_busy(&mddev->sync_work) goto retry mddev_unlock(mddev) set_bit(MD_RECOVERY_INTR, ...) <-- aborts the new sync cycle flush_work(&mddev->sync_work) wait_event(resync_wait, ...) <-- sync_seq !=3D mddev->sync_seq is already true; returns immediately Because sync_seq is sampled before the retry label and never refreshed, wait_event() does not wait for the newly interrupted sync thread to exit, leaving MD_RECOVERY_RUNNING set when md_idle_sync_thread() returns (causing callers such as dm-raid's raid_message() to fail with -EBUSY). Should the retry at relock skip work_busy(&mddev->sync_work) when !test_bit(MD_RECOVERY_FROZEN, &mddev->recovery) and sync_seq has already advanced? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202041327.616-= 1-thanhnguyentuan2007@gmail.com?part=3D1