From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385568; b=YRBwD0rO/7rGbWQYV2uPqtJw+G25LOsBro0ABBQjqegxP21y/8/utIJ625m7gDsYViPF VTxUZTdh3JTdLxuZCFi8P0VkiphnmKUH8hDRydLXB3cUsKImpcP+7sYvBsF3aWZK5D/nB 4stYhLaY3+j4w3XQTzgEodxH9S0VSK58rC37HTk1fkBneHJF45PP3gfGY9CBKqsQSXq39 36yJ9x0Fgi+2rUEkzcintgHgAwov4k5q7fpPkR8P2OkKK9wEz6lFiweyCfBr88BiYFzAw DQSE5OjDZJyHaPj3jAh5Fvs3MiPpGxpDmnvuiBbQryhIoHBoLYP9c8bs4MT6zaDd7yg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385568; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=1vAGpFTmpNBU/chPLX6lNE3SPKPUI1eI4XU7JHiINSw=; b=tvRivFkxCrILClbPHA7IrVAiyExhhfFT2nBqoEBEzm7sJKXX3OpeZQYVMA/dEc48Rhxp R8RObE6bbPgNsTRrTZLOZemmtJZ57ULHYTi8HbV3PH7br45ka2o2gqaP8AXX9/yjv3b9R DntA44K6SLdGk4XoiUIhAdEDCbI9lX5nFCKTIc9+tI3Jp8p+7lIStw/+oe21U2rSKTNWy me9TBkgAcWepGu+qp9yDjK6j01DQQCnsKoGR3UEuEthgRFL5cxv8t0AzMnBktqnOC2oJ3 WkHAEv3UmMceokuhuWwy1+UjxPB7797xyKybqaTfDlhgFPDZ1S0Yao06YaHWqyK1O1A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QsLQuIFE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DBEC606A33B for ; Fri, 4 Dec 2026 11:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QsLQuIFE Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6C4A1F00936; Fri, 4 Dec 2026 11:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385567; bh=1vAGpFTmpNBU/chPLX6lNE3SPKPUI1eI4XU7JHiINSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QsLQuIFESHmbnnK3OTmxzhhugT02wZvsd+If6u0R9a7Q2tDXMN14GpfTM3AzaHYnS 7xerZHADB+xm8BFhSRqPwV4rjxr3oA5U1Z+9J69kawh/tH/ToYqIPYLI/Ca3xhRz1I Hl0WFryFI66NCNLPF4c+XxNeucatLVMueaqCfmYWcWRE7kW9mdXOcClvpQMaAXLc9U h8QJEuanEj9XTWbHycGb9luf18Z0Wz6VQr+YyxZ/HRTAfdE4F7G1m0rI/S043NBH74 XsDJ8mS5oLQUC9KTatPhuyTU1pYwjzPjnUtufy8bpZZ9mjfsKHaoUPCJLzv5vAFOVI ju2RyafiV8zsA== From: Sasha Levin To: stable@vger.kernel.org Cc: Siddharth Chintamaneni , Adam Kim , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.1.y] smb: client: fix busy dentry and inode on unmount from late oplock break Date: Fri, 4 Dec 2026 06:59:25 -0500 Message-ID: <20261204115758.2886618-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120248-purely-chill-c526@gregkh> References: <2026120248-purely-chill-c526@gregkh> X-Mailing-List: stable@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 From: Siddharth Chintamaneni [ Upstream commit a10ec8dba77799a0460a4b3dfcac040ac452a325 ] During unmount, cifs_kill_sb() flushes cifsoplockd_wq and deferredclose_wq before waiting on cifs_sb->outstanding_rreq for in-flight netfs I/O requests to finish their cleanup_work in cifs_free_request(). While cifs_kill_sb() is waiting on outstanding_rreq, any cifsFileInfo referenced by an in-flight request (req->cfile) still has cfile->count >= 1 and remains on tcon->openFileList. If the SMB server sends a lease or oplock break for that file during this window, the demultiplex thread (cifsd) finds cfile on tcon->openFileList and calls cifs_queue_oplock_break(cfile), which takes a new reference on cfile and queues cfile->oplock_break onto cifsoplockd_wq after cifsoplockd_wq was already flushed: Thread 1 (umount) Thread 2 (cifsd) Thread 3 (workers) ----------------- ---------------- ------------------ cifs_kill_sb() flush(cifsoplockd_wq) flush(deferredclose_wq) wait(outstanding_rreq) [blocks: rreq == 1] SMB2 Lease Break finds cfile on list cifs_queue_oplock_break() queue(cifsoplockd_wq) cifsFileInfo_get(cfile) [cfile->count: 1 -> 2] cifs_oplock_break() ihold(inode) cifs_free_request() cifsFileInfo_put() [cfile->count: 2 -> 1] dec(outstanding_rreq) [wakes: rreq == 0] flush(serverclose_wq) flush(fileinfo_put_wq) kill_anon_super(sb) -> generic_shutdown_super() BUG: Dentry still in use (1) VFS: Busy inodes after unmount! Furthermore, cifs_oplock_break() itself holds the inode via ihold() after dropping cfile and may initiate writeback via filemap_fdatawrite(), spawning new netfs I/O requests. Fix this by counting queued oplock breaks in cifs_sb->outstanding_rreq from when cifs_queue_oplock_break() queues the work until cifs_oplock_break() finishes, so wait_var_event() in cifs_kill_sb() waits for both in-flight I/O requests and any late oplock breaks to complete. Fixes: 340cea84f691 ("cifs: open files should not hold ref on superblock") Cc: stable@vger.kernel.org Reported-by: Adam Kim Signed-off-by: Siddharth Chintamaneni Signed-off-by: Paulo Alcantara [ sashal: Adapted to the older outstanding_aio counter instead of outstanding_rreq, and used CIFS_SB(cfile->dentry->d_sb) with a new cifs_sb local in cifs_oplock_break(). ] Signed-off-by: Sasha Levin --- fs/smb/client/cifsfs.c | 8 ++++---- fs/smb/client/file.c | 3 +++ fs/smb/client/misc.c | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index 3e85bd5bc2608..953276516d638 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -300,10 +300,10 @@ static void cifs_kill_sb(struct super_block *sb) flush_workqueue(deferredclose_wq); /* - * Wait for all in-flight AIO contexts to finish cleanup so - * that their cifsFileInfo final puts have been queued, then - * drain the workqueues so the dentry refs are dropped before - * kill_anon_super(). + * Wait for all in-flight AIO contexts and oplock breaks to + * finish cleanup so that their cifsFileInfo final puts have + * been queued, then drain the workqueues so the dentry refs + * are dropped before kill_anon_super(). */ wait_var_event(&cifs_sb->outstanding_aio, !atomic_read(&cifs_sb->outstanding_aio)); diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 55f33278078d1..4e1c7b3f87fee 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -5245,6 +5245,7 @@ void cifs_oplock_break(struct work_struct *work) struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo, oplock_break); struct inode *inode = d_inode(cfile->dentry); + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifsInodeInfo *cinode = CIFS_I(inode); struct cifs_tcon *tcon; struct TCP_Server_Info *server; @@ -5338,6 +5339,8 @@ void cifs_oplock_break(struct work_struct *work) out: cifs_done_oplock_break(cinode); iput(inode); + if (atomic_dec_and_test(&cifs_sb->outstanding_aio)) + wake_up_var(&cifs_sb->outstanding_aio); } /* diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 5efcda855c215..929fbd7ecd243 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -634,6 +634,8 @@ void cifs_put_writer(struct cifsInodeInfo *cinode) */ void cifs_queue_oplock_break(struct cifsFileInfo *cfile) { + struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb); + /* * Bump the handle refcount now while we hold the * open_file_lock to enforce the validity of it for the oplock @@ -642,8 +644,10 @@ void cifs_queue_oplock_break(struct cifsFileInfo *cfile) * * Only take a reference if the work is actually queued. */ - if (queue_work(cifsoplockd_wq, &cfile->oplock_break)) + if (queue_work(cifsoplockd_wq, &cfile->oplock_break)) { cifsFileInfo_get(cfile); + atomic_inc(&cifs_sb->outstanding_aio); + } } void cifs_done_oplock_break(struct cifsInodeInfo *cinode) -- 2.53.0