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=1796385544; b=UlhANf3OYynB5yjbmH43ObA4KP792gNh45bykQER96LRWH/cGB9lfs3pVMflYWGEo8tP s3xnGP8wtV3ebmCHldx7vM9gss1Z/w8f3LelcqeH7XOSvdG37myzgUgZ1IRX6xzj4rb1w xt7u+hjvXncpqZjkaJuRYAnEiV3hmQMRXjHzTAaQ8q7jdrF3mUqh+y6UF4LX5/z+FiDzx vCP+VqJ2vgitEVvEf8YgA6g4bjWA/d73TvZ1IbFzGOhHR34QBG3dxSzy1A03CIUHcanqa 8yzDqk5Os0vNuQVdAY7t3fDfgrN0JI4vUCCTLNbIw0dtkRAdnxfUlmniglz8miZtMXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385544; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=DAmK3Tq12/xChy3gdyyTFeZQKVF6FHfVUj48QtJNmlg=; b=3WmL2/rKsNsUzc963RafxfK8X9fBCZdTb07sWmAg9xV08DIfGqRx+9Y6OPk1OnD1/Vom CKVN0cjrOVW+YcP52JTbPLW6tvMq7fVEkjMmVARuyECBkX5d4OuybKvXkeDQcTT817VE7 aEJgJuDnFw1LjAx2cduBGILVYiTq3AFg759XvkDruWTOlX82qfhpQTGnMek6ki5kputU/ 0ORXnhysZU6DEH3p4/Gu6M9GOC2/1erRnBGuxfcz4wncSRpsrnqiT0P4z0MAQhHSSSzQr kvErRV1B+/vLny1n2SG06E+kyWFvjaUSfdPjukoJO4QMEP7wCCKxqOkhOCxZquR32Bg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vRUX+v+x; 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 AD6DE606A322; Fri, 4 Dec 2026 11:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vRUX+v+x Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF94D1F00937; Fri, 4 Dec 2026 11:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385544; bh=DAmK3Tq12/xChy3gdyyTFeZQKVF6FHfVUj48QtJNmlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vRUX+v+xXo9+G8D56BIoSGXDi17+d7iZ4FJrbHRmmBKIdg1tSXr3dX/VNymAG9jjJ be3yb03nLmt5kC6p1sPW89VUoMy4pvedN6TcplDB+Iysd9M710ZD0Pv6pqdSygNK0j Vh671nE9A7uqN7gU4sdFfx3l4lz2u1W2PKL6Whh4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Paulo Alcantara Subject: [PATCH 6.6 0595/1167] smb: client: dont block dying tasks waiting for writeback on close Date: Fri, 4 Dec 2026 19:00:22 +0900 Message-ID: <20261204100717.553566477@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paulo Alcantara commit 15ea186abbcd04157c62e0901701870b812bb2bd upstream. cifs_flush() waits uninterruptibly for the writeback it starts. A task that gets killed while closing a file on a hard mount with an unresponsive server is stuck in D state until the server comes back. It also consumes any writeback error for a caller that is about to exit, hiding it from everyone else. Wait killably instead. If the closer gets killed, stop waiting and leave the error bits in the mapping for others to see; writeback already in flight completes on its own. Don't wait at all, nor check for errors, if it is already dying. This is also needed before letting dying tasks issue their writes from a worker, which would otherwise make them wait for every one of them. Fixes: d3f1322af8f8 ("cifs: wait for writeback to complete in cifs_flush") Signed-off-by: Paulo Alcantara Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/smb/client/file.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -3474,17 +3474,44 @@ fsync_exit: return rc; } +static int cifs_wait_writeback_killable(struct address_space *mapping) +{ + struct folio_batch fbatch; + pgoff_t index = 0; + int rc = 0; + + folio_batch_init(&fbatch); + while (!rc && + filemap_get_folios_tag(mapping, &index, (pgoff_t)-1, + PAGECACHE_TAG_WRITEBACK, &fbatch)) { + for (unsigned int i = 0; + !rc && i < folio_batch_count(&fbatch); i++) + rc = folio_wait_writeback_killable(fbatch.folios[i]); + folio_batch_release(&fbatch); + cond_resched(); + } + return rc; +} + /* * As file closes, flush all cached write data for this inode checking * for write behind errors. */ int cifs_flush(struct file *file, fl_owner_t id) { + struct address_space *mapping = file->f_mapping; struct inode *inode = file_inode(file); - int rc = 0; + int rc = 0, rc2; - if (file->f_mode & FMODE_WRITE) - rc = filemap_write_and_wait(inode->i_mapping); + if (file->f_mode & FMODE_WRITE) { + rc = filemap_fdatawrite(mapping); + if (fatal_signal_pending(current) || + cifs_wait_writeback_killable(mapping)) + return 0; + rc2 = filemap_check_errors(mapping); + if (!rc) + rc = rc2; + } cifs_dbg(FYI, "Flush inode %p file %p rc %d\n", inode, file, rc); if (rc) {