All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Liu Kui <kui.liu@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: azaitsev@virtuozzo.com, devel@openvz.org,
	Liu Kui <kui.liu@virtuozzo.com>
Subject: [Devel] [PATCH hci-8.0] fs/fuse: fix writectr imbalance when failing writeback of invalidated file
Date: Fri, 18 Sep 2026 18:25:41 +0800	[thread overview]
Message-ID: <20260918-vstor-145614-writectr-v1-1-588a9eff3aa3@virtuozzo.com> (raw)

The shoot-on-sight path in fuse_writepages_send() for files being
invalidated violates the writectr protocol: the increment is not
gated on writectr >=0, and the matching decrement lives in a separate
fi->lock critical section. A concurrent fuse_set_nowrite() and
fuse_release_nowrite() pair lands in that window observes writectr ==
FUSE_NOWRITE + 1 and triggers BUG_ON(fi->writectr != FUSE_NOWRITE) in
__fuse_release_nowrite():

  kernel BUG at fs/fuse/dir.c:1842!
  RIP: fuse_release_nowrite+0x45/0x50 [fuse]
   fuse_release+0xd0/0x300 [fuse]
   __fput+0xe1/0x2a0
   __x64_sys_close+0x3c/0x80

Fix it by always routing writeback through fi->queued_writes so the
writectr gating applies, and failing requests on invalidated files
in fuse_send_writepage() instead, where the existing out_free path
keeps the writectr increment and decrement balanced within a single
fi->lock critical section. Note that if a NOWRITE section is active,
queue the request instead of failing it immediately is harmless for
the file invalidation operation.

https://virtuozzo.atlassian.net/browse/VSTOR-145614

Signed-off-by: Liu Kui <kui.liu@virtuozzo.com>
---
Fix a writectr protocol violation in the shoot-on-sight writeback path
for invalidated files, which races with fuse_set_nowrite()/
fuse_release_nowrite() and triggers BUG_ON(fi->writectr != FUSE_NOWRITE)
in __fuse_release_nowrite() (vmcore analysis in VSTOR-145614).

https://virtuozzo.atlassian.net/browse/VSTOR-145614
---
 fs/fuse/file.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index c96a631b9529..180f60fc539a 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2237,6 +2237,11 @@ __acquires(fi->lock)
 	int err;
 
 	fi->writectr++;
+	if (fuse_file_fail_immediately(wpa->ia.ff)) {
+		/* File is under invalidation: fail request without sending */
+		mapping_set_error(wpa->inode->i_mapping, -EIO);
+		goto out_free;
+	}
 	if (inarg->offset + data_size <= size) {
 		inarg->size = data_size;
 	} else if (inarg->offset < size) {
@@ -2619,28 +2624,17 @@ static void fuse_writepages_send(struct fuse_fill_wb_data *data)
 {
 	struct fuse_writepage_args *wpa = data->wpa;
 	struct inode *inode = data->inode;
-	struct fuse_mount *fm = get_fuse_mount(inode);
 	struct fuse_inode *fi = get_fuse_inode(inode);
 	int num_pages = wpa->ia.ap.num_pages;
-	struct fuse_args *args = &wpa->ia.ap.args;
-	int shoot_on_sight = 0;
 	int i;
 
 	spin_lock(&fi->lock);
-	if (fuse_file_fail_immediately(data->ff)) {
-		shoot_on_sight = 1;
-		fi->writectr++;
-	} else {
-		list_add_tail(&wpa->queue_entry, &fi->queued_writes);
-		fuse_flush_writepages(inode);
-	}
+	list_add_tail(&wpa->queue_entry, &fi->queued_writes);
+	fuse_flush_writepages(inode);
 	spin_unlock(&fi->lock);
 
 	for (i = 0; i < num_pages; i++)
 		end_page_writeback(data->orig_pages[i]);
-
-	if (shoot_on_sight)
-		args->end(fm, args, -EIO);
 }
 
 /*

---
base-commit: 397370a45ebb33b582fe6e5c0b2240cc4edb7bc9
change-id: 20260918-vstor-145614-writectr-17baf632e5b7

Best regards,
--  
Liu Kui <kui.liu@virtuozzo.com>

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

             reply	other threads:[~2026-09-18 10:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 10:25 Liu Kui [this message]
2026-09-19 11:14 ` Alexey Kuznetsov
2026-09-21 15:09 ` Konstantin Khorenko
2026-09-21 15:55   ` Konstantin Khorenko
2026-09-21 15:58 ` Konstantin Khorenko

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=20260918-vstor-145614-writectr-v1-1-588a9eff3aa3@virtuozzo.com \
    --to=kui.liu@virtuozzo.com \
    --cc=azaitsev@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.