From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796062328; b=cFUUCrGzj33a3hsqKHDZ8N32ukiwstuw3BgJfnWYvdzL8G1zX+mHVnnyn5aKH2aasXDm Cu2NvCtTZ/cY5u0/5R9QBJWwhKbXfdH4PhQrQiKcQ5evUtQVUuQ19+yytLDBXnAksyyTx 0MZ0ZPwmon+lvFvT3IrJY/Uo7hf2sG4pa3ZtvEfjXpRVSCKVY62URmmd5JeudtgD6ospg eQ9cp8gj2+Q/NkWY9Nhbr5dkUNnxjsU5GuvesCqVcG7yETt7vHbt5NhTDnJxdM53S8nRL 0K/5YJzkK+5CU2AJAlrjTm6WAZ1bChwP4Bj7cluGMy3mDtOl3LyCNxizyA8Ud5kmJxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796062328; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=AL6rLL8DM8EGKvX98NxOg2UC+t/F4dFYqlO0U21iIaY=; b=SEtb8JPS2W5dxj7wxEIlofGCOcMPDhrkbu/EUzoIpusv4PtGxDZsurqGzFDYz/GrKvZt 4SfQU2gP0B/oC4Sd9kymVPwriefFgnf4oKsk0wMg3T5voIsE2Ueie1qxsHVNrTvUquAz2 /7wYmsd/mgFtf7hngNwOyAeAfQ/jblU8NL43Q0rgoHzdl9GXcGEG0vuSS9FkZ4WfEN4pU nLH1WNsQevQAr+1xG2wXG2z2IsaQdb6WrN7hUrGwcBQwgMXRvW5+Rt5o7ypQNWovG1YRP bVVGp/iOY9/h8ZlYfCkK0/YtaZqaElLbMsVjHNpV0BZ1K/eaPBXzSJJHe+f+Zpyoo+w== 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=cyaCQ+wh; arc=none smtp.remote-ip=209.85.216.41 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 18CE0606A682 for ; Mon, 30 Nov 2026 18:12:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 18CE0606A682 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=cyaCQ+wh Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-3b49a6e8212so4881655a91.2 for ; Mon, 30 Nov 2026 10:12:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796062326; x=1796667126; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AL6rLL8DM8EGKvX98NxOg2UC+t/F4dFYqlO0U21iIaY=; b=cyaCQ+whbKZpeY0CI67tIbWFST0yyWyuZj+djqsFjXYDfFunRGNNdH84ooAUcGv7a8 5n+uYOEFEwGalmnMj7GjyLcdaLS1RgLDySqhPSTpYkxg+ytH/5rkFNFg7ofGXksAY0R8 qFGikE/rBEU3vSl0ShRQ/msZOEqTcXVdmOYDlXSFeGlVdwWsqRq9zzJvO33U5reEVMJh vIJT4PsmAbqomgpRXIzGOaqgcyo3J5qTF2nxaKxL6A56nz6Ks+x92UZvbq9tlYfkMUsx G+cDKJfdWKlYl+NQRSfqrt1GkdesNJ42eMBjgEpfXS+lg+Vx88jqu26zjFZfMAU1wPg4 NZsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796062326; x=1796667126; h=content-transfer-encoding:mime-version:references:in-reply-to :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=AL6rLL8DM8EGKvX98NxOg2UC+t/F4dFYqlO0U21iIaY=; b=QG37pwlXqd1ji7PLLReWFv+Cwlxs2GJ67o0x5FqLaG/nr23Qu+6xfOYLNOmHzXlcKF lbjrrcjDSFYvBN2gJH5dGDb5i+g86roTbNyLWFW6z1b6EZ7wvIeQN5kdy6Vw+1zaKvYr bWkvTOmKMr4wOyxoyoD4H4VKmuwpqmEXoyzlLg7ZSc1MbVLS5r+fn/r/vHa2O+hLHtpl QGj9ok44sTRBQZ9n/m2iN7Y2TTAeBKxfg47kUm6c0YrpBWsQ0Rg3E2oFBHvtGIZjpP2t J/x+tVi+T6zWumtZ95LYEooFTCCF6uewm9+xW6us79KUjcGBofN/yPfvRxnxlDtumh9U X2Ww== X-Forwarded-Encrypted: i=1; AL+hErEGq8LU8bMvt02t+30CjgBBFHB3Ry4HR1eBU22oDDuW2TNnWZQBredO0C5Qwy818d4+HpBwsdhlIXcI@vger.kernel.org X-Gm-Message-State: APuU4Z+vCCo9Lnv/1gCzeOfhlh4zbYCjE4rQ591N9U7cnOdu/NfC6+95 DyXyXYR0y7+/lLiopyR+JgJkYJJRKJG86AyHiKeSiUjvoLdX8hk4ocug X-Gm-Gg: AZFdTZcuhzkaAjoFd7uWcli4HrAXgLK5MLpdcYMiITleHEhDoiM0IClXYowrQKiymeg EhHBUoWPbAV/xNpNQYZNQmCwuFWYJQuK3RWvaraRs+ZGJkjLrhUGYWh2dHy4pbytEB2oje9gA2W mzZzLXKm4gnTTwBWPg9jzov5Lvwt9xH+xHA2rup6jUKPQjpNlagFNU+IV0b42xvJI2mOCnWXl8x pxi+lJGbzb2kxhzQ12cZF9aXTRr52o3lxsnUe+VA/fxB8cCa0ntaJBw9DJ3YdZO/VeaCIA/+6hH RDf8O0zxHNdijkLCRdJJApclysPZT10DgivDm1nzLVBYhuU7fBDAq3A9P6VQh/C7lZZbKT5oo9w goMwImq7TMtSVxgljUQO/zqYxzK7u8IEjlwxJ6dwBJPuGCOBPKXzu2a0BlR7kec/f1u/uzkv/Rl +j5Wz6RhcbdjIptOUaj/OytOxkyewV7RbCXjFFdT4wDlZXSQ3PGQC4LdV/BSmp3POqKrftISveL PJ+PuicihFrR+9nOP+lZkMmfNW/R2ukkwkjjvDmtMTpnVmPZT+qhM+FBdmchQvxf84CdPnPjxwu x24658VpehKloK+IlDc3KejrxTVAT6hmRYwzCG3zBE46tJv7JXDhQsbA77LOpGpMUJBl5Y6aP4u Hxj6XYBVT4ujR9wDB12/NArkMQtJfUkTOl5BdRO7X3QZ88zkVtKxo/leL4xI7zSrxURSRHBXmDv rOy9r3cQEKRYcc4b0nZ6roUrys2Jw3mV6psFfgaTlyVg== X-Received: by 2002:a17:90b:2f8c:b0:3b0:b556:ba9b with SMTP id 98e67ed59e1d1-3b41c9b227fmr32312078a91.23.1796062326311; Mon, 30 Nov 2026 10:12:06 -0800 (PST) Received: from sid-dev-env.cgrhrlrrq2nuffriizdlnb1x4b.xx.internal.cloudapp.net ([4.155.54.158]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b4b3c71192sm37919254a91.5.2026.11.30.10.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 10:12:05 -0800 (PST) From: Siddharth Chintamaneni To: Paulo Alcantara Cc: Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , Allen Pais , Rachel Menge , Hardik Garg , Siddharth Chintamaneni , Gillian Laming , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] smb: client: drop dentries for dying cached dirs during unmount Date: Mon, 30 Nov 2026 18:11:58 +0000 Message-ID: <20261130181159.93456-2-sidchintamaneni@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130181159.93456-1-sidchintamaneni@gmail.com> References: <20261130181159.93456-1-sidchintamaneni@gmail.com> X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit During unmount, cifs_kill_sb() calls close_all_cached_dirs() to release all cached directory dentries and flush cfid_put_wq before calling kill_anon_super(). Three races allow a cached_fid's dentry reference to outlive close_all_cached_dirs() and trigger a busy-dentry panic in generic_shutdown_super(): 1. When invalidate_all_cached_dirs() or cfids_laundromat_worker() runs concurrently, it moves cached_fid entries from cfids->entries onto cfids->dying under cfids->cfid_list_lock, then drops cfid_list_lock before laundromat_work runs on cfid_put_wq. If close_all_cached_dirs() runs in that window, it only walks cfids->entries (missing cfids->dying) and flushes cfid_put_wq before laundromat_work is queued, leaving cfid->dentry held: Thread 1 (umount) Thread 2 (reconnect / open_dirs) ----------------- -------------------------------- invalidate_all_cached_dirs() spin_lock(&cfid_list_lock) list_move(&cfid->entry, &cfids->dying) spin_unlock(&cfid_list_lock) cifs_kill_sb() close_all_cached_dirs() spin_lock(&cfid_list_lock) walks cfids->entries (empty) spin_unlock(&cfid_list_lock) flush_workqueue(cfid_put_wq) kill_anon_super(sb) -> generic_shutdown_super() BUG: Dentry still in use (1) VFS: Busy inodes after unmount! mod_delayed_work(cfid_put_wq, &cfids->laundromat_work, 0) dput(cfid->dentry) [too late] 2. When two mounts share a cifs_tcon, close_all_cached_dirs() detaches cfid->dentry from cfids->entries without checking whether the dentry belongs to the unmounting superblock. This both clears cfid->dentry on live cached directories belonging to the sibling mount and allows cifs_sb1 to steal a dentry belonging to a concurrently unmounting cifs_sb2, letting cifs_sb2 reach kill_anon_super() before cifs_sb1 calls dput(). 3. When two mounts share a cifs_tcon and drop_cached_dir_by_name() (for example via rmdir on the sibling mount) drops the final reference in close_cached_dir() -> smb2_close_cached_fid(), it deletes cfid from cfids->entries under cfids->cfid_list_lock, unlocks cfid_list_lock, and calls dput(cfid->dentry) synchronously outside cfid_put_wq. A concurrent unmount of the superblock owning cfid->dentry can finish close_all_cached_dirs() and reach kill_anon_super() before that dput() completes. Fix these by walking both cfids->entries and cfids->dying under cfids->cfid_list_lock in close_all_cached_dirs() while filtering for dentries belonging to cifs_sb, and by detaching cfid->dentry under cfids->cfid_list_lock in smb2_close_cached_fid() while holding cifs_sb->outstanding_rreq across dput(dentry). Fixes: 3fa640d035e5 ("smb: During unmount, ensure all cached dir instances drop their dentry") Signed-off-by: Siddharth Chintamaneni --- Changes in v2: - Filter cfids->entries and cfids->dying in close_all_cached_dirs() for dentries belonging to cifs_sb. - Fix function name in commit description. fs/smb/client/cached_dir.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c index 50217f47a0ed1..2c6243cbe10e4 100644 --- a/fs/smb/client/cached_dir.c +++ b/fs/smb/client/cached_dir.c @@ -467,6 +467,8 @@ __releases(&cfid->cfids->cfid_list_lock) { struct cached_fid *cfid = container_of(ref, struct cached_fid, refcount); + struct cifs_sb_info *cifs_sb = NULL; + struct dentry *dentry; int rc; lockdep_assert_held(&cfid->cfids->cfid_list_lock); @@ -476,10 +478,19 @@ __releases(&cfid->cfids->cfid_list_lock) cfid->on_list = false; cfid->cfids->num_entries--; } + dentry = cfid->dentry; + cfid->dentry = NULL; + if (dentry) { + cifs_sb = CIFS_SB(dentry->d_sb); + atomic_inc(&cifs_sb->outstanding_rreq); + } spin_unlock(&cfid->cfids->cfid_list_lock); - dput(cfid->dentry); - cfid->dentry = NULL; + if (dentry) { + dput(dentry); + if (atomic_dec_and_test(&cifs_sb->outstanding_rreq)) + wake_up_var(&cifs_sb->outstanding_rreq); + } if (cfid->is_open) { rc = SMB2_close(0, cfid->tcon, cfid->fid.persistent_fid, @@ -576,6 +587,9 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb) continue; spin_lock(&cfids->cfid_list_lock); list_for_each_entry(cfid, &cfids->entries, entry) { + if (!cfid->dentry || + CIFS_SB(cfid->dentry->d_sb) != cifs_sb) + continue; tmp_list = kmalloc_obj(*tmp_list, GFP_ATOMIC); if (tmp_list == NULL) { /* @@ -594,6 +608,23 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb) list_add_tail(&tmp_list->entry, &entry); } + list_for_each_entry(cfid, &cfids->dying, entry) { + if (!cfid->dentry || + CIFS_SB(cfid->dentry->d_sb) != cifs_sb) + continue; + tmp_list = kmalloc_obj(*tmp_list, GFP_ATOMIC); + if (!tmp_list) { + cifs_tcon_dbg(VFS, "Out of memory while dropping dentries\n"); + spin_unlock(&cfids->cfid_list_lock); + spin_unlock(&cifs_sb->tlink_tree_lock); + goto done; + } + + tmp_list->dentry = cfid->dentry; + cfid->dentry = NULL; + + list_add_tail(&tmp_list->entry, &entry); + } spin_unlock(&cfids->cfid_list_lock); } spin_unlock(&cifs_sb->tlink_tree_lock); -- 2.43.0