Commit b6c2b637 authored by Chandan Babu R's avatar Chandan Babu R
Browse files

Merge tag 'fix-efi-recovery-6.6_2023-09-12' of...

Merge tag 'fix-efi-recovery-6.6_2023-09-12' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux

 into xfs-6.6-fixesA

xfs: fix EFI recovery livelocks

This series fixes a customer-reported transaction reservation bug
introduced ten years ago that could result in livelocks during log
recovery.  Log intent item recovery single-steps each step of a deferred
op chain, which means that each step only needs to allocate one
transaction's worth of space in the log, not an entire chain all at
once.  This single-stepping is critical to unpinning the log tail since
there's nobody else to do it for us.

Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>

* tag 'fix-efi-recovery-6.6_2023-09-12' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: reserve less log space when recovering log intent items
parents f41d7d70 3c919b09
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -131,4 +131,26 @@ void xlog_check_buf_cancel_table(struct xlog *log);
#define xlog_check_buf_cancel_table(log) do { } while (0)
#endif

/*
 * Transform a regular reservation into one suitable for recovery of a log
 * intent item.
 *
 * Intent recovery only runs a single step of the transaction chain and defers
 * the rest to a separate transaction.  Therefore, we reduce logcount to 1 here
 * to avoid livelocks if the log grant space is nearly exhausted due to the
 * recovered intent pinning the tail.  Keep the same logflags to avoid tripping
 * asserts elsewhere.  Struct copies abound below.
 */
static inline struct xfs_trans_res
xlog_recover_resv(const struct xfs_trans_res *r)
{
	struct xfs_trans_res ret = {
		.tr_logres	= r->tr_logres,
		.tr_logcount	= 1,
		.tr_logflags	= r->tr_logflags,
	};

	return ret;
}

#endif	/* __XFS_LOG_RECOVER_H__ */
+4 −3
Original line number Diff line number Diff line
@@ -547,7 +547,7 @@ xfs_attri_item_recover(
	struct xfs_inode		*ip;
	struct xfs_da_args		*args;
	struct xfs_trans		*tp;
	struct xfs_trans_res		tres;
	struct xfs_trans_res		resv;
	struct xfs_attri_log_format	*attrp;
	struct xfs_attri_log_nameval	*nv = attrip->attri_nameval;
	int				error;
@@ -618,8 +618,9 @@ xfs_attri_item_recover(
		goto out;
	}

	xfs_init_attr_trans(args, &tres, &total);
	error = xfs_trans_alloc(mp, &tres, total, 0, XFS_TRANS_RESERVE, &tp);
	xfs_init_attr_trans(args, &resv, &total);
	resv = xlog_recover_resv(&resv);
	error = xfs_trans_alloc(mp, &resv, total, 0, XFS_TRANS_RESERVE, &tp);
	if (error)
		goto out;

+3 −1
Original line number Diff line number Diff line
@@ -490,6 +490,7 @@ xfs_bui_item_recover(
	struct list_head		*capture_list)
{
	struct xfs_bmap_intent		fake = { };
	struct xfs_trans_res		resv;
	struct xfs_bui_log_item		*buip = BUI_ITEM(lip);
	struct xfs_trans		*tp;
	struct xfs_inode		*ip = NULL;
@@ -515,7 +516,8 @@ xfs_bui_item_recover(
		return error;

	/* Allocate transaction and do the work. */
	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
	resv = xlog_recover_resv(&M_RES(mp)->tr_itruncate);
	error = xfs_trans_alloc(mp, &resv,
			XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK), 0, 0, &tp);
	if (error)
		goto err_rele;
+3 −1
Original line number Diff line number Diff line
@@ -660,6 +660,7 @@ xfs_efi_item_recover(
	struct xfs_log_item		*lip,
	struct list_head		*capture_list)
{
	struct xfs_trans_res		resv;
	struct xfs_efi_log_item		*efip = EFI_ITEM(lip);
	struct xfs_mount		*mp = lip->li_log->l_mp;
	struct xfs_efd_log_item		*efdp;
@@ -683,7 +684,8 @@ xfs_efi_item_recover(
		}
	}

	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
	resv = xlog_recover_resv(&M_RES(mp)->tr_itruncate);
	error = xfs_trans_alloc(mp, &resv, 0, 0, 0, &tp);
	if (error)
		return error;
	efdp = xfs_trans_get_efd(tp, efip, efip->efi_format.efi_nextents);
+4 −2
Original line number Diff line number Diff line
@@ -477,6 +477,7 @@ xfs_cui_item_recover(
	struct xfs_log_item		*lip,
	struct list_head		*capture_list)
{
	struct xfs_trans_res		resv;
	struct xfs_cui_log_item		*cuip = CUI_ITEM(lip);
	struct xfs_cud_log_item		*cudp;
	struct xfs_trans		*tp;
@@ -514,8 +515,9 @@ xfs_cui_item_recover(
	 * doesn't fit.  We need to reserve enough blocks to handle a
	 * full btree split on either end of the refcount range.
	 */
	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
			mp->m_refc_maxlevels * 2, 0, XFS_TRANS_RESERVE, &tp);
	resv = xlog_recover_resv(&M_RES(mp)->tr_itruncate);
	error = xfs_trans_alloc(mp, &resv, mp->m_refc_maxlevels * 2, 0,
			XFS_TRANS_RESERVE, &tp);
	if (error)
		return error;

Loading