All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Dave Chinner <david@fromorbit.com>,
	Dave Chinner <dchinner@redhat.com>,
	Christoph Hellwig <hch@lst.de>,
	"Darrick J . Wong" <darrick.wong@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-xfs@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 44/50] xfs: gut error handling in xfs_trans_unreserve_and_mod_sb()
Date: Mon,  8 Jun 2020 19:26:34 -0400	[thread overview]
Message-ID: <20200608232640.3370262-44-sashal@kernel.org> (raw)
In-Reply-To: <20200608232640.3370262-1-sashal@kernel.org>

From: Dave Chinner <david@fromorbit.com>

[ Upstream commit dc3ffbb14060c943469d5e12900db3a60bc3fa64 ]

xfs: gut error handling in xfs_trans_unreserve_and_mod_sb()

From: Dave Chinner <dchinner@redhat.com>

The error handling in xfs_trans_unreserve_and_mod_sb() is largely
incorrect - rolling back the changes in the transaction if only one
counter underruns makes all the other counters incorrect. We still
allow the change to proceed and committing the transaction, except
now we have multiple incorrect counters instead of a single
underflow.

Further, we don't actually report the error to the caller, so this
is completely silent except on debug kernels that will assert on
failure before we even get to the rollback code.  Hence this error
handling is broken, untested, and largely unnecessary complexity.

Just remove it.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/xfs/xfs_trans.c | 163 ++++++---------------------------------------
 1 file changed, 20 insertions(+), 143 deletions(-)

diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index a280e126491f..fb208944d77b 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -493,57 +493,9 @@ xfs_trans_apply_sb_deltas(
 				  sizeof(sbp->sb_frextents) - 1);
 }
 
-STATIC int
-xfs_sb_mod8(
-	uint8_t			*field,
-	int8_t			delta)
-{
-	int8_t			counter = *field;
-
-	counter += delta;
-	if (counter < 0) {
-		ASSERT(0);
-		return -EINVAL;
-	}
-	*field = counter;
-	return 0;
-}
-
-STATIC int
-xfs_sb_mod32(
-	uint32_t		*field,
-	int32_t			delta)
-{
-	int32_t			counter = *field;
-
-	counter += delta;
-	if (counter < 0) {
-		ASSERT(0);
-		return -EINVAL;
-	}
-	*field = counter;
-	return 0;
-}
-
-STATIC int
-xfs_sb_mod64(
-	uint64_t		*field,
-	int64_t			delta)
-{
-	int64_t			counter = *field;
-
-	counter += delta;
-	if (counter < 0) {
-		ASSERT(0);
-		return -EINVAL;
-	}
-	*field = counter;
-	return 0;
-}
-
 /*
- * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations
- * and apply superblock counter changes to the in-core superblock.  The
+ * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations and
+ * apply superblock counter changes to the in-core superblock.  The
  * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT
  * applied to the in-core superblock.  The idea is that that has already been
  * done.
@@ -588,20 +540,17 @@ xfs_trans_unreserve_and_mod_sb(
 	/* apply the per-cpu counters */
 	if (blkdelta) {
 		error = xfs_mod_fdblocks(mp, blkdelta, rsvd);
-		if (error)
-			goto out;
+		ASSERT(!error);
 	}
 
 	if (idelta) {
 		error = xfs_mod_icount(mp, idelta);
-		if (error)
-			goto out_undo_fdblocks;
+		ASSERT(!error);
 	}
 
 	if (ifreedelta) {
 		error = xfs_mod_ifree(mp, ifreedelta);
-		if (error)
-			goto out_undo_icount;
+		ASSERT(!error);
 	}
 
 	if (rtxdelta == 0 && !(tp->t_flags & XFS_TRANS_SB_DIRTY))
