--- /dev/null
+From ef740a1e2939376ea4cc11cc8b923214dc1f4a41 Mon Sep 17 00:00:00 2001
+From: Kent Overstreet <kent.overstreet@linux.dev>
+Date: Mon, 15 Jan 2024 15:06:43 -0500
+Subject: bcachefs: Add missing bch2_moving_ctxt_flush_all()
+
+From: Kent Overstreet <kent.overstreet@linux.dev>
+
+commit ef740a1e2939376ea4cc11cc8b923214dc1f4a41 upstream.
+
+This fixes a bug with rebalance IOs getting stuck with reads completed,
+but writes never being issued.
+
+Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ fs/bcachefs/rebalance.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/fs/bcachefs/rebalance.c
++++ b/fs/bcachefs/rebalance.c
+@@ -356,6 +356,7 @@ static int do_rebalance(struct moving_co
+ !kthread_should_stop() &&
+ !atomic64_read(&r->work_stats.sectors_seen) &&
+ !atomic64_read(&r->scan_stats.sectors_seen)) {
++ bch2_moving_ctxt_flush_all(ctxt);
+ bch2_trans_unlock_long(trans);
+ rebalance_wait(c);
+ }
--- /dev/null
+From 0124f42da70c513dc371b73688663c54e5a9666f Mon Sep 17 00:00:00 2001
+From: Kent Overstreet <kent.overstreet@linux.dev>
+Date: Mon, 15 Jan 2024 14:12:43 -0500
+Subject: bcachefs: Don't pass memcmp() as a pointer
+
+From: Kent Overstreet <kent.overstreet@linux.dev>
+
+commit 0124f42da70c513dc371b73688663c54e5a9666f upstream.
+
+Some (buggy!) compilers have issues with this.
+
+Fixes: https://github.com/koverstreet/bcachefs/issues/625
+Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ fs/bcachefs/replicas.c | 10 ++++++++--
+ 1 file changed, 8 insertions(+), 2 deletions(-)
+
+--- a/fs/bcachefs/replicas.c
++++ b/fs/bcachefs/replicas.c
+@@ -9,6 +9,12 @@
+ static int bch2_cpu_replicas_to_sb_replicas(struct bch_fs *,
+ struct bch_replicas_cpu *);
+
++/* Some (buggy!) compilers don't allow memcmp to be passed as a pointer */
++static int bch2_memcmp(const void *l, const void *r, size_t size)
++{
++ return memcmp(l, r, size);
++}
++
+ /* Replicas tracking - in memory: */
+
+ static void verify_replicas_entry(struct bch_replicas_entry *e)
+@@ -33,7 +39,7 @@ void bch2_replicas_entry_sort(struct bch
+
+ static void bch2_cpu_replicas_sort(struct bch_replicas_cpu *r)
+ {
+- eytzinger0_sort(r->entries, r->nr, r->entry_size, memcmp, NULL);
++ eytzinger0_sort(r->entries, r->nr, r->entry_size, bch2_memcmp, NULL);
+ }
+
+ static void bch2_replicas_entry_v0_to_text(struct printbuf *out,
+@@ -833,7 +839,7 @@ static int bch2_cpu_replicas_validate(st
+ sort_cmp_size(cpu_r->entries,
+ cpu_r->nr,
+ cpu_r->entry_size,
+- memcmp, NULL);
++ bch2_memcmp, NULL);
+
+ for (i = 0; i < cpu_r->nr; i++) {
+ struct bch_replicas_entry *e =
--- /dev/null
+From 0c069781ddfa4e31c169a8eced1ee90b8929d522 Mon Sep 17 00:00:00 2001
+From: Daniel Hill <daniel@gluo.nz>
+Date: Sun, 26 Nov 2023 19:33:31 +1300
+Subject: bcachefs: rebalance should wakeup on shutdown if disabled
+
+From: Daniel Hill <daniel@gluo.nz>
+
+commit 0c069781ddfa4e31c169a8eced1ee90b8929d522 upstream.
+
+Signed-off-by: Daniel Hill <daniel@gluo.nz>
+Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ fs/bcachefs/move.c | 2 +-
+ fs/bcachefs/move.h | 1 +
+ fs/bcachefs/rebalance.c | 12 ++++++++++--
+ 3 files changed, 12 insertions(+), 3 deletions(-)
+
+--- a/fs/bcachefs/move.c
++++ b/fs/bcachefs/move.c
+@@ -152,7 +152,7 @@ void bch2_move_ctxt_wait_for_io(struct m
+ atomic_read(&ctxt->write_sectors) != sectors_pending);
+ }
+
+-static void bch2_moving_ctxt_flush_all(struct moving_context *ctxt)
++void bch2_moving_ctxt_flush_all(struct moving_context *ctxt)
+ {
+ move_ctxt_wait_event(ctxt, list_empty(&ctxt->reads));
+ bch2_trans_unlock_long(ctxt->trans);
+--- a/fs/bcachefs/move.h
++++ b/fs/bcachefs/move.h
+@@ -81,6 +81,7 @@ void bch2_moving_ctxt_init(struct moving
+ struct write_point_specifier, bool);
+ struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *);
+ void bch2_moving_ctxt_do_pending_writes(struct moving_context *);
++void bch2_moving_ctxt_flush_all(struct moving_context *);
+ void bch2_move_ctxt_wait_for_io(struct moving_context *);
+ int bch2_move_ratelimit(struct moving_context *);
+
+--- a/fs/bcachefs/rebalance.c
++++ b/fs/bcachefs/rebalance.c
+@@ -317,8 +317,16 @@ static int do_rebalance(struct moving_co
+ BTREE_ID_rebalance_work, POS_MIN,
+ BTREE_ITER_ALL_SNAPSHOTS);
+
+- while (!bch2_move_ratelimit(ctxt) &&
+- !kthread_wait_freezable(r->enabled)) {
++ while (!bch2_move_ratelimit(ctxt)) {
++ if (!r->enabled) {
++ bch2_moving_ctxt_flush_all(ctxt);
++ kthread_wait_freezable(r->enabled ||
++ kthread_should_stop());
++ }
++
++ if (kthread_should_stop())
++ break;
++
+ bch2_trans_begin(trans);
+
+ ret = bkey_err(k = next_rebalance_entry(trans, &rebalance_work_iter));
--- /dev/null
+From bbe6a7c899e7f265c5a6d01a178336a405e98ed6 Mon Sep 17 00:00:00 2001
+From: Al Viro <viro@zeniv.linux.org.uk>
+Date: Tue, 14 Nov 2023 18:52:42 -0500
+Subject: bch2_ioctl_subvolume_destroy(): fix locking
+
+From: Al Viro <viro@zeniv.linux.org.uk>
+
+commit bbe6a7c899e7f265c5a6d01a178336a405e98ed6 upstream.
+
+make it use user_path_locked_at() to get the normal directory protection
+for modifications, as well as stable ->d_parent and ->d_name in victim
+
+Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ fs/bcachefs/fs-ioctl.c | 31 +++++++++++++++++--------------
+ 1 file changed, 17 insertions(+), 14 deletions(-)
+
+--- a/fs/bcachefs/fs-ioctl.c
++++ b/fs/bcachefs/fs-ioctl.c
+@@ -451,33 +451,36 @@ static long bch2_ioctl_subvolume_create(
+ static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
+ struct bch_ioctl_subvolume arg)
+ {
++ const char __user *name = (void __user *)(unsigned long)arg.dst_ptr;
+ struct path path;
+ struct inode *dir;
++ struct dentry *victim;
+ int ret = 0;
+
+ if (arg.flags)
+ return -EINVAL;
+
+- ret = user_path_at(arg.dirfd,
+- (const char __user *)(unsigned long)arg.dst_ptr,
+- LOOKUP_FOLLOW, &path);
+- if (ret)
+- return ret;
++ victim = user_path_locked_at(arg.dirfd, name, &path);
++ if (IS_ERR(victim))
++ return PTR_ERR(victim);
+
+- if (path.dentry->d_sb->s_fs_info != c) {
++ if (victim->d_sb->s_fs_info != c) {
+ ret = -EXDEV;
+ goto err;
+ }
+-
+- dir = path.dentry->d_parent->d_inode;
+-
+- ret = __bch2_unlink(dir, path.dentry, true);
+- if (ret)
++ if (!d_is_positive(victim)) {
++ ret = -ENOENT;
+ goto err;
+-
+- fsnotify_rmdir(dir, path.dentry);
+- d_delete(path.dentry);
++ }
++ dir = d_inode(path.dentry);
++ ret = __bch2_unlink(dir, victim, true);
++ if (!ret) {
++ fsnotify_rmdir(dir, victim);
++ d_delete(victim);
++ }
++ inode_unlock(dir);
+ err:
++ dput(victim);
+ path_put(&path);
+ return ret;
+ }
--- /dev/null
+From 74d016ecc1a7974664e98d1afbf649cd4e0e0423 Mon Sep 17 00:00:00 2001
+From: Al Viro <viro@zeniv.linux.org.uk>
+Date: Wed, 15 Nov 2023 22:41:27 -0500
+Subject: new helper: user_path_locked_at()
+
+From: Al Viro <viro@zeniv.linux.org.uk>
+
+commit 74d016ecc1a7974664e98d1afbf649cd4e0e0423 upstream.
+
+Equivalent of kern_path_locked() taking dfd/userland name.
+User introduced in the next commit.
+
+Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ fs/namei.c | 16 +++++++++++++---
+ include/linux/namei.h | 1 +
+ 2 files changed, 14 insertions(+), 3 deletions(-)
+
+--- a/fs/namei.c
++++ b/fs/namei.c
+@@ -2573,13 +2573,13 @@ static int filename_parentat(int dfd, st
+ }
+
+ /* does lookup, returns the object with parent locked */
+-static struct dentry *__kern_path_locked(struct filename *name, struct path *path)
++static struct dentry *__kern_path_locked(int dfd, struct filename *name, struct path *path)
+ {
+ struct dentry *d;
+ struct qstr last;
+ int type, error;
+
+- error = filename_parentat(AT_FDCWD, name, 0, path, &last, &type);
++ error = filename_parentat(dfd, name, 0, path, &last, &type);
+ if (error)
+ return ERR_PTR(error);
+ if (unlikely(type != LAST_NORM)) {
+@@ -2598,12 +2598,22 @@ static struct dentry *__kern_path_locked
+ struct dentry *kern_path_locked(const char *name, struct path *path)
+ {
+ struct filename *filename = getname_kernel(name);
+- struct dentry *res = __kern_path_locked(filename, path);
++ struct dentry *res = __kern_path_locked(AT_FDCWD, filename, path);
+
+ putname(filename);
+ return res;
+ }
+
++struct dentry *user_path_locked_at(int dfd, const char __user *name, struct path *path)
++{
++ struct filename *filename = getname(name);
++ struct dentry *res = __kern_path_locked(dfd, filename, path);
++
++ putname(filename);
++ return res;
++}
++EXPORT_SYMBOL(user_path_locked_at);
++
+ int kern_path(const char *name, unsigned int flags, struct path *path)
+ {
+ struct filename *filename = getname_kernel(name);
+--- a/include/linux/namei.h
++++ b/include/linux/namei.h
+@@ -66,6 +66,7 @@ extern struct dentry *kern_path_create(i
+ extern struct dentry *user_path_create(int, const char __user *, struct path *, unsigned int);
+ extern void done_path_create(struct path *, struct dentry *);
+ extern struct dentry *kern_path_locked(const char *, struct path *);
++extern struct dentry *user_path_locked_at(int , const char __user *, struct path *);
+ int vfs_path_parent_lookup(struct filename *filename, unsigned int flags,
+ struct path *parent, struct qstr *last, int *type,
+ const struct path *root);
io_uring-net-un-indent-mshot-retry-path-in-io_recv_finish.patch
io_uring-rw-ensure-poll-based-multishot-read-retries-appropriately.patch
pci-aspm-fix-deadlock-when-enabling-aspm.patch
+new-helper-user_path_locked_at.patch
+bch2_ioctl_subvolume_destroy-fix-locking.patch
+bcachefs-don-t-pass-memcmp-as-a-pointer.patch
+bcachefs-rebalance-should-wakeup-on-shutdown-if-disabled.patch
+bcachefs-add-missing-bch2_moving_ctxt_flush_all.patch