Skip to contentSkip to conversation

remove LI_FAILED buffer pinning

PATCH In review Christoph Hellwig 2 participants 8 messages Mar 20, 2025 – Apr 16, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Hi all,

this series is based on a report from Dan about sleeping while atomic and removes the now uneeded pinning of LI_FAILED buffers to fix that.

Diffstat:

 xfs_buf.c        |    1 +
 xfs_dquot.c      |    3 +--
 xfs_inode_item.c |    6 ------
 xfs_trans_ail.c  |    5 ++---
 xfs_trans_priv.h |   28 ----------------------------
 5 files changed, 4 insertions(+), 39 deletions(-)
#1 lore raw

PATCH 1/2 xfs: remove the leftover xfs_{set,clear}_li_failed infrastructure

Marking a log item as failed kept a buffer reference around for resubmission of inode and dquote items.

For inode items commit 298f7bec503f3 ("xfs: pin inode backing buffer to the inode log item") started pinning the inode item buffers unconditionally and removed the need for this. Later commit acc8f8628c37 ("xfs: attach dquot buffer to dquot log item buffer") did the same for dquot items but didn't fully clean up the xfs_clear_li_failed side for them. Stop adding the extra pin for dquot items and remove the helpers.

This happens to fix a call to xfs_buf_free with the AIL lock held, which would be incorrect for the unlikely case freeing the buffer ends up calling vfree.

---
 fs/xfs/xfs_dquot.c      |  3 +--
 fs/xfs/xfs_inode_item.c |  6 ------
 fs/xfs/xfs_trans_ail.c  |  5 ++---
 fs/xfs/xfs_trans_priv.h | 28 ----------------------------
 4 files changed, 3 insertions(+), 39 deletions(-)
fs/xfs/xfs_dquot.c +1 -2
index edbc521870a1..b4e32f0860b7 100644
@@ -1186,9 +1186,8 @@ xfs_qm_dqflush_done(
 	if (test_bit(XFS_LI_IN_AIL, &lip->li_flags) &&
 	    (lip->li_lsn == qlip->qli_flush_lsn ||
 	     test_bit(XFS_LI_FAILED, &lip->li_flags))) {
-
 		spin_lock(&ailp->ail_lock);
-		xfs_clear_li_failed(lip);
+		clear_bit(XFS_LI_FAILED, &lip->li_flags);
 		if (lip->li_lsn == qlip->qli_flush_lsn) {
 			/* xfs_ail_update_finish() drops the AIL lock */
 			tail_lsn = xfs_ail_delete_one(ailp, lip);
fs/xfs/xfs_inode_item.c +0 -6
index 40fc1bf900af..c6cb0b6b9e46 100644
@@ -1089,13 +1089,7 @@ xfs_iflush_abort(
 	 * state. Whilst the inode is in the AIL, it should have a valid buffer
 	 * pointer for push operations to access - it is only safe to remove the
 	 * inode from the buffer once it has been removed from the AIL.
-	 *
-	 * We also clear the failed bit before removing the item from the AIL
-	 * as xfs_trans_ail_delete()->xfs_clear_li_failed() will release buffer
-	 * references the inode item owns and needs to hold until we've fully
-	 * aborted the inode log item and detached it from the buffer.
 	 */
-	clear_bit(XFS_LI_FAILED, &iip->ili_item.li_flags);
 	xfs_trans_ail_delete(&iip->ili_item, 0);
 
 	/*
fs/xfs/xfs_trans_ail.c +2 -3
index 0fcb1828e598..85a649fec6ac 100644
@@ -909,10 +909,9 @@ xfs_trans_ail_delete(
 		return;
 	}
 
-	/* xfs_ail_update_finish() drops the AIL lock */
-	xfs_clear_li_failed(lip);
+	clear_bit(XFS_LI_FAILED, &lip->li_flags);
 	tail_lsn = xfs_ail_delete_one(ailp, lip);
-	xfs_ail_update_finish(ailp, tail_lsn);
+	xfs_ail_update_finish(ailp, tail_lsn);	/* drops the AIL lock */
 }
 
 int
fs/xfs/xfs_trans_priv.h +0 -28
index bd841df93021..f945f0450b16 100644
@@ -167,32 +167,4 @@ xfs_trans_ail_copy_lsn(
 }
 #endif
 
-static inline void
-xfs_clear_li_failed(
-	struct xfs_log_item	*lip)
-{
-	struct xfs_buf	*bp = lip->li_buf;
-
-	ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags));
-	lockdep_assert_held(&lip->li_ailp->ail_lock);
-
-	if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) {
-		lip->li_buf = NULL;
-		xfs_buf_rele(bp);
-	}
-}
-
-static inline void
-xfs_set_li_failed(
-	struct xfs_log_item	*lip,
-	struct xfs_buf		*bp)
-{
-	lockdep_assert_held(&lip->li_ailp->ail_lock);
-
-	if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) {
-		xfs_buf_hold(bp);
-		lip->li_buf = bp;
-	}
-}
-
 #endif	/* __XFS_TRANS_PRIV_H__ */
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs: remove the leftover xfs_{set,clear}_li_failed infrastructure