@@ -609,95 +558,23 @@ xfs_trans_unreserve_and_mod_sb(
 
 	/* apply remaining deltas */
 	spin_lock(&mp->m_sb_lock);
-	if (rtxdelta) {
-		error = xfs_sb_mod64(&mp->m_sb.sb_frextents, rtxdelta);
-		if (error)
-			goto out_undo_ifree;
-	}
-
-	if (tp->t_dblocks_delta != 0) {
-		error = xfs_sb_mod64(&mp->m_sb.sb_dblocks, tp->t_dblocks_delta);
-		if (error)
-			goto out_undo_frextents;
-	}
-	if (tp->t_agcount_delta != 0) {
-		error = xfs_sb_mod32(&mp->m_sb.sb_agcount, tp->t_agcount_delta);
-		if (error)
-			goto out_undo_dblocks;
-	}
-	if (tp->t_imaxpct_delta != 0) {
-		error = xfs_sb_mod8(&mp->m_sb.sb_imax_pct, tp->t_imaxpct_delta);
-		if (error)
-			goto out_undo_agcount;
-	}
-	if (tp->t_rextsize_delta != 0) {
-		error = xfs_sb_mod32(&mp->m_sb.sb_rextsize,
-				     tp->t_rextsize_delta);
-		if (error)
-			goto out_undo_imaxpct;
-	}
-	if (tp->t_rbmblocks_delta != 0) {
-		error = xfs_sb_mod32(&mp->m_sb.sb_rbmblocks,
-				     tp->t_rbmblocks_delta);
-		if (error)
-			goto out_undo_rextsize;
-	}
-	if (tp->t_rblocks_delta != 0) {
-		error = xfs_sb_mod64(&mp->m_sb.sb_rblocks, tp->t_rblocks_delta);
-		if (error)
-			goto out_undo_rbmblocks;
-	}
-	if (tp->t_rextents_delta != 0) {
-		error = xfs_sb_mod64(&mp->m_sb.sb_rextents,
-				     tp->t_rextents_delta);
-		if (error)
-			goto out_undo_rblocks;
-	}
-	if (tp->t_rextslog_delta != 0) {
-		error = xfs_sb_mod8(&mp->m_sb.sb_rextslog,
-				     tp->t_rextslog_delta);
-		if (error)
-			goto out_undo_rextents;
-	}
+	mp->m_sb.sb_frextents += rtxdelta;
+	mp->m_sb.sb_dblocks += tp->t_dblocks_delta;
+	mp->m_sb.sb_agcount += tp->t_agcount_delta;
+	mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta;
+	mp->m_sb.sb_rextsize += tp->t_rextsize_delta;
+	mp->m_sb.sb_rbmblocks += tp->t_rbmblocks_delta;
+	mp->m_sb.sb_rblocks += tp->t_rblocks_delta;
+	mp->m_sb.sb_rextents += tp->t_rextents_delta;
+	mp->m_sb.sb_rextslog += tp->t_rextslog_delta;
 	spin_unlock(&mp->m_sb_lock);
-	return;
 
-out_undo_rextents:
-	if (tp->t_rextents_delta)
-		xfs_sb_mod64(&mp->m_sb.sb_rextents, -tp->t_rextents_delta);
-out_undo_rblocks:
-	if (tp->t_rblocks_delta)
-		xfs_sb_mod64(&mp->m_sb.sb_rblocks, -tp->t_rblocks_delta);
-out_undo_rbmblocks:
-	if (tp->t_rbmblocks_delta)
-		xfs_sb_mod32(&mp->m_sb.sb_rbmblocks, -tp->t_rbmblocks_delta);
-out_undo_rextsize:
-	if (tp->t_rextsize_delta)
-		xfs_sb_mod32(&mp->m_sb.sb_rextsize, -tp->t_rextsize_delta);
-out_undo_imaxpct:
-	if (tp->t_rextsize_delta)
-		xfs_sb_mod8(&mp->m_sb.sb_imax_pct, -tp->t_imaxpct_delta);
-out_undo_agcount:
-	if (tp->t_agcount_delta)
-		xfs_sb_mod32(&mp->m_sb.sb_agcount, -tp->t_agcount_delta);
-out_undo_dblocks:
-	if (tp->t_dblocks_delta)
-		xfs_sb_mod64(&mp->m_sb.sb_dblocks, -tp->t_dblocks_delta);
-out_undo_frextents:
-	if (rtxdelta)
-		xfs_sb_mod64(&mp->m_sb.sb_frextents, -rtxdelta);
-out_undo_ifree:
-	spin_unlock(&mp->m_sb_lock);
-	if (ifreedelta)
-		xfs_mod_ifree(mp, -ifreedelta);
-out_undo_icount:
-	if (idelta)
-		xfs_mod_icount(mp, -idelta);
-out_undo_fdblocks:
-	if (blkdelta)
-		xfs_mod_fdblocks(mp, -blkdelta, rsvd);
-out:
-	ASSERT(error == 0);
+	/*
+	 * Debug checks outside of the spinlock so they don't lock up the
+	 * machine if they fail.
+	 */
+	ASSERT(mp->m_sb.sb_imax_pct >= 0);
+	ASSERT(mp->m_sb.sb_rextslog >= 0);
 	return;
 }
 
