From nobody Sat Jul 25 06:09:22 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94E9731E83A for ; Fri, 17 Jul 2026 05:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784265159; cv=none; b=W3MtCXFgII03amgcPw/QEI7LJsXw4fFmFirBhO7SspiimRvhocjrhG4MboxH+8VtkkPZza6kxJ6hKbJRt0HASE8qxtw6kZjIDEuYpiESX9LXagcXaUIAieilziDi6DyJL1AVGROL0Dwd6D+rNpogPXTOipc7mvRqPKo8L8GOZX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784265159; c=relaxed/simple; bh=7OgtVrX4qWjQ8RLN3/wCQTJOFkXr58vLLsN5TO3iZno=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GS63z04cJ8gI5fz/cLkUG/CfzCKwG9yqmQtkEsSmnTanIjCcJNrJJA7dECn9OxVt5TZQgZabsyXOcTcufKOLxFlSNgoS4QseaUbPLqdcWoxoY0QwvKTxtzA4dEJOZ13HzWLnRxfBqZ0JTb7VDT/E8N0vefaaiUyTSMDlw1TIFXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=CKtPvUVf; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="CKtPvUVf" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-49253e951cdso3007675e9.1 for ; Thu, 16 Jul 2026 22:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1784265155; x=1784869955; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=hY/aWdSFnzVfY4ztJ2GhxxkEtTKsmz44EPQBjeTA3NA=; b=CKtPvUVfmh4N7lhGD4GuXTJAYYkH0UQTviGwufmtcoKnVoMA3eIfDPXvCUyCcA0/G5 Ifm2lqKet+jDtDhIApZNzkVGLpDjp3PLt2T58C1MCi6MD4iSTYzPvr/kXBDjZ9SaPW7w 5TrE8k1VxAodRtWH517wZCY1FUH6tFx+oL36aI30MPc3V0+ECflNiHSUyMy1+7TCpcS4 jvf/SkSYjw2YtGFr2uaHl/0Ba3lEtHvIloPnQu21ckyqJ5PcIZZOmh0t4DfK2TizFyBK l7ROlqasolVkqg/ZSye2tR//1PrhwHoIfa/qRXBOC1oujdTpIbY8Kt/WqrpQVQdcWptE 4w7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784265155; x=1784869955; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hY/aWdSFnzVfY4ztJ2GhxxkEtTKsmz44EPQBjeTA3NA=; b=IJLBuo8RY8rky1+f6VGJMYU4RD8y+kJXL7kVRbxIeMYGNT/q8Oxu0o2c3jcfLfiJSJ xbLOh6xlZYZBzShcMyzI79PlgGy0MuZcQKfaOBTvvBrMQ1qAAUNcr0gQlLF9eJK22asA MCDb+XPAkqXRXrdOVigOlnI7uoxZqsjtE4iQpfenRfI9BllcceufPnlMxp/ClsfC8Hq+ GqV634ICCtDRAK1Y93XI4pDlYaijmz58EQhLoUR3nlXo9I3xNIm3c4lVy+vv9hNRz8m7 y9ZDqMudoQJvI9I3uNqZkVjT3CQEx9N4/LLd5Icf6ako/KivsRLCy11Gg7txWuSgwh7h r6Gg== X-Forwarded-Encrypted: i=1; AHgh+RptP6cMQKo8n5TrljWfLnLM4JGIxxl+ouwAWtQwFuDTVEjHGxcetyG8R0TeCjuoZwYV7hywVMtHFQBTFdY=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz733S8dUBQ12hI+bqwR3l1G9agKkY0xO3x1K8AMtvdtpxB9SU rWwgHv06xbP9RlfmAJdkd0qnCMfDcZgrVm9nIt4tcmnHdJZdAAryfhkrG3ZB2YMb/r8= X-Gm-Gg: AfdE7cnft2u689+92i0SGbJS3+4O5etfaPsWDdNj6Rm354jWhd7lWMv4wKHrlcNRRS0 txeFi7q20mRHA5cQLd5VIPbt+dK0Tzs9R/ee0bUIwyDHbFPXAw7jqDll7OA4jZGNfcPD07LO9vJ j5greYNzy1MY6C8DQyJcDIqIadJhCQ1x/q95qdKA2AyOprlWgFxivWbvJenu2vUtrk/p7rXS7Mr nm4/kXPAko8w9eiqrzqxth+2ibnQpkSyXk0pKUs/NScWd3J8WPueQ9dRuwGJz/0YrqEVhgT1o0o 2kbtN+3z3kll0uNStO8jmw5eTdaJB2mmMB/SIrMcr8XdRBRUjjc1+k4haXgN/ZN7PRXKdQzfEhp 0bc/o2oZZAl2Ksa+QDKjH1ODqdvbmjxhZQwqyO86PJtT/g8Qkau285kFsXJn/XyMpo+S4dXznu2 IxWd8aI6FcdGIMDmItE3vdxwuZYTfX3as4jA== X-Received: by 2002:a05:600c:350a:b0:493:f13a:3f74 with SMTP id 5b1f17b1804b1-4954a51df12mr5245285e9.5.1784265154725; Thu, 16 Jul 2026 22:12:34 -0700 (PDT) Received: from jwang-ThinkPad-T14-Gen-6.fritz.box ([2001:9e8:1455:9e00:bd6c:f8b2:6d2:3372]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549c96f19sm22952255e9.9.2026.07.16.22.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2026 22:12:34 -0700 (PDT) From: Jack Wang To: Song Liu , Yu Kuai Cc: Li Nan , Xiao Ni , linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, Jack Wang Subject: [PATCHv2] md: clear MD_CLOSING when array_state_store() bails on interrupted lock Date: Fri, 17 Jul 2026 07:12:33 +0200 Message-ID: <20260717051233.383373-1-jinpu.wang@ionos.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jack Wang Writing "clear", "readonly", "inactive" or "read_auto" to array_state calls mddev_set_closing_and_sync_blockdev(), which sets MD_CLOSING so the array cannot be reopened while it is being torn down. The flag is only cleared again at the tail of array_state_store() (for readonly, read_auto, inactive, or the failed-clear case). Between setting the flag and reaching that tail there is an early return: err =3D mddev_lock(mddev); if (err) return err; mddev_lock() is mutex_lock_interruptible() on reconfig_mutex. If the writing task is signalled while blocked there - easy to hit when the mutex is held for a long time by a running resync/recovery or reshape - it returns -EINTR and array_state_store() returns with MD_CLOSING still set. do_md_stop()/md_set_readonly() never ran, so the array keeps working internally, but every subsequent md_open() now returns -ENODEV for all callers: the device still shows up in /proc/mdstat and sysfs is fully populated, yet it cannot be opened and cannot be recovered without a reboot (the remaining clear paths either need the device open or re-enter test_and_set_bit(MD_CLOSING) and bail with -EBUSY before the clear). Route the interrupted-lock exit through a common label so the flag is released. Guard the clear with a set_closing flag that records whether this write actually set MD_CLOSING: when mddev->pers is already NULL (for example a concurrent STOP_ARRAY is mid-teardown) this write skips the mddev_set_closing_and_sync_blockdev() call above, so it must not clear a MD_CLOSING that the other thread owns - doing so could let the array be reopened while it is being destroyed. This also tightens the pre-existing tail clear, which had the same unconditional behaviour. mddev_unlock() is correctly skipped on the goto path since the lock was never acquired. Fixes: 99b902ac1725 ("md: sync blockdev before stopping raid or setting rea= donly") Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Jack Wang --- drivers/md/md.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index d1465bcd86c8..7b7a4d925907 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4649,6 +4649,7 @@ array_state_store(struct mddev *mddev, const char *bu= f, size_t len) { int err =3D 0; enum array_state st =3D match_word(buf, array_states); + bool set_closing =3D false; =20 /* No lock dependent actions */ switch (st) { @@ -4668,6 +4669,7 @@ array_state_store(struct mddev *mddev, const char *bu= f, size_t len) err =3D mddev_set_closing_and_sync_blockdev(mddev, 0); if (err) return err; + set_closing =3D true; break; default: break; @@ -4696,7 +4698,7 @@ array_state_store(struct mddev *mddev, const char *bu= f, size_t len) } err =3D mddev_lock(mddev); if (err) - return err; + goto out_clear_closing; =20 switch (st) { case inactive: @@ -4769,8 +4771,17 @@ array_state_store(struct mddev *mddev, const char *b= uf, size_t len) } mddev_unlock(mddev); =20 - if (st =3D=3D readonly || st =3D=3D read_auto || st =3D=3D inactive || - (err && st =3D=3D clear)) +out_clear_closing: + /* + * Only clear MD_CLOSING if this write actually set it. Otherwise a + * concurrent teardown (e.g. STOP_ARRAY) may own the flag - this write + * would have skipped setting it above when mddev->pers was already + * NULL - and clearing it here would let the array be reopened while it + * is being destroyed. + */ + if (set_closing && + (st =3D=3D readonly || st =3D=3D read_auto || st =3D=3D inactive || + (err && st =3D=3D clear))) clear_bit(MD_CLOSING, &mddev->flags); =20 return err ?: len; --=20 2.43.0