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=mn0O/jwFo+w+mizboZM4CKPS1BiofN+lm8nln+Sqm1NExGpaktzvpm5MPOz/zkfllBcG INHGsjYNjIwaxf6nuKjQaHPIrzMujQ6KfaEgG2Vn7E1Dz+tw7cpwyY6U0UdPjopu9NEYQ 9NhftUO24wXK6RNCnJtE9rTZmNdpAW04NfpC1crgejC1SAHl2h1W9AvKUTxrohhkaeAC0 vC55DY4UPP9yYfACU5/tt70GWbWn9Z5PIsn7H0RvvBCo3caePmZo8qnGi5E3LX+7FaJ+G tmoAzfTgO+brVsSIDodm59F+bQwsCAXrm31mh2y0YN7lVqnuJNGc6+dw0l2aK8j+d/Q== 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=xVvJN78gf5leuEre76VxkHpwr7zERsg9jqwkqWrr1tg=; b=3xiGLPx619GxHCatKMSo379I4/2vI3p6xsvVgn0fq+RGQKxKm8B+m9C6kBpkN6/rVJNH HcwkuEsZ4tlNR9T45qtoTjHuAHLLT7URgAp3EKhQd4CZUDKwbA5xaLPcBoxUVuUrKcTAd OKFW0I79YzL2kTqW4m8AhPNs5GM0uSvIGKYBZl3iHCaXuSVj/OsJ4lnsanG/V5XFptijF d0OVwuQG6L3y/ewQf9K0cghMX6/gn6t+6t+eLI4jTQaOpXCoJ5OXwkNJOl6PvBDGOML87 GwITRx08RHBbdNNTPwCcUk51+C8MtESeW8zTNURm8cPp2JBlW1UiG3E9ycOadxbpVXA== 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=Kv+VB6ew; 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 E7956606A334 for ; Mon, 30 Nov 2026 18:12:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E7956606A334 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=Kv+VB6ew Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-3b542b4d7bcso1172300a91.0 for ; Mon, 30 Nov 2026 10:12:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796062327; x=1796667127; 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=xVvJN78gf5leuEre76VxkHpwr7zERsg9jqwkqWrr1tg=; b=Kv+VB6ewefuOjJFhY9GA+cRGfDQVWaDn0s3C20W+LllNmAIH/seZ4fGeRN45v+S88F WRvQmqgjPO9ITrxt6ByoizvCI+II1PEHjyzKyEUGRe2S/SOgz/dTxp/VzK+2rlO/Cgun NmCvNBNIiTqMa/k/RrTepwAep1KY+CC6VynxpbOjiWBGuc8Wdsriv6WbnB/cYCaS6k1g 1gjkLXFAHfvvXmIaYVMFPMflj19fji8kr5BHtlc49coW/IfCZiglgo7Qgt/O8gKVThXZ r8cTe+gEmvRehJZzAq+1/fXoEUDTzj2udBAd/Ah001EFXSgJePovFPX0sLNX6CdUuF5b bSlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796062327; x=1796667127; 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=xVvJN78gf5leuEre76VxkHpwr7zERsg9jqwkqWrr1tg=; b=sW5V8+VfREreIqAxIinwn92ziRLKBqZYuVXbhTwEwzBy83n7narN8s6pshvEYQ6r4T N+MD/LcWiY0Qfvqp+yfFXCGZEjFjRot9Qg0Clg7Io1lVLq4Y6Tg/NZ74SS9GxQ3Z44wT LZmOBxBfsyh8OjLmeMjkdBTjR8orfwwceNfywZjOm8NVPN0XmyEuT6AaqPbVhYkGVvE1 I08zG5D3/qtAjeNMFA78/FHhSoCrIGa+vq3dT6z5WUV0N3TMTrj3vVLbrZwswbl1p2jA Rr57lJohY8O5hyZCjEc8XDDoGER+qGO89f35s3NLMjMYbY9BSefAzhy7dqvkwYOn/+K7 bFaQ== X-Forwarded-Encrypted: i=1; AL+hErGX+WbAjBidpOQbnpfJ7xKgud1qA/UuzvERzRpafxQYjbmP8AMi8N0NlBOK6JRbI9PkfFMH9j7ZXcGs@vger.kernel.org X-Gm-Message-State: APuU4Z9kPXlwhL4pUUmCmf2+p/qMK44Y6bn/xqnUQJ7mH2W5UzKr5dna 3FYjjvqIdKFermRuNn69rVcYp2iJqkj0+vobS37jsuKwihujzQp547eL X-Gm-Gg: AZFdTZd4p7WK5I+7q/6mmwDWO+u/7Qn6O28XkJk/P8MIlIFhDMScoBDouLzCGFmIlxO 98jXersQpcK7gplkeM7HOicb9/eDteWzLBEp+icKgVoo7uXKTNrPiqdcvctZx1sXT58FrY9cOGM sUpfT9b8LDv0LJQhGDds3put+2xf1rHA6I0Yw69b8RbkOMHyuDdzZ8mA3PGD3bea3zCzQk8Jbzl Lz6wPH9b5fPdD3o12TxoFnLB5tOZyEemVzmVtXvfqqfh/qjp9oNUX1bOsT2M0w7bg26+sSMu7A9 ynkf9bPamsaHLZ9aOPQooiefdU1PYsktmuXpCA1EZBnb+mNzku3A3luR1MRZKFbH1jtXaEx0Y6Y u2E4h8VSxpNWZR9Gd0IaMD8kQW1mYqTAO4WnSBQwZragcy7rqRtR+yMEjy1o0hL7raQPaXJii33 +NEaOceBvjdo+ExIWprhZV08cY6RC45jewSgg+rz6MbyWPOiGc8jGEqW4YgBUYO3GKqbAJJN02/ GUCy2J1HO0mFnOl9MdRkZFCaJW17fg6nvi9a1NDe3FS/I1yen8I26Em41T4xhzBU3MAigtxWpf1 I0rNiGpuuE1WyfBCF1D+1RLu7QYpprIoSP/DcimOl36NahITUIh94tT1ycE9YI5ABN5pxaEaQvw Fb30Af/Pg4q0BnNhbN3tr7TAGTm3n7xFJK6OWleBxa0szBLTRx/wPu2wJrMGNzcVZIZppBZPPay vb91JQOmwSS7ZhQ9gtBvFMOlav4QzaBruceGP68EBH X-Received: by 2002:a17:90a:e7d0:b0:3ab:e588:c275 with SMTP id 98e67ed59e1d1-3b41c8d4881mr31287467a91.20.1796062327002; Mon, 30 Nov 2026 10:12:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 10:12:06 -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 2/2] smb: client: fix busy dentry on unmount from cancelled deferred close Date: Mon, 30 Nov 2026 18:11:59 +0000 Message-ID: <20261130181159.93456-3-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 When cifs_close_deferred_file(), cifs_close_all_deferred_files(), or cifs_close_deferred_file_under_dentry() cancels a pending deferred close via cancel_delayed_work(&cfile->deferred), the cifsFileInfo is moved to a thread-local stack list (file_head) before open_file_lock is dropped and _cifsFileInfo_put() is called outside the lock. Because tcon->openFileList is shared across superblocks using the same tree connection, a concurrent operation or unmount on a sibling mount sharing the tcon can cancel a deferred close work item belonging to a superblock that is concurrently unmounting. Once cancel_delayed_work() removes the work from deferredclose_wq, cifs_kill_sb() observes neither a pending delayed work item on deferredclose_wq nor a non-zero outstanding_rreq counter, and proceeds to kill_anon_super() before _cifsFileInfo_put() drops cfile->dentry: Thread 1 (umount sb1) Thread 2 (sibling mount / rename) --------------------- --------------------------------- cifs_close_all_deferred_files(tcon) spin_lock(&tcon->open_file_lock) cancel_delayed_work(&cfile->deferred) list_add_tail(..., &file_head) spin_unlock(&tcon->open_file_lock) cifs_kill_sb(sb1) cifs_close_all_deferred_files_sb() [delayed_work_pending == false] flush(cifsoplockd_wq) flush(deferredclose_wq) wait(outstanding_rreq == 0) flush(serverclose_wq) flush(fileinfo_put_wq) kill_anon_super(sb1) -> generic_shutdown_super() BUG: Dentry still in use (1) VFS: Busy inodes after unmount! _cifsFileInfo_put(cfile, true, false) dput(cfile->dentry) [too late] Fix this by incrementing cifs_sb->outstanding_rreq while still holding open_file_lock whenever cancel_delayed_work(&cfile->deferred) succeeds, and decrementing it (waking any waiter in cifs_kill_sb()) after _cifsFileInfo_put() completes. Fixes: 340cea84f691 ("cifs: open files should not hold ref on superblock") Signed-off-by: Siddharth Chintamaneni --- Changes in v2: - Update Fixes: tag to 340cea84f691 ("cifs: open files should not hold ref on superblock"). fs/smb/client/misc.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 72a986bfaefc4..5072efd0ea568 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -502,15 +502,19 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode) { struct cifsFileInfo *cfile = NULL, *failed_cfile = NULL; struct file_list *tmp_list, *tmp_next_list; + struct cifs_sb_info *cifs_sb; LIST_HEAD(file_head); if (cifs_inode == NULL) return; + cifs_sb = CIFS_SB(cifs_inode->netfs.inode.i_sb); + spin_lock(&cifs_inode->open_file_lock); list_for_each_entry(cfile, &cifs_inode->openFileList, flist) { if (delayed_work_pending(&cfile->deferred)) { if (cancel_delayed_work(&cfile->deferred)) { + atomic_inc(&cifs_sb->outstanding_rreq); spin_lock(&cifs_inode->deferred_lock); cifs_del_deferred_close(cfile); spin_unlock(&cifs_inode->deferred_lock); @@ -528,11 +532,16 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode) } spin_unlock(&cifs_inode->open_file_lock); - if (failed_cfile) + if (failed_cfile) { _cifsFileInfo_put(failed_cfile, false, false); + if (atomic_dec_and_test(&cifs_sb->outstanding_rreq)) + wake_up_var(&cifs_sb->outstanding_rreq); + } list_for_each_entry_safe(tmp_list, tmp_next_list, &file_head, list) { _cifsFileInfo_put(tmp_list->cfile, false, false); + if (atomic_dec_and_test(&cifs_sb->outstanding_rreq)) + wake_up_var(&cifs_sb->outstanding_rreq); list_del(&tmp_list->list); kfree(tmp_list); } @@ -543,12 +552,15 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon) { struct cifsFileInfo *cfile, *failed_cfile = NULL; struct file_list *tmp_list, *tmp_next_list; + struct cifs_sb_info *cifs_sb; LIST_HEAD(file_head); spin_lock(&tcon->open_file_lock); list_for_each_entry(cfile, &tcon->openFileList, tlist) { if (delayed_work_pending(&cfile->deferred)) { if (cancel_delayed_work(&cfile->deferred)) { + cifs_sb = CIFS_SB(d_inode(cfile->dentry)->i_sb); + atomic_inc(&cifs_sb->outstanding_rreq); spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock); cifs_del_deferred_close(cfile); spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock); @@ -566,11 +578,18 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon) } spin_unlock(&tcon->open_file_lock); - if (failed_cfile) + if (failed_cfile) { + cifs_sb = CIFS_SB(d_inode(failed_cfile->dentry)->i_sb); _cifsFileInfo_put(failed_cfile, true, false); + if (atomic_dec_and_test(&cifs_sb->outstanding_rreq)) + wake_up_var(&cifs_sb->outstanding_rreq); + } list_for_each_entry_safe(tmp_list, tmp_next_list, &file_head, list) { + cifs_sb = CIFS_SB(d_inode(tmp_list->cfile->dentry)->i_sb); _cifsFileInfo_put(tmp_list->cfile, true, false); + if (atomic_dec_and_test(&cifs_sb->outstanding_rreq)) + wake_up_var(&cifs_sb->outstanding_rreq); list_del(&tmp_list->list); kfree(tmp_list); } @@ -618,6 +637,7 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, { struct file_list *tmp_list, *tmp_next_list; struct cifsFileInfo *cfile, *failed_cfile = NULL; + struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb); LIST_HEAD(file_head); spin_lock(&tcon->open_file_lock); @@ -625,6 +645,7 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, if ((cfile->dentry == dentry) && delayed_work_pending(&cfile->deferred) && cancel_delayed_work(&cfile->deferred)) { + atomic_inc(&cifs_sb->outstanding_rreq); spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock); cifs_del_deferred_close(cfile); spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock); @@ -640,11 +661,16 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, } spin_unlock(&tcon->open_file_lock); - if (failed_cfile) + if (failed_cfile) { _cifsFileInfo_put(failed_cfile, true, false); + if (atomic_dec_and_test(&cifs_sb->outstanding_rreq)) + wake_up_var(&cifs_sb->outstanding_rreq); + } list_for_each_entry_safe(tmp_list, tmp_next_list, &file_head, list) { _cifsFileInfo_put(tmp_list->cfile, true, false); + if (atomic_dec_and_test(&cifs_sb->outstanding_rreq)) + wake_up_var(&cifs_sb->outstanding_rreq); list_del(&tmp_list->list); kfree(tmp_list); } -- 2.43.0