--- /dev/null
+From 5c791fe1e2a4f401f819065ea4fc0450849f1818 Mon Sep 17 00:00:00 2001
+From: Miklos Szeredi <mszeredi@redhat.com>
+Date: Fri, 22 Oct 2021 17:03:01 +0200
+Subject: fuse: make sure reclaim doesn't write the inode
+
+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
+@@ -738,11 +738,19 @@ static int fuse_symlink(struct user_name
+ 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
+@@ -1848,6 +1848,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(fi);
+ err = fuse_flush_times(inode, ff);
+ if (ff)
+@@ -3002,6 +3013,8 @@ out:
+ if (lock_inode)
+ inode_unlock(inode);
+
++ fuse_flush_time_update(inode);
++
+ return err;
+ }
+
+@@ -3111,6 +3124,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
+@@ -1148,6 +1148,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
+@@ -118,6 +118,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) {
--- /dev/null
+From c29d9792607e67ed8a3f6e9db0d96836d885a8c5 Mon Sep 17 00:00:00 2001
+From: Adrian Hunter <adrian.hunter@intel.com>
+Date: Thu, 25 Nov 2021 09:14:57 +0200
+Subject: perf inject: Fix itrace space allowed for new attributes
+
+From: Adrian Hunter <adrian.hunter@intel.com>
+
+commit c29d9792607e67ed8a3f6e9db0d96836d885a8c5 upstream.
+
+The space allowed for new attributes can be too small if existing header
+information is large. That can happen, for example, if there are very
+many CPUs, due to having an event ID per CPU per event being stored in the
+header information.
+
+Fix by adding the existing header.data_offset. Also increase the extra
+space allowed to 8KiB and align to a 4KiB boundary for neatness.
+
+Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
+Cc: Jiri Olsa <jolsa@redhat.com>
+Link: http://lore.kernel.org/lkml/20211125071457.2066863-1-adrian.hunter@intel.com
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+[Adrian: Backport to v5.15]
+Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/perf/builtin-inject.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/builtin-inject.c
++++ b/tools/perf/builtin-inject.c
+@@ -819,7 +819,7 @@ static int __cmd_inject(struct perf_inje
+ inject->tool.ordered_events = true;
+ inject->tool.ordering_requires_timestamps = true;
+ /* Allow space in the header for new attributes */
+- output_data_offset = 4096;
++ output_data_offset = roundup(8192 + session->header.data_offset, 4096);
+ if (inject->strip)
+ strip_init(inject);
+ }