Quoted 11 lines · Christoph Hellwig

Marking a log item as failed kept a buffer reference around for resubmission of inode and dquote items.

For inode items commit 298f7bec503f3 ("xfs: pin inode backing buffer to the inode log item") started pinning the inode item buffers unconditionally and removed the need for this. Later commit acc8f8628c37 ("xfs: attach dquot buffer to dquot log item buffer") did the same for dquot items but didn't fully clean up the xfs_clear_li_failed side for them. Stop adding the extra pin for dquot items and remove the helpers.

Quoted 6 lines

This happens to fix a call to xfs_buf_free with the AIL lock held, which would be incorrect for the unlikely case freeing the buffer ends up calling vfree.

Quoted 97 lines
---
 fs/xfs/xfs_dquot.c      |  3 +--
 fs/xfs/xfs_inode_item.c |  6 ------
 fs/xfs/xfs_trans_ail.c  |  5 ++---
 fs/xfs/xfs_trans_priv.h | 28 ----------------------------
 4 files changed, 3 insertions(+), 39 deletions(-)
fs/xfs/xfs_dquot.c +1 -2
index edbc521870a1..b4e32f0860b7 100644
@@ -1186,9 +1186,8 @@ xfs_qm_dqflush_done(
 	if (test_bit(XFS_LI_IN_AIL, &lip->li_flags) &&
 	    (lip->li_lsn == qlip->qli_flush_lsn ||
 	     test_bit(XFS_LI_FAILED, &lip->li_flags))) {
-
 		spin_lock(&ailp->ail_lock);
-		xfs_clear_li_failed(lip);
+		clear_bit(XFS_LI_FAILED, &lip->li_flags);
 		if (lip->li_lsn == qlip->qli_flush_lsn) {
 			/* xfs_ail_update_finish() drops the AIL lock */
 			tail_lsn = xfs_ail_delete_one(ailp, lip);
fs/xfs/xfs_inode_item.c +0 -6
index 40fc1bf900af..c6cb0b6b9e46 100644
@@ -1089,13 +1089,7 @@ xfs_iflush_abort(
 	 * state. Whilst the inode is in the AIL, it should have a valid buffer
 	 * pointer for push operations to access - it is only safe to remove the
 	 * inode from the buffer once it has been removed from the AIL.
-	 *
-	 * We also clear the failed bit before removing the item from the AIL
-	 * as xfs_trans_ail_delete()->xfs_clear_li_failed() will release buffer
-	 * references the inode item owns and needs to hold until we've fully
-	 * aborted the inode log item and detached it from the buffer.
 	 */
-	clear_bit(XFS_LI_FAILED, &iip->ili_item.li_flags);
 	xfs_trans_ail_delete(&iip->ili_item, 0);
 
 	/*
fs/xfs/xfs_trans_ail.c +2 -3
index 0fcb1828e598..85a649fec6ac 100644
@@ -909,10 +909,9 @@ xfs_trans_ail_delete(
 		return;
 	}
 
-	/* xfs_ail_update_finish() drops the AIL lock */
-	xfs_clear_li_failed(lip);
+	clear_bit(XFS_LI_FAILED, &lip->li_flags);
 	tail_lsn = xfs_ail_delete_one(ailp, lip);
-	xfs_ail_update_finish(ailp, tail_lsn);
+	xfs_ail_update_finish(ailp, tail_lsn);	/* drops the AIL lock */
 }
 
 int
fs/xfs/xfs_trans_priv.h +0 -29
index bd841df93021..f945f0450b16 100644
@@ -167,32 +167,4 @@ xfs_trans_ail_copy_lsn(
 }
 #endif
 
-static inline void
-xfs_clear_li_failed(
-	struct xfs_log_item	*lip)
-{
-	struct xfs_buf	*bp = lip->li_buf;
-
-	ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags));
-	lockdep_assert_held(&lip->li_ailp->ail_lock);
-
-	if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) {
-		lip->li_buf = NULL;
-		xfs_buf_rele(bp);
-	}
-}
-
-static inline void
-xfs_set_li_failed(
-	struct xfs_log_item	*lip,
-	struct xfs_buf		*bp)
-{
-	lockdep_assert_held(&lip->li_ailp->ail_lock);
-
-	if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) {
-		xfs_buf_hold(bp);
-		lip->li_buf = bp;
-	}
-}
-
 #endif	/* __XFS_TRANS_PRIV_H__ */
