All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: Xie Yongji <xieyongji@bytedance.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] fuse: Fix deadlock on open(O_TRUNC)
Date: Mon, 16 Aug 2021 14:39:14 +0200	[thread overview]
Message-ID: <YRpcck0FHaH+uxgp@miu.piliscsaba.redhat.com> (raw)
In-Reply-To: <20210813093155.45-1-xieyongji@bytedance.com>

On Fri, Aug 13, 2021 at 05:31:55PM +0800, Xie Yongji wrote:
> The invalidate_inode_pages2() might be called with FUSE_NOWRITE
> set in fuse_finish_open(), which can lead to deadlock in
> fuse_launder_page().
> 
> To fix it, this tries to delay calling invalidate_inode_pages2()
> until FUSE_NOWRITE is removed.

Thanks for the report and the patch.  I think it doesn't make sense to delay the
invalidate_inode_pages2() call since the inode has been truncated in this case,
there's no data worth writing out.

This patch replaces the invalidate_inode_pages2() with a truncate_pagecache()
call.  This makes sense regardless of FOPEN_KEEP_CACHE or fc->writeback cache,
so do it unconditionally.

Can you please check out the following patch?

Thanks,
Miklos

---
 fs/fuse/file.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -198,12 +198,11 @@ void fuse_finish_open(struct inode *inod
 	struct fuse_file *ff = file->private_data;
 	struct fuse_conn *fc = get_fuse_conn(inode);
 
-	if (!(ff->open_flags & FOPEN_KEEP_CACHE))
-		invalidate_inode_pages2(inode->i_mapping);
 	if (ff->open_flags & FOPEN_STREAM)
 		stream_open(inode, file);
 	else if (ff->open_flags & FOPEN_NONSEEKABLE)
 		nonseekable_open(inode, file);
+
 	if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) {
 		struct fuse_inode *fi = get_fuse_inode(inode);
 
@@ -211,10 +210,14 @@ void fuse_finish_open(struct inode *inod
 		fi->attr_version = atomic64_inc_return(&fc->attr_version);
 		i_size_write(inode, 0);
 		spin_unlock(&fi->lock);
+		truncate_pagecache(inode, 0);
 		fuse_invalidate_attr(inode);
 		if (fc->writeback_cache)
 			file_update_time(file);
+	} else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) {
+		invalidate_inode_pages2(inode->i_mapping);
 	}
+
 	if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache)
 		fuse_link_write_file(file);
 }

  parent reply	other threads:[~2021-08-16 12:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13  9:31 [PATCH] fuse: Fix deadlock on open(O_TRUNC) Xie Yongji
2021-08-16  2:35 ` Peng Tao
2021-08-16  5:35   ` Yongji Xie
2021-08-16 12:39 ` Miklos Szeredi [this message]
2021-08-16 13:16   ` Yongji Xie
2021-12-14 14:26   ` Luís Henriques
2021-12-14 15:19     ` Miklos Szeredi
2021-12-14 15:35       ` Luís Henriques

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=YRpcck0FHaH+uxgp@miu.piliscsaba.redhat.com \
    --to=miklos@szeredi.hu \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=xieyongji@bytedance.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.