-- 
2.25.1


  parent reply	other threads:[~2020-06-08 23:41 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-08 23:25 [PATCH AUTOSEL 4.9 01/50] ath9x: Fix stack-out-of-bounds Write in ath9k_hif_usb_rx_cb Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 02/50] ath9k: Fix use-after-free Write in ath9k_htc_rx_msg Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 03/50] media: si2157: Better check for running tuner in init Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 04/50] objtool: Ignore empty alternatives Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 05/50] net: ena: fix error returning in ena_com_get_hash_function() Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 06/50] spi: dw: Zero DMA Tx and Rx configurations on stack Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 07/50] Bluetooth: Add SCO fallback for invalid LMP parameters error Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 08/50] kgdb: Prevent infinite recursive entries to the debugger Sasha Levin
2020-06-08 23:25 ` [PATCH AUTOSEL 4.9 09/50] spi: dw: Enable interrupts in accordance with DMA xfer mode Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 10/50] clocksource: dw_apb_timer_of: Fix missing clockevent timers Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 11/50] btrfs: do not ignore error from btrfs_next_leaf() when inserting checksums Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 12/50] ARM: 8978/1: mm: make act_mm() respect THREAD_SIZE Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 13/50] x86/kvm/hyper-v: Explicitly align hcall param for kvm_hyperv_exit Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 14/50] net: vmxnet3: fix possible buffer overflow caused by bad DMA value in vmxnet3_get_rss() Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 15/50] staging: android: ion: use vmap instead of vm_map_ram Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 16/50] ath9k: Fix use-after-free Read in ath9k_wmi_ctrl_rx Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 17/50] ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 18/50] e1000: Distribute switch variables for initialization Sasha Levin
2020-06-08 23:26   ` [Intel-wired-lan] " Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 19/50] dt-bindings: display: mediatek: control dpi pins mode to avoid leakage Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 20/50] media: dvb: return -EREMOTEIO on i2c transfer failure Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 21/50] media: platform: fcp: Set appropriate DMA parameters Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 22/50] MIPS: Make sparse_init() using top-down allocation Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 23/50] netfilter: nft_nat: return EOPNOTSUPP if type or flags are not supported Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 24/50] lib/mpi: Fix 64-bit MIPS build with Clang Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 25/50] perf: Add cond_resched() to task_function_call() Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 26/50] exit: Move preemption fixup up, move blocking operations down Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 27/50] net: lpc-enet: fix error return code in lpc_mii_init() Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 28/50] net: allwinner: Fix use correct return type for ndo_start_xmit() Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 29/50] powerpc/spufs: fix copy_to_user while atomic Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 30/50] ath9k_htc: Silence undersized packet warnings Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 31/50] MIPS: Truncate link address into 32bit for 32bit kernel Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 32/50] mips: cm: Fix an invalid error code of INTVN_*_ERR Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 33/50] kgdb: Fix spurious true from in_dbg_master() Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 34/50] md: don't flush workqueue unconditionally in md_open Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 35/50] rtlwifi: Fix a double free in _rtl_usb_tx_urb_setup() Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 36/50] mwifiex: Fix memory corruption in dump_station Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 37/50] x86/boot: Correct relocation destination on old linkers Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 38/50] mips: Add udelay lpj numbers adjustment Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 39/50] x86/mm: Stop printing BRK addresses Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 40/50] m68k: mac: Don't call via_flush_cache() on Mac IIfx Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 41/50] macvlan: Skip loopback packets in RX handler Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 42/50] PCI: Don't disable decoding when mmio_always_on is set Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 43/50] MIPS: Fix IRQ tracing when call handle_fpe() and handle_msa_fpe() Sasha Levin
2020-06-08 23:26 ` Sasha Levin [this message]
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 45/50] staging: greybus: sdio: Respect the cmd->busy_timeout from the mmc core Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 46/50] ixgbe: fix signed-integer-overflow warning Sasha Levin
2020-06-08 23:26   ` [Intel-wired-lan] " Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 47/50] mmc: sdhci-esdhc-imx: fix the mask for tuning start point Sasha Levin
2020-06-08 23:26   ` Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 48/50] spi: dw: Return any value retrieved from the dma_transfer callback Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 49/50] cpuidle: Fix three reference count leaks Sasha Levin
2020-06-08 23:26 ` [PATCH AUTOSEL 4.9 50/50] vxlan: Avoid infinite loop when suppressing NS messages with invalid options Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200608232640.3370262-44-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=dchinner@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.