Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795989992; b=Hp8h2tHtTRdLcuBoie5J08Sm5TB2lJxeuBkx0HdSNRq4LBIwXyvV9EqizcLHj5Co1YDf A4GZZiWwUVjXbjWLFudDqkck0dqbdndn7KIZqNuxvjtEr1i6/6NL1jFWpjE5HxSi8uunU tLM4tmtKQ164cNhbNn25qo+GfNsmTJOnGDh/ti8cawR3pbo/OSoQ5HIzrzY+ZRbxJb3IS Sr1+6kDor/sZFHjwTL6yfYe5RXTTr3AwlfKpAGepkMcgs0JcKsAJ7pA0VQmZjlbKa0ZUG 4elR+0NjvaH0zWU97fvV/NW4jD70udZ8jtWPO+K9le4T3Fz5P/6xe3lN9SgVrnAE8mQ== 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=ohLSOnz2o61logmkqp4q1PToQy/I5e9wAVJQ3X4ThxCbv7982ETkP1hOZKEL2F5z788O Ay1kOpNXv8FxPxTP+dQexqaE24/RjeeAa7+FcOlE0/Mohq4oWss6fBn6155+EAsdEtJ0R aZK2vfsAijrjk2k4mAa6CoD8udrDANaXh5qi7YbCdig6Cc9jJz28Fb9F3vzBNRHXx1SOh 3KT8HU1nKk30hRBn0Iez0Ob4d1P2AUNisUuiP9mzmkZqJFFLT3EgFzwKWQdNnVKRbEv1w d6XcjRVWmAwO4BKPxZzUNSV2hewtx2NWnysM91XTHVqtp5FCpT3SWZQdyNUI3Qa2sTQ== 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.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 9674F606A325 for ; Sun, 29 Nov 2026 22:06:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9674F606A325 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-f52.google.com with SMTP id 006d021491bc7-71ad1db7e31so6713505eaf.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=aVQGYMSD3l7WaLNPFQFDNlXl7aqZXzZPYH30s2olCNiTWObvgJN0rBF6nU5FI8B6Gv ebcam2jBFtL5qnE0aWxlYt09lhkeWgHsGoQuzyE8AYFP3bkLTSiHank3pnYACSUIOFQw vV6sr564h8zZMY2Qd5lv581V7iPHO59LyR8vO6ULkziIUaBbWKC4VbJltmSiR6XD3R75 TGxzHInOZbkVJaxDlZsWxHQwlYJDvjv5gp1jrPHnJCHyNAWOjLKOO1xjqZJ5q0mQmvuB z+m1UXtk62Og8R7hKwu454XsW9SlKyMH5A13HBMdV5SKmnj64UIf5SdP6QaqSaLqT2oQ ObEQ== X-Forwarded-Encrypted: i=1; AL+hErEjAJ+cdIeOk27DLrdgOw1tLpU7tmcfX5UR6bUHKEV6f/d/Ens3pWTVQhJ4iXzYUPDMXUjNSooYEEc=@vger.kernel.org X-Gm-Message-State: APuU4Z8WOvR8Ij5ACBxP7UFd3DGpFd9hUc1C90xo/tL+qTa2/B9/gdn9 kyK/8efWuyt4mFelEDzDaqYM00mkpGvQccC0qXwUzwXnQLXw0s4ldms= X-Gm-Gg: AZFdTZdtMeUOfdhiODpUQZLNPDQqpfYUf5g+fD6lFCRZTVvMEcLuBXhdZPQDf/vo7ig YQ7iwE41HxW/lfnlZAEakmEax5aI+t7BLEK/Drdaa4M10Hy7zZVMH1NzfiOOnm3iT0Dm3ifX0RK 3ENSMtNsmPJHkz5KMJhiBvu9wWhojLjm3ZZO5WW+SqWsnMzfE6FLwffsxM6dTLJ2SxqjbEISpkW 7f6kFH/ArLx84lMxtOIkpIDT02Q9ocQmg4SeMzQxzMgzqoNeHPUWPhy2vHqCQgsIfAyk3MMm4pE PoQ+w0w+JwucElAJw5BX6tNWxKrtY1uzDkhY7vcwOU/thNqhpODCubrQ15BX7VGEYn6Sc5NFAbU mn5ZYh5ZmjYihNqpzOBUf3L53C+hl3W/3S24TbcF3rjOE0lxzSEq+j6gB0HI7Vnc8x+u/2yMxM6 r5beenL3mTAN1SXRHrJU5G4Hesb9AulSLGPFeaXXJ7FUwkGhr4/YO/kPoKmKfUBUf+jVYGDIDzm 6jaMzTbmzNxoq0KKdMAmcxqcqriIorxev3szgte9Z+jfoJbVLiCIKqWiDQpw4T3kGkrzVHqSTt6 ZdI5bXdiCzHlgjBDw8N1AUIFHFtIq0VOR0whoK8MpUqDTcPCi1BfsrCVzUiV0o1tAbDZyM9ZRW7 JZxunK7Ri07qdkUpCMfmlMlLd7oCUq/5y3nJw+cNKS2pjA0xumUPhN2eovP9wd7zOYv15PB5KQd lrGvWkzm54+E6v 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-nfs@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 }