Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Paulo Alcantara <pc@manguebit.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10.y] smb: client: don't block dying tasks waiting for writeback on close
Date: Wed, 25 Nov 2026 23:23:30 -0500	[thread overview]
Message-ID: <20261126042230.1914554-1-sashal@kernel.org> (raw)
In-Reply-To: <2026112534-bullfight-wanting-5e38@gregkh>

From: Paulo Alcantara <pc@manguebit.org>

[ Upstream commit 15ea186abbcd04157c62e0901701870b812bb2bd ]

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 <pc@manguebit.org>
Cc: stable@vger.kernel.org
[ sashal: Replaced folio batch and folio writeback-wait calls with pagevec and wait_on_page_bit_killable equivalents, and dropped the braces around the if (rc) body to match the older code. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/cifs/file.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 0da9c11cae278..a2b390facd7e0 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2676,17 +2676,50 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 	return rc;
 }
 
+static int cifs_wait_writeback_killable(struct address_space *mapping)
+{
+	struct pagevec pvec;
+	pgoff_t index = 0;
+	int rc = 0;
+	unsigned int nr, i;
+
+	pagevec_init(&pvec);
+	while (!rc &&
+	       (nr = pagevec_lookup_range_tag(&pvec, mapping, &index,
+					      (pgoff_t)-1,
+					      PAGECACHE_TAG_WRITEBACK))) {
+		for (i = 0; !rc && i < nr; i++) {
+			struct page *page = pvec.pages[i];
+
+			while (PageWriteback(page) && !rc)
+				rc = wait_on_page_bit_killable(page,
+							       PG_writeback);
+		}
+		pagevec_release(&pvec);
+		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)
-- 
2.53.0


      reply	other threads:[~2026-11-26  4:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 11:10 FAILED: patch "[PATCH] smb: client: don't block dying tasks waiting for writeback on" failed to apply to 5.10-stable tree gregkh
2026-11-26  4:23 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126042230.1914554-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=pc@manguebit.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox