stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, chenguanyou <chenguanyou@xiaomi.com>,
	Miklos Szeredi <mszeredi@redhat.com>,
	Ed Tsai <ed.tsai@mediatek.com>
Subject: [PATCH 5.10 18/33] fuse: make sure reclaim doesnt write the inode
Date: Wed, 15 Dec 2021 18:21:16 +0100	[thread overview]
Message-ID: <20211215172025.403287477@linuxfoundation.org> (raw)
In-Reply-To: <20211215172024.787958154@linuxfoundation.org>

From: Miklos Szeredi <mszeredi@redhat.com>

commit 5c791fe1e2a4f401f819065ea4fc0450849f1818 upstream.

In writeback cache mode mtime/ctime updates are cached, and flushed to the
server using the ->write_inode() callback.

Closing the file will result in a dirty inode being immediately written,
but in other cases the inode can remain dirty after all references are
dropped.  This result in the inode being written back from reclaim, which
can deadlock on a regular allocation while the request is being served.

The usual mechanisms (GFP_NOFS/PF_MEMALLOC*) don't work for FUSE, because
serving a request involves unrelated userspace process(es).

Instead do the same as for dirty pages: make sure the inode is written
before the last reference is gone.

 - fallocate(2)/copy_file_range(2): these call file_update_time() or
   file_modified(), so flush the inode before returning from the call

 - unlink(2), link(2) and rename(2): these call fuse_update_ctime(), so
   flush the ctime directly from this helper

Reported-by: chenguanyou <chenguanyou@xiaomi.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: Ed Tsai <ed.tsai@mediatek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 fs/fuse/dir.c    |    8 ++++++++
 fs/fuse/file.c   |   15 +++++++++++++++
 fs/fuse/fuse_i.h |    1 +
 fs/fuse/inode.c  |    3 +++
 4 files changed, 27 insertions(+)

--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -791,11 +791,19 @@ static int fuse_symlink(struct inode *di
 	return create_new_entry(fm, &args, dir, entry, S_IFLNK);
 }
 
+void fuse_flush_time_update(struct inode *inode)
+{
+	int err = sync_inode_metadata(inode, 1);
+
+	mapping_set_error(inode->i_mapping, err);
+}
+
 void fuse_update_ctime(struct inode *inode)
 {
 	if (!IS_NOCMTIME(inode)) {
 		inode->i_ctime = current_time(inode);
 		mark_inode_dirty_sync(inode);
+		fuse_flush_time_update(inode);
 	}
 }
 
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1849,6 +1849,17 @@ int fuse_write_inode(struct inode *inode
 	struct fuse_file *ff;
 	int err;
 
+	/*
+	 * Inode is always written before the last reference is dropped and
+	 * hence this should not be reached from reclaim.
+	 *
+	 * Writing back the inode from reclaim can deadlock if the request
+	 * processing itself needs an allocation.  Allocations triggering
+	 * reclaim while serving a request can't be prevented, because it can
+	 * involve any number of unrelated userspace processes.
+	 */
+	WARN_ON(wbc->for_reclaim);
+
 	ff = __fuse_write_file_get(fc, fi);
 	err = fuse_flush_times(inode, ff);
 	if (ff)
@@ -3338,6 +3349,8 @@ out:
 	if (lock_inode)
 		inode_unlock(inode);
 
+	fuse_flush_time_update(inode);
+
 	return err;
 }
 
@@ -3447,6 +3460,8 @@ out:
 	inode_unlock(inode_out);
 	file_accessed(file_in);
 
+	fuse_flush_time_update(inode_out);
+
 	return err;
 }
 
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1113,6 +1113,7 @@ int fuse_allow_current_process(struct fu
 
 u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
 
+void fuse_flush_time_update(struct inode *inode);
 void fuse_update_ctime(struct inode *inode);
 
 int fuse_update_attributes(struct inode *inode, struct file *file);
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -119,6 +119,9 @@ static void fuse_evict_inode(struct inod
 {
 	struct fuse_inode *fi = get_fuse_inode(inode);
 
+	/* Will write inode on close/munmap and in all other dirtiers */
+	WARN_ON(inode->i_state & I_DIRTY_INODE);
+
 	truncate_inode_pages_final(&inode->i_data);
 	clear_inode(inode);
 	if (inode->i_sb->s_flags & SB_ACTIVE) {



  parent reply	other threads:[~2021-12-15 17:26 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 17:20 [PATCH 5.10 00/33] 5.10.86-rc1 review Greg Kroah-Hartman
2021-12-15 17:20 ` [PATCH 5.10 01/33] nfc: fix segfault in nfc_genl_dump_devices_done Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 02/33] drm/msm/dsi: set default num_data_lanes Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 03/33] KVM: arm64: Save PSTATE early on exit Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 04/33] s390/test_unwind: use raw opcode instead of invalid instruction Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 05/33] Revert "tty: serial: fsl_lpuart: drop earlycon entry for i.MX8QXP" Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 06/33] net/mlx4_en: Update reported link modes for 1/10G Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 07/33] ALSA: hda: Add Intel DG2 PCI ID and HDMI codec vid Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 08/33] ALSA: hda/hdmi: fix HDA codec entry table order for ADL-P Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 09/33] parisc/agp: Annotate parisc agp init functions with __init Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 10/33] i2c: rk3x: Handle a spurious start completion interrupt flag Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 11/33] net: netlink: af_netlink: Prevent empty skb by adding a check on len Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 12/33] drm/amd/display: Fix for the no Audio bug with Tiled Displays Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 13/33] drm/amd/display: add connector type check for CRC source set Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 14/33] tracing: Fix a kmemleak false positive in tracing_map Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 15/33] KVM: x86: Ignore sparse banks size for an "all CPUs", non-sparse IPI req Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 16/33] staging: most: dim2: use device release method Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 17/33] bpf: Fix integer overflow in argument calculation for bpf_map_area_alloc Greg Kroah-Hartman
2021-12-15 17:21 ` Greg Kroah-Hartman [this message]
2021-12-15 17:21 ` [PATCH 5.10 19/33] hwmon: (dell-smm) Fix warning on /proc/i8k creation error Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 20/33] ethtool: do not perform operations on net devices being unregistered Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 21/33] perf inject: Fix itrace space allowed for new attributes Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 22/33] perf intel-pt: Fix some PGE (packet generation enable/control flow packets) usage Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 23/33] perf intel-pt: Fix sync state when a PSB (synchronization) packet is found Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 24/33] perf intel-pt: Fix intel_pt_fup_event() assumptions about setting state type Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 25/33] perf intel-pt: Fix state setting when receiving overflow (OVF) packet Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 26/33] perf intel-pt: Fix next err value, walking trace Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 27/33] perf intel-pt: Fix missing instruction events with q option Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 28/33] perf intel-pt: Fix error timestamp setting on the decoder error path Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 29/33] memblock: free_unused_memmap: use pageblock units instead of MAX_ORDER Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 30/33] memblock: align freed memory map on pageblock boundaries with SPARSEMEM Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 31/33] memblock: ensure there is no overflow in memblock_overlaps_region() Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 32/33] arm: extend pfn_valid to take into account freed memory map alignment Greg Kroah-Hartman
2021-12-15 17:21 ` [PATCH 5.10 33/33] arm: ioremap: dont abuse pfn_valid() to check if pfn is in RAM Greg Kroah-Hartman
2021-12-15 18:32 ` 5.10.85 breaks CIP testing Re: [PATCH 5.10 00/33] 5.10.86-rc1 review Pavel Machek
2021-12-15 18:40   ` Greg Kroah-Hartman
2021-12-15 20:00 ` Jon Hunter
2021-12-15 21:52 ` Shuah Khan
2021-12-15 23:28 ` Florian Fainelli
2021-12-16  1:12 ` Fox Chen
2021-12-16  9:06 ` Samuel Zou
2021-12-16 10:54 ` Naresh Kamboju
2021-12-16 18:07 ` Guenter Roeck

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=20211215172025.403287477@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=chenguanyou@xiaomi.com \
    --cc=ed.tsai@mediatek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mszeredi@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).