From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795989992; b=JHYbWgDTDIv0GU9tbMCboYBoeoLn+hrfCDuDc0UODudfKohkMiU6SaDhAqnr/fYlMfS0 /nIk69/uQEBHM1v40GblF9EfjafAmf6lLAu99RcPRHMWL703vUcbQFwmjtLfdF8/Lu9il Dau4SuL29EIPf5UbcmhqNhDePAIVvdOdPjarpSu5hOJtISJJKEv809s0NX8+DcgDvI+ya dEfz4tynR1ElMQrE50aJdInWy5JYo74UknWbQ/oVfUMfsZ0qiKTExW6hm8u1OSWPphWzJ 1zKavdzBhYvAVS1p30fqixUx670KHvB2M9/Klybp/soUs+jB4o9dPwRuq/CudsqA+pQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795989992; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=QY7wrP+yk9/zMNH1BB+A9OoA5tnhusKVXWW5+sSQX4E=; b=nTNTMcjrT3Ckyed49Dx9k+/SL/R36uXPEH4HlgAmG3aeo7OPMgGUzaN1KakVjtoDeH+X wZQs3KVsWegEo5fcoQby93WuuhdFvHUi0k3IkxGX/0WTGn8ndiQeQSkxvsEhk2p5Cnev0 rMzzv/4SO037YrWuXyB5yBBFmzhQ2oMQ+K0diJxCIEbas01B3P9uoa78YDk9V9pGZr9HE oIa3GW86ch2yJ54oP4WdJiuP5dshmA/ECVh9CVavgsHAvhQe//enAN6JkS2sMcBeP1dv8 QzEbGyI/VKN3D0jzi/FpkMaPWXVCcrUWE4Iozw2XL/CmJEzcKHHyYTyBhuNVHWwK02w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qAaKyeUP; arc=none smtp.remote-ip=209.85.161.51 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F876606A327 for ; Sun, 29 Nov 2026 22:06:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F876606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qAaKyeUP Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-71ad1db7e31so6713504eaf.1 for ; Sun, 29 Nov 2026 14:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795989990; x=1796594790; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=QY7wrP+yk9/zMNH1BB+A9OoA5tnhusKVXWW5+sSQX4E=; b=qAaKyeUP9LF5ENC6DtUeLVlxLMso+S8ZcV0uT14wVNwkDzjBQXsd1tJKwiGe1mMsfX yvdzf2TvxcTsB/5nmKQ74/w3mSKMeBQMWjd8Vb4XU7YCKSunlFyggtyxldo1euFSqoa2 wjaiCpksed7slppsvjUXxscjMQzlOVKgvdAnqzpFidjkUzY6sBFORS8KvDF9VaEIlU/i Pdn5eby2aXH8xEpN6mNX2kJaMyElPzwwx5hx0Ncc7hbMgLQTVEIEzpsOJKiMqXoZJuII AR3QyDaYmHPSlKZTYJ/HdH/aqM74D/34fMzJg/PsfZen70bvT555UhZB/PrhIX8nOH/C JBaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795989990; x=1796594790; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QY7wrP+yk9/zMNH1BB+A9OoA5tnhusKVXWW5+sSQX4E=; b=u4w/ad0SMFqMABHlYZLT10Tgn90iwq5Nrw27ipBieEp61GrzPQ1rLTA99r3sUCb+HD ATRxKLflWxH5XZ/4C3KMe+cF+beyClPOjuKuMQLH26v/tAPmJ7cfw0kVlH4Up2S9Eggy HHYr5Ly1QlewLGyYvkuzP5zGGPIpAHNPzkRc8kcZmFwnkrt47mWicjePMnAN6LuvDCoG 8bPR9/7TtRSOhxCNFEIEUGVFjcwgTjmxZr80ne4qZM+iokZwzGjPzOil0WA20H6v2vJt YNSZiouwANLGrpibcy2rpo3DdlRwMB58/bv7ZR6jL7rF5Evx6F71BgCShJMeaRCdlbLc ayMA== X-Forwarded-Encrypted: i=1; AL+hErHxcU7QM5baAOPPeF2vS7Q7QRaEwq+bbVLWnTVTSXCFrI5PM/D6bzTA0OifTzdAzV1Wj/OIVSFe52s9va4=@vger.kernel.org X-Gm-Message-State: APuU4Z87nKXhTPFvABNeBJlq+j+oy74jzGalJmlXT3JWSiSAm1mA9N7A iKfikx9gf7XkPXvop15rF1fch8tP479WYU67RAP4rGn1q4bxnZBt3pI= X-Gm-Gg: AZFdTZd16u0zN/+RywnihKxsIJI8T8Pbf0NM6SLptEOFtWTR4J+AEdsM/V7EFJA0l3b 48QraajMrcriUmq9VBGEf9eHCMizKVwxi7rJZmppJmgytgO4J9ElVpDqovh/EtzlB12HYjZYqHb RrbldXtZBjg1d5YCZv69huyNjZe+czrCwXwuIYNqud5GOQTl0yPdR4FPFfXBLRrt8/+Ksc+Fa+z V3GJxLLJUfnR/PBAovWMKbTINQqQFeNa8Z0NpIkQ8ilrpoXqv16yinOauTycOzVuRyS52Kklbdh SUFz8wm6MO9WTb3aApUKCkIKCc4M6B8rckFe4soGTyORN4SkKhl69/d5GEJHEIaAIyc2fvIrXLw Enl/lMmo09BG5TBzvMnDxXzSVlXUXbBjY65s9W5AZJFOe4oGbz+JyWMPE3F0wpruo1S66dvoxbt f31rrlR5+l24/m6WVpant+mEDLTxItzkwZDmSpntqF/rw4LzxNGXOxB0u+34Kt8JdUbRXzyD5iB 4MjSNZBwIYO5AnTaHwk7cpjNL4t+qBfCgKyw/qbzkqgGBbloJw8Qslw50x+VErxbONDe662JHEC q/s7mz8qEXPGRlEabwpJklgrN9AqH4Z4to667AtMQrkX3SI9vtnVr9IvhoLnr4Uk1HNTEegYJoy gwlN1NUerJDvy3D4Gj8U2jkigCaxLPiIXcuqzzhEsQ/bKfOre2gqboKij+xIn5F8KxvcAtRj/w8 OEwIwsnAbRSJ45 X-Received: by 2002:a05:6820:190e:b0:71a:de89:ba50 with SMTP id 006d021491bc7-71b326d1250mr22099356eaf.27.1795989990498; Sun, 29 Nov 2026 14:06:30 -0800 (PST) Received: from [192.168.75.157] (162-232-235-235.lightspeed.livnmi.sbcglobal.net. [162.232.235.235]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc61081159sm27167371fac.15.2026.11.29.14.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 14:06:30 -0800 (PST) Message-ID: <6611465edc18c4cf6c2910ba756fb479fe813cec.camel@gmail.com> Subject: Re: [PATCH v2] NFS: pin the superblock across migration recovery From: Trond Myklebust To: teel4res@gmail.com Cc: anna@kernel.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Sun, 29 Nov 2026 17:06:28 -0500 In-Reply-To: <20261026105222.1150121-1-teel4res@gmail.com> References: <20261026105222.1150121-1-teel4res@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Mon, 26 Oct 2026 03:52:22 -0700, Cheng Yongkang wrote: > Umount may now wait for the migration attempt to finish, bounded by the > mount's RPC timeouts, the same trade-off as the other nfs_sb_active() > users. Is this description accurate? While the pin is held, umount(2) returns as soon as its deactivate_super() call has decremented s_active: fs/super.c:deactivate_super() { if (!atomic_add_unless(&s->s_active, -1, 1)) { __super_lock_excl(s); deactivate_locked_super(s); } } The wait goes the other way. The last nfs_sb_deactive() in the state manager runs the unmount teardown. There are questions about that below. [ ... ] > Fixes: c9fdeb280b8c ("NFS: Add basic migration support to state manager thread") This isn't a bug, but nfs4_handle_lease_moved() was added by commit b7f7a66e420a ("NFS: Support NFS4ERR_LEASE_MOVED recovery in state manager"). Should that commit get a Fixes: tag too? [ ... ] > diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c > index a5dec04..ff866f6 100644 > --- a/fs/nfs/nfs4state.c > +++ b/fs/nfs/nfs4state.c > @@ -2169,8 +2169,12 @@ restart: > &server->mig_status)) > continue; > > + if (!server->super || !nfs_sb_active(server->super)) > + continue; > + > rcu_read_unlock(); > status =3D nfs4_try_migration(server, cred); > + nfs_sb_deactive(server->super); When this drops the last reference, deactivate_super() runs nfs_kill_super() and generic_shutdown_super() here, on the state manager thread. NFS4CLNT_MANAGER_RUNNING is still set at that point. Once nfs4_try_migration() has called nfs4_begin_drain_session(), NFS4_SLOT_TBL_DRAINING is set too. Only the nfs4_end_drain_session() call at the bottom of the nfs4_state_manager() loop clears it. Can this deadlock against sync(2) on a pNFS mount? A pending LAYOUTCOMMIT does not hold an active superblock reference, because pnfs_set_layoutcommit() takes only an lseg reference. While a write delegation is held, nfs4_file_flush() may only start writeback. A close that sends no CLOSE, for example one for an open satisfied from the delegation, never reaches nfs4_do_close() and pnfs_roc(). If sync(2) reaches such an inode while the migration attempt has the table drained: sync(2) iterate_supers() super_lock(sb, false) <- s_umount held shared sync_inodes_sb() nfs4_write_inode() <- flusher, WB_SYNC_ALL pnfs_layoutcommit_inode(inode, true) nfs4_proc_layoutcommit(data, true) <- not privileged nfs4_layoutcommit_prepare() nfs4_setup_sequence() rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL) state manager nfs4_handle_migration() nfs4_try_migration() nfs4_begin_drain_session() nfs_sb_deactive() <- umount already returned deactivate_super() __super_lock_excl() <- waits for sync(2) Only nfs4_end_drain_slot_table() can wake the LAYOUTCOMMIT, and the state manager never gets back to it. Without pNFS there does not seem to be a deadlock. Dirty and unstable pages keep an open context, and with it an nfs_sb_active() reference, until their WRITE or COMMIT completes. The DELEGRETURN and LAYOUTRETURN sent from nfs4_evict_inode() become privileged once the inode is being freed. The teardown still runs inside the drain, though. evict_inodes() sends a synchronous DELEGRETURN for each delegation. Until it finishes, every non-privileged RPC for every mount that shares this nfs_client waits on slot_tbl_waitq. Before this patch the umount thread did that work, and the state manager went on to lift the drain. nfs_reap_expired_delegations() and nfs4_do_reclaim() already drop superblock references inside a drain in the same way, so this may need a common fix. Could the reference be held until after nfs4_end_drain_session() and nfs4_clear_state_manager_bit()? That is where nfs_client_return_marked_delegations() already runs. > if (status < 0) { > put_cred(cred); > return status; > @@ -2212,13 +2216,20 @@ restart: [ ... ] > inode =3D d_inode(server->super->s_root); > status =3D nfs4_proc_fsid_present(inode, cred); > - if (status !=3D -NFS4ERR_MOVED) > + if (status !=3D -NFS4ERR_MOVED) { > + nfs_sb_deactive(server->super); > goto restart; /* wasn't this one */ > - if (nfs4_try_migration(server, cred) =3D=3D -NFS4ERR_LEASE_MOVED) > + } > + status =3D nfs4_try_migration(server, cred); > + nfs_sb_deactive(server->super); > + if (status =3D=3D -NFS4ERR_LEASE_MOVED) The same question applies to both nfs_sb_deactive() calls added to nfs4_handle_lease_moved(). After a restart for -NFS4ERR_LEASE_MOVED, the "wasn't this one" release also runs inside the drain left by the previous nfs4_try_migration(). [ ... ] I've dropped this from my testing branch for now. On Mon, Oct 26, 2026 06:52 AM, Cheng Yongkang wrote: > The NFSv4 state manager walks clp->cl_superblocks under RCU in > nfs4_handle_migration() and nfs4_handle_lease_moved(), then drops the > lock and calls nfs4_try_migration() without holding a reference on > the > nfs_server or its superblock.=C2=A0 A concurrent umount can therefore run > nfs_kill_super() -> nfs_free_server() while migration recovery is > still > inside nfs4_update_server(): the server is removed from > cl_superblocks a > second time (DEBUG_LIST BUG), and once freed by call_rcu() the > migration > path still writes server->mig_status and touches server->super- > >s_root. >=20 > Pin the superblock with nfs_sb_active() before dropping RCU, as > nfs_client_for_each_server() already does, and drop it again with > nfs_sb_deactive() on every path: umount then detaches the superblock > but > cannot reach nfs_kill_super()/nfs_free_server() until migration > recovery > has finished and restored the server's list membership. > nfs4_handle_migration() releases the pin after nfs4_try_migration(); > nfs4_handle_lease_moved() releases it on both restart paths and > before > its final return. >=20 > Umount may now wait for the migration attempt to finish, bounded by > the > mount's RPC timeouts, the same trade-off as the other nfs_sb_active() > users. >=20 > Link: > https://lore.kernel.org/all/20261025180323.349533-1-teel4res@gmail.com/ > Fixes: c9fdeb280b8c ("NFS: Add basic migration support to state > manager thread") > Cc: stable@vger.kernel.org > Assisted-by: LLM > Signed-off-by: Cheng Yongkang > --- > v2: add Link, Fixes and stable tags, and remove local validation > details from the > commit message. >=20 > =C2=A0fs/nfs/nfs4state.c | 15 +++++++++++++-- > =C2=A01 file changed, 13 insertions(+), 2 deletions(-) >=20 > diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c > index a5dec04..ff866f6 100644 > --- a/fs/nfs/nfs4state.c > +++ b/fs/nfs/nfs4state.c > @@ -2169,8 +2169,12 @@ restart: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 &server->mig_status)) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 continue; >=20 > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!server->supe= r || !nfs_sb_active(server->super)) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0continue; > + > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rcu_read_unlock()= ; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D nfs4_t= ry_migration(server, cred); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0nfs_sb_deactive(s= erver->super); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (status < 0) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 put_cred(cred); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return status; > @@ -2212,13 +2216,20 @@ restart: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 continue; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 server->mig_gen = =3D clp->cl_mig_gen; >=20 > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!server->supe= r || !nfs_sb_active(server->super)) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0continue; > + > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rcu_read_unlock()= ; >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 inode =3D d_inode= (server->super->s_root); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D nfs4_p= roc_fsid_present(inode, cred); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (status !=3D -= NFS4ERR_MOVED) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (status !=3D -= NFS4ERR_MOVED) { > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0nfs_sb_deactive(server->super); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 goto restart;=C2=A0 =C2=A0/* wasn't this one */ > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (nfs4_try_migr= ation(server, cred) =3D=3D - > NFS4ERR_LEASE_MOVED) > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0status =3D nfs4_t= ry_migration(server, cred); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0nfs_sb_deactive(s= erver->super); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (status =3D=3D= -NFS4ERR_LEASE_MOVED) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 goto restart;=C2=A0 =C2=A0/* there are more */ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 goto out; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 }