--

2.45.2

#3 lore raw

PATCH 2/2 xfs: mark xfs_buf_free as might_sleep()

In reply to Christoph Hellwig

xfs_buf_free can call vunmap, which can sleep. The vunmap path is an unlikely one, so add might_sleep to ensure calling xfs_buf_free from atomic context gets caught more easily.

---
 fs/xfs/xfs_buf.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_buf.c +1 -0
index 8e7f1b324b3b..1a2b3f06fa71 100644
@@ -105,6 +105,7 @@ xfs_buf_free(
 {
 	unsigned int		size = BBTOB(bp->b_length);
 
+	might_sleep();
 	trace_xfs_buf_free(bp, _RET_IP_);
 
 	ASSERT(list_empty(&bp->b_lru));
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] xfs: mark xfs_buf_free as might_sleep()

Quoted 15 lines · Christoph Hellwig

xfs_buf_free can call vunmap, which can sleep. The vunmap path is an unlikely one, so add might_sleep to ensure calling xfs_buf_free from atomic context gets caught more easily.

---
 fs/xfs/xfs_buf.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_buf.c +0 -0
index 8e7f1b324b3b..1a2b3f06fa71 100644

fs/xfs/xfs_buf.c xfs_buf_free( · line 111

Quoted 7 lines
fs/xfs/xfs_buf.c +1 -0
@@ -105,6 +105,7 @@ xfs_buf_free(
 {
 	unsigned int		size = BBTOB(bp->b_length);
 
+	might_sleep();
 	trace_xfs_buf_free(bp, _RET_IP_);
 
 	ASSERT(list_empty(&bp->b_lru));

If I followed it correct, vunmap can be caught via xfs_buf_free_pages(). If that's the case, wouldn't make more sense to put might_sleep() inside xfs_buf_free_pages() giving it is not called only from xfs_buf_free()?

Otherwise,

Quoted 3 lines

--
2.45.2

#5 lore raw

Re: [PATCH 2/2] xfs: mark xfs_buf_free as might_sleep()

Quoted 4 lines · Carlos Maiolino

If I followed it correct, vunmap can be caught via xfs_buf_free_pages(). If that's the case, wouldn't make more sense to put might_sleep() inside xfs_buf_free_pages() giving it is not called only from xfs_buf_free()?

xfs_buf_free_pages has been folded into xfs_buf_free in for-next.

maintainer
#6 lore raw

Re: [PATCH 2/2] xfs: mark xfs_buf_free as might_sleep()

Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Carlos Maiolino

If I followed it correct, vunmap can be caught via xfs_buf_free_pages(). If that's the case, wouldn't make more sense to put might_sleep() inside xfs_buf_free_pages() giving it is not called only from xfs_buf_free()?

xfs_buf_free_pages has been folded into xfs_buf_free in for-next.

Woops, looked at the wrong code base... Thanks for the heads up.

maintainer Applied
#7 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

this series is based on a report from Dan about sleeping while atomic and removes the now uneeded pinning of LI_FAILED buffers to fix that.

Diffstat:

Quoted 8 lines
 xfs_buf.c        |    1 +
 xfs_dquot.c      |    3 +--
 xfs_inode_item.c |    6 ------
 xfs_trans_ail.c  |    5 ++---
 xfs_trans_priv.h |   28 ----------------------------
 5 files changed, 4 insertions(+), 39 deletions(-)

[...]

Applied to for-next, thanks!

[1/2] xfs: remove the leftover xfs_{set,clear}_li_failed infrastructure

      commit: b73e05281cd9e37b5525641ca6f4544867372533
[2/2] xfs: mark xfs_buf_free as might_sleep()
      commit: a1a56f541a8f634007de4bcb45aa3eaf803154a8

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>