xfs: restore nofs context unconditionally in xfs_trans_roll
PATCH v3 1/1 xfs: restore nofs context unconditionally in xfs_trans_roll
When __xfs_trans_commit() fails in xfs_trans_roll(), the NOFS context is cleared but only restored in the success path. This leaves the error path without nofs protection, causing a circular lock dependency between xfs_nondir_ilock_class and fs_reclaim:
CPU0 CPU1
---- ----
lock(&xfs_nondir_ilock_class);
lock(fs_reclaim);
lock(&xfs_nondir_ilock_class); lock(fs_reclaim);
Fix this by moving xfs_trans_set_context() before the error check so that nofs context is always restored on the new transaction.
---
v3:
- Change back to v1
v2:
- Instead of moving xfs_trans_set_context() before the error check, transfer the nofs context in xfs_trans_dup() via a new memalloc_flags_move() helper, as suggested by Darrick.
- Change t_pflags from unsigned long to unsigned int to match mm API.
v1: https://lore.kernel.org/all/[email protected]/T/
fs/xfs/xfs_trans.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
fs/xfs/xfs_trans.c +9 -7
@@ -1029,6 +1029,15 @@ xfs_trans_roll(* duplicate transaction that gets returned. */ error =__xfs_trans_commit (tp, true); + + tp = *tpp; +/* +* __xfs_trans_commit cleared the NOFS flag by calling into +* xfs_trans_free. Set it again here before doing memory +* allocations. +*/ +xfs_trans_set_context (tp); +if (error)return error;
@@ -1040,13 +1049,6 @@ xfs_trans_roll(* either nothing be locked across this call, or that anything that is * locked be logged in the prior and the next transactions. */ - tp = *tpp; -/* -* __xfs_trans_commit cleared the NOFS flag by calling into -* xfs_trans_free. Set it again here before doing memory -* allocations. -*/ -xfs_trans_set_context (tp); error =xfs_log_regrant (tp->t_mountp, tp->t_ticket);if (error)return error;
Signature · 1 line
2.43.0
Looks good:
Quoted 15 lines · Yun Zhou
When
__xfs_trans_commit()fails inxfs_trans_roll(), the NOFS context is cleared but only restored in the success path. This leaves the error path without nofs protection, causing a circular lock dependency betweenxfs_nondir_ilock_classandfs_reclaim:CPU0 CPU1 ---- ---- lock(&xfs_nondir_ilock_class); lock(fs_reclaim); lock(&xfs_nondir_ilock_class);
lock(fs_reclaim);Fix this by moving
xfs_trans_set_context()before the error check so that nofs context is always restored on the new transaction.
Quoted 6 lines
Reported-by [email protected]Fixes a1ca658d649a ("xfs: fix incorrect context handling in xfs_trans_roll")Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Yun Zhou <[email protected]>
Looks good to me,
--D
Quoted 53 lines
---
v3:
- Change back to v1v2:
- Instead of movingxfs_trans_set_context()before the error check, transfer the nofs context inxfs_trans_dup()via a newmemalloc_flags_move()helper, as suggested by Darrick.
- Changet_pflagsfrom unsigned long to unsigned int to match mm API.v1: https://lore.kernel.org/all/[email protected]/T/
fs/xfs/xfs_trans.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)fs/xfs/xfs_trans.c +9
-7@@ -1029,6 +1029,15 @@ xfs_trans_roll(* duplicate transaction that gets returned. */ error =__xfs_trans_commit (tp, true); + + tp = *tpp; +/* +* __xfs_trans_commit cleared the NOFS flag by calling into +* xfs_trans_free. Set it again here before doing memory +* allocations. +*/ +xfs_trans_set_context (tp); +if (error)return error;@@ -1040,13 +1049,6 @@ xfs_trans_roll(* either nothing be locked across this call, or that anything that is * locked be logged in the prior and the next transactions. */ - tp = *tpp; -/* -* __xfs_trans_commit cleared the NOFS flag by calling into -* xfs_trans_free. Set it again here before doing memory -* allocations. -*/ -xfs_trans_set_context (tp); error =xfs_log_regrant (tp->t_mountp, tp->t_ticket);if (error)return error;Signature · 1 line
2.43.0
Quoted 5 lines · Yun Zhou
When
__xfs_trans_commit()fails inxfs_trans_roll(), the NOFS context is cleared but only restored in the success path. This leaves the error path without nofs protection, causing a circular lock dependency betweenxfs_nondir_ilock_classandfs_reclaim:
Quoted 8 lines
CPU0 CPU1 ---- ---- lock(&xfs_nondir_ilock_class); lock(fs_reclaim); lock(&xfs_nondir_ilock_class);
lock(fs_reclaim);[...]
Applied to for-next, thanks!
[1/1] xfs: restore nofs context unconditionally in xfs_trans_roll
commit: 0241ea5fb0fe86d2a673163b2f5815111aadc7f7
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>