* [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker
@ 2026-09-21 7:10 Kefeng Wang
2026-09-21 10:19 ` Carlos Maiolino
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kefeng Wang @ 2026-09-21 7:10 UTC (permalink / raw)
To: Carlos Maiolino, linux-xfs
Cc: Darrick J . Wong, Shakeel Butt, Dave Chinner, Kefeng Wang,
Christoph Hellwig, Brian Foster
xfs_btree_split_worker() calls xfs_trans_set_context() and
xfs_trans_clear_context() on the caller's transaction, overwriting
tp->t_pflags with the worker's NOFS state. When the caller already has
PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io),
the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear
the caller's NOFS protection.
Use memalloc_nofs_save/restore with a local variable instead so
tp->t_pflags is never touched.
Closes: https://sashiko.dev/#/patchset/20260902131653.1338227-1-wangkefeng.wang@huawei.com
Fixes: 756b1c343333 ("xfs: use current->journal_info for detecting transaction recursion")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
v3:
- Using correct unsigned int type for nofs_flags, per Darrick
v2:
- Send bugfix only based on xfs-linux/for-next, suggested by Carlos[1]
https://lore.kernel.org/linux-xfs/aqqGiu9W0G7dquoY@nidhogg.toxiclabs.cc/
v1:
- https://lore.kernel.org/linux-xfs/20260911104227.2028941-1-wangkefeng.wang@huawei.com/
fs/xfs/libxfs/xfs_btree.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
index 60ef7f08b1d3..239741132914 100644
--- a/fs/xfs/libxfs/xfs_btree.c
+++ b/fs/xfs/libxfs/xfs_btree.c
@@ -3010,6 +3010,7 @@ xfs_btree_split_worker(
struct xfs_btree_split_args, work);
unsigned long pflags;
unsigned long new_pflags = 0;
+ unsigned int nofs_flags;
/*
* we are in a transaction context here, but may also be doing work
@@ -3021,12 +3022,17 @@ xfs_btree_split_worker(
new_pflags |= PF_MEMALLOC | PF_KSWAPD;
current_set_flags_nested(&pflags, new_pflags);
- xfs_trans_set_context(args->cur->bc_tp);
+
+ /*
+ * Don't use xfs_trans_set_context() here: it would overwrite the
+ * caller's saved NOFS state in tp->t_pflags. Use a local scope.
+ */
+ nofs_flags = memalloc_nofs_save();
args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
args->key, args->curp, args->stat);
- xfs_trans_clear_context(args->cur->bc_tp);
+ memalloc_nofs_restore(nofs_flags);
current_restore_flags_nested(&pflags, new_pflags);
/*
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker
2026-09-21 7:10 [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker Kefeng Wang
@ 2026-09-21 10:19 ` Carlos Maiolino
2026-09-21 14:22 ` Darrick J. Wong
2026-10-05 18:06 ` Carlos Maiolino
2 siblings, 0 replies; 4+ messages in thread
From: Carlos Maiolino @ 2026-09-21 10:19 UTC (permalink / raw)
To: Kefeng Wang
Cc: linux-xfs, Darrick J . Wong, Shakeel Butt, Dave Chinner,
Christoph Hellwig, Brian Foster
On Mon, Sep 21, 2026 at 03:10:30PM +0800, Kefeng Wang wrote:
> xfs_btree_split_worker() calls xfs_trans_set_context() and
> xfs_trans_clear_context() on the caller's transaction, overwriting
> tp->t_pflags with the worker's NOFS state. When the caller already has
> PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io),
> the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear
> the caller's NOFS protection.
>
> Use memalloc_nofs_save/restore with a local variable instead so
> tp->t_pflags is never touched.
>
> Closes: https://sashiko.dev/#/patchset/20260902131653.1338227-1-wangkefeng.wang@huawei.com
> Fixes: 756b1c343333 ("xfs: use current->journal_info for detecting transaction recursion")
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Brian Foster <bfoster@redhat.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Looks good,
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
> ---
> v3:
> - Using correct unsigned int type for nofs_flags, per Darrick
>
> v2:
> - Send bugfix only based on xfs-linux/for-next, suggested by Carlos[1]
> https://lore.kernel.org/linux-xfs/aqqGiu9W0G7dquoY@nidhogg.toxiclabs.cc/
> v1:
> - https://lore.kernel.org/linux-xfs/20260911104227.2028941-1-wangkefeng.wang@huawei.com/
>
> fs/xfs/libxfs/xfs_btree.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
> index 60ef7f08b1d3..239741132914 100644
> --- a/fs/xfs/libxfs/xfs_btree.c
> +++ b/fs/xfs/libxfs/xfs_btree.c
> @@ -3010,6 +3010,7 @@ xfs_btree_split_worker(
> struct xfs_btree_split_args, work);
> unsigned long pflags;
> unsigned long new_pflags = 0;
> + unsigned int nofs_flags;
>
> /*
> * we are in a transaction context here, but may also be doing work
> @@ -3021,12 +3022,17 @@ xfs_btree_split_worker(
> new_pflags |= PF_MEMALLOC | PF_KSWAPD;
>
> current_set_flags_nested(&pflags, new_pflags);
> - xfs_trans_set_context(args->cur->bc_tp);
> +
> + /*
> + * Don't use xfs_trans_set_context() here: it would overwrite the
> + * caller's saved NOFS state in tp->t_pflags. Use a local scope.
> + */
> + nofs_flags = memalloc_nofs_save();
>
> args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
> args->key, args->curp, args->stat);
>
> - xfs_trans_clear_context(args->cur->bc_tp);
> + memalloc_nofs_restore(nofs_flags);
> current_restore_flags_nested(&pflags, new_pflags);
>
> /*
> --
> 2.55.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker
2026-09-21 7:10 [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker Kefeng Wang
2026-09-21 10:19 ` Carlos Maiolino
@ 2026-09-21 14:22 ` Darrick J. Wong
2026-10-05 18:06 ` Carlos Maiolino
2 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2026-09-21 14:22 UTC (permalink / raw)
To: Kefeng Wang
Cc: Carlos Maiolino, linux-xfs, Shakeel Butt, Dave Chinner,
Christoph Hellwig, Brian Foster
On Mon, Sep 21, 2026 at 03:10:30PM +0800, Kefeng Wang wrote:
> xfs_btree_split_worker() calls xfs_trans_set_context() and
> xfs_trans_clear_context() on the caller's transaction, overwriting
> tp->t_pflags with the worker's NOFS state. When the caller already has
> PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io),
> the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear
> the caller's NOFS protection.
>
> Use memalloc_nofs_save/restore with a local variable instead so
> tp->t_pflags is never touched.
>
> Closes: https://sashiko.dev/#/patchset/20260902131653.1338227-1-wangkefeng.wang@huawei.com
> Fixes: 756b1c343333 ("xfs: use current->journal_info for detecting transaction recursion")
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Brian Foster <bfoster@redhat.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Looks good to me now, thanks for cleaning this up
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> v3:
> - Using correct unsigned int type for nofs_flags, per Darrick
>
> v2:
> - Send bugfix only based on xfs-linux/for-next, suggested by Carlos[1]
> https://lore.kernel.org/linux-xfs/aqqGiu9W0G7dquoY@nidhogg.toxiclabs.cc/
> v1:
> - https://lore.kernel.org/linux-xfs/20260911104227.2028941-1-wangkefeng.wang@huawei.com/
>
> fs/xfs/libxfs/xfs_btree.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
> index 60ef7f08b1d3..239741132914 100644
> --- a/fs/xfs/libxfs/xfs_btree.c
> +++ b/fs/xfs/libxfs/xfs_btree.c
> @@ -3010,6 +3010,7 @@ xfs_btree_split_worker(
> struct xfs_btree_split_args, work);
> unsigned long pflags;
> unsigned long new_pflags = 0;
> + unsigned int nofs_flags;
>
> /*
> * we are in a transaction context here, but may also be doing work
> @@ -3021,12 +3022,17 @@ xfs_btree_split_worker(
> new_pflags |= PF_MEMALLOC | PF_KSWAPD;
>
> current_set_flags_nested(&pflags, new_pflags);
> - xfs_trans_set_context(args->cur->bc_tp);
> +
> + /*
> + * Don't use xfs_trans_set_context() here: it would overwrite the
> + * caller's saved NOFS state in tp->t_pflags. Use a local scope.
> + */
> + nofs_flags = memalloc_nofs_save();
>
> args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
> args->key, args->curp, args->stat);
>
> - xfs_trans_clear_context(args->cur->bc_tp);
> + memalloc_nofs_restore(nofs_flags);
> current_restore_flags_nested(&pflags, new_pflags);
>
> /*
> --
> 2.55.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker
2026-09-21 7:10 [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker Kefeng Wang
2026-09-21 10:19 ` Carlos Maiolino
2026-09-21 14:22 ` Darrick J. Wong
@ 2026-10-05 18:06 ` Carlos Maiolino
2 siblings, 0 replies; 4+ messages in thread
From: Carlos Maiolino @ 2026-10-05 18:06 UTC (permalink / raw)
To: linux-xfs, Kefeng Wang
Cc: Darrick J . Wong, Shakeel Butt, Dave Chinner, Christoph Hellwig,
Brian Foster
On Mon, 21 Sep 2026 15:10:30 +0800, Kefeng Wang wrote:
> xfs_btree_split_worker() calls xfs_trans_set_context() and
> xfs_trans_clear_context() on the caller's transaction, overwriting
> tp->t_pflags with the worker's NOFS state. When the caller already has
> PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io),
> the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear
> the caller's NOFS protection.
>
> [...]
Applied to for-next, thanks!
[1/1] xfs: fix NOFS state corruption in btree split worker
commit: 23f91a51425ed3d4a5c42978fc25f1087611e4ba
Best regards,
--
Carlos Maiolino <cem@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-05 18:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-21 7:10 [PATCH for-next v3] xfs: fix NOFS state corruption in btree split worker Kefeng Wang
2026-09-21 10:19 ` Carlos Maiolino
2026-09-21 14:22 ` Darrick J. Wong
2026-10-05 18:06 ` Carlos Maiolino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox