mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Roland Dreier" <roland@kernel.org>,
	"Eryu Guan" <guaneryu@gmail.com>, "Theodore Ts'o" <tytso@mit.edu>,
	"Jan Kara" <jack@suse.com>
Subject: [PATCH 3.2 106/107] jbd2: avoid infinite loop when destroying aborted journal
Date: Fri, 09 Oct 2015 01:12:28 +0100	[thread overview]
Message-ID: <lsq.1444349548.503556510@decadent.org.uk> (raw)
In-Reply-To: <lsq.1444349547.316291576@decadent.org.uk>

3.2.72-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: Jan Kara <jack@suse.com>

commit 841df7df196237ea63233f0f9eaa41db53afd70f upstream.

Commit 6f6a6fda2945 "jbd2: fix ocfs2 corrupt when updating journal
superblock fails" changed jbd2_cleanup_journal_tail() to return EIO
when the journal is aborted. That makes logic in
jbd2_log_do_checkpoint() bail out which is fine, except that
jbd2_journal_destroy() expects jbd2_log_do_checkpoint() to always make
a progress in cleaning the journal. Without it jbd2_journal_destroy()
just loops in an infinite loop.

Fix jbd2_journal_destroy() to cleanup journal checkpoint lists of
jbd2_log_do_checkpoint() fails with error.

Reported-by: Eryu Guan <guaneryu@gmail.com>
Tested-by: Eryu Guan <guaneryu@gmail.com>
Fixes: 6f6a6fda294506dfe0e3e0a253bb2d2923f28f0a
Signed-off-by: Jan Kara <jack@suse.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: Roland Dreier <roland@kernel.org>
---
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -509,14 +509,15 @@ int jbd2_cleanup_journal_tail(journal_t
  * journal_clean_one_cp_list
  *
  * Find all the written-back checkpoint buffers in the given list and
- * release them.
+ * release them. If 'destroy' is set, clean all buffers unconditionally.
  *
  * Called with the journal locked.
  * Called with j_list_lock held.
  * Returns number of bufers reaped (for debug)
  */
 
-static int journal_clean_one_cp_list(struct journal_head *jh, int *released)
+static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy,
+				     int *released)
 {
 	struct journal_head *last_jh;
 	struct journal_head *next_jh = jh;
@@ -532,7 +533,10 @@ static int journal_clean_one_cp_list(str
 		next_jh = jh->b_cpnext;
 		/* Use trylock because of the ranking */
 		if (jbd_trylock_bh_state(jh2bh(jh))) {
-			ret = __try_to_free_cp_buf(jh);
+			if (!destroy)
+				ret = __try_to_free_cp_buf(jh);
+			else
+				ret = __jbd2_journal_remove_checkpoint(jh) + 1;
 			if (ret) {
 				freed++;
 				if (ret == 2) {
@@ -558,13 +562,14 @@ static int journal_clean_one_cp_list(str
  * journal_clean_checkpoint_list
  *
  * Find all the written-back checkpoint buffers in the journal and release them.
+ * If 'destroy' is set, release all buffers unconditionally.
  *
  * Called with the journal locked.
  * Called with j_list_lock held.
  * Returns number of buffers reaped (for debug)
  */
 
-int __jbd2_journal_clean_checkpoint_list(journal_t *journal)
+int __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
 {
 	transaction_t *transaction, *last_transaction, *next_transaction;
 	int ret = 0;
@@ -580,7 +585,7 @@ int __jbd2_journal_clean_checkpoint_list
 		transaction = next_transaction;
 		next_transaction = transaction->t_cpnext;
 		ret += journal_clean_one_cp_list(transaction->
-				t_checkpoint_list, &released);
+				t_checkpoint_list, destroy, &released);
 		/*
 		 * This function only frees up some memory if possible so we
 		 * dont have an obligation to finish processing. Bail out if
@@ -596,7 +601,7 @@ int __jbd2_journal_clean_checkpoint_list
 		 * we can possibly see not yet submitted buffers on io_list
 		 */
 		ret += journal_clean_one_cp_list(transaction->
-				t_checkpoint_io_list, &released);
+				t_checkpoint_io_list, destroy, &released);
 		if (need_resched())
 			goto out;
 	} while (transaction != last_transaction);
@@ -605,6 +610,28 @@ out:
 }
 
 /*
+ * Remove buffers from all checkpoint lists as journal is aborted and we just
+ * need to free memory
+ */
+void jbd2_journal_destroy_checkpoint(journal_t *journal)
+{
+	/*
+	 * We loop because __jbd2_journal_clean_checkpoint_list() may abort
+	 * early due to a need of rescheduling.
+	 */
+	while (1) {
+		spin_lock(&journal->j_list_lock);
+		if (!journal->j_checkpoint_transactions) {
+			spin_unlock(&journal->j_list_lock);
+			break;
+		}
+		__jbd2_journal_clean_checkpoint_list(journal, true);
+		spin_unlock(&journal->j_list_lock);
+		cond_resched();
+	}
+}
+
+/*
  * journal_remove_checkpoint: called after a buffer has been committed
  * to disk (either by being write-back flushed to disk, or being
  * committed to the log).
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -435,7 +435,7 @@ void jbd2_journal_commit_transaction(jou
 	 * frees some memory
 	 */
 	spin_lock(&journal->j_list_lock);
-	__jbd2_journal_clean_checkpoint_list(journal);
+	__jbd2_journal_clean_checkpoint_list(journal, false);
 	spin_unlock(&journal->j_list_lock);
 
 	jbd_debug(3, "JBD2: commit phase 1\n");
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1571,8 +1571,17 @@ int jbd2_journal_destroy(journal_t *jour
 	while (journal->j_checkpoint_transactions != NULL) {
 		spin_unlock(&journal->j_list_lock);
 		mutex_lock(&journal->j_checkpoint_mutex);
-		jbd2_log_do_checkpoint(journal);
+		err = jbd2_log_do_checkpoint(journal);
 		mutex_unlock(&journal->j_checkpoint_mutex);
+		/*
+		 * If checkpointing failed, just free the buffers to avoid
+		 * looping forever
+		 */
+		if (err) {
+			jbd2_journal_destroy_checkpoint(journal);
+			spin_lock(&journal->j_list_lock);
+			break;
+		}
 		spin_lock(&journal->j_list_lock);
 	}
 
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -980,8 +980,9 @@ int __jbd2_update_log_tail(journal_t *jo
 extern void jbd2_journal_commit_transaction(journal_t *);
 
 /* Checkpoint list management */
-int __jbd2_journal_clean_checkpoint_list(journal_t *journal);
+int __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy);
 int __jbd2_journal_remove_checkpoint(struct journal_head *);
+void jbd2_journal_destroy_checkpoint(journal_t *journal);
 void __jbd2_journal_insert_checkpoint(struct journal_head *, transaction_t *);
 
 


  parent reply	other threads:[~2015-10-09  0:21 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-09  0:12 [PATCH 3.2 000/107] 3.2.72-rc1 review Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 035/107] PCI: Add dev_flags bit to access VPD through function 0 Ben Hutchings
2015-10-09  0:26   ` Rustad, Mark D
2015-10-09  1:22     ` Ben Hutchings
2015-10-09 17:02       ` Rustad, Mark D
2015-10-09  0:12 ` [PATCH 3.2 038/107] KVM: MMU: fix validation of mmio page fault Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 006/107] USB: sierra: add 1199:68AB device ID Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 008/107] md/raid1: extend spinlock to protect raid1_end_read_request against inconsistencies Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 012/107] rds: fix an integer overflow test in rds_info_getsockopt() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 003/107] jbd2: protect all log tail updates with j_checkpoint_mutex Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 019/107] x86/ldt: Correct LDT access in single stepping logic Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 016/107] net: Clone skb before setting peeked flag Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 004/107] xen/gntdevt: Fix race condition in gntdev_release() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 027/107] net: Fix RCU splat in af_key Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 034/107] mac80211: enable assoc check for mesh interfaces Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 036/107] PCI: Add VPD function 0 quirk for Intel Ethernet devices Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 009/107] target: REPORT LUNS should return LUN 0 even for dynamic ACLs Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 010/107] MIPS: Fix sched_getaffinity with MT FPAFF enabled Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 001/107] ipv6: Fix build failure when CONFIG_INET disabled Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 026/107] x86/ldt: Further fix FPU emulation Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 007/107] target/iscsi: Fix double free of a TUR followed by a solicited NOPOUT Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 030/107] dcache: Handle escaped paths in prepend_path Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 014/107] MIPS: Make set_pte() SMP safe Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 028/107] sctp: donot reset the overall_error_count in SHUTDOWN_RECEIVE state Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 025/107] ipc,sem: fix use after free on IPC_RMID after a task using same semaphore set exits Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 031/107] vfs: Test for and handle paths that are unreachable from their mnt_root Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 013/107] perf: Fix fasync handling on inherited events Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 021/107] localmodconfig: Use Kbuild files too Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 015/107] ocfs2: fix BUG in ocfs2_downconvert_thread_do_work() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 005/107] crypto: ixp4xx - Remove bogus BUG_ON on scattered dst buffer Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 024/107] libfc: Fix fc_fcp_cleanup_each_cmd() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 018/107] x86/ldt: Make modify_ldt synchronous Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 002/107] pktgen: Require CONFIG_INET due to use of IPv4 checksum function Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 017/107] net: Fix skb_set_peeked use-after-free bug Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 032/107] [media] rc-core: fix remove uevent generation Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 033/107] PCI: Fix TI816X class code quirk Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 020/107] x86/ldt: Correct FPU emulation access to LDT Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 023/107] libiscsi: Fix host busy blocking during connection teardown Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 037/107] usb: gadget: m66592-udc: forever loop in set_feature() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 039/107] auxdisplay: ks0108: fix refcount Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 029/107] sparc64: Fix userspace FPU register corruptions Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 022/107] dm btree: add ref counting ops for the leaves of top level btrees Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 011/107] xhci: fix off by one error in TRB DMA address boundary check Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 064/107] crypto: ghash-clmulni: specify context size for ghash async algorithm Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 067/107] pagemap: hide physical addresses from non-privileged users Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 048/107] xfs: Fix xfs_attr_leafblock definition Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 043/107] drivers: usb: fsl: Workaround for USB erratum-A005275 Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 081/107] usb: Use the USB_SS_MULT() macro to get the burst multiplier Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 087/107] ocfs2/dlm: fix deadlock when dispatch assert master Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 058/107] IB/uverbs: Fix race between ib_uverbs_open and remove_one Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 099/107] bonding: correct the MAC address for "follow" fail_over_mac policy Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 046/107] USB: ftdi_sio: Added custom PID for CustomWare products Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 059/107] spi: spi-pxa2xx: Check status register to determine if SSSR_TINT is disabled Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 061/107] Add radeon suspend/resume quirk for HP Compaq dc5750 Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 044/107] serial: 8250: bind to ALi Fast Infrared Controller (ALI5123) Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 103/107] ipv6: prevent fib6_run_gc() contention Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 073/107] Btrfs: fix read corruption of compressed and shared extents Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 050/107] rtlwifi: rtl8192cu: Add new device ID Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 069/107] hfs,hfsplus: cache pages correctly between bnode_create and bnode_free Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 086/107] x86/paravirt: Replace the paravirt nop with a bona fide empty function Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 089/107] md: use kzalloc() when bitmap is disabled Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 100/107] net/ipv6: Correct PIM6 mrt_lock handling Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 074/107] btrfs: skip waiting on ordered range for special files Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 078/107] ASoC: fix broken pxa SoC support Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 051/107] rtlwifi: rtl8192cu: Add new device ID Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 068/107] powerpc/MSI: Fix race condition in tearing down MSI interrupts Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 075/107] ARM: 7880/1: Clear the IT state independent of the Thumb-2 mode Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 104/107] ipv6: update ip6_rt_last_gc every time GC is run Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 095/107] net/tipc: initialize security state for new connection socket Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 047/107] eCryptfs: Invalidate dcache entries when lower i_nlink is zero Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 092/107] RDS: verify the underlying transport exists before creating a connection Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 072/107] USB: option: add ZTE PIDs Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 045/107] usb: host: ehci-sys: delete useless bus_to_hcd conversion Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 057/107] IB/mlx4: Use correct SL on AH query under RoCE Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 091/107] virtio-net: drop NETIF_F_FRAGLIST Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 049/107] DRM - radeon: Don't link train DisplayPort on HPD until we get the dpcd Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 076/107] ARM: fix Thumb2 signal handling when ARMv6 is enabled Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 066/107] ARM: 8429/1: disable GCC SRA optimization Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 090/107] ipv6: addrconf: validate new MTU before applying it Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 062/107] IB/uverbs: reject invalid or unknown opcodes Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 077/107] x86/platform: Fix Geode LX timekeeping in the generic x86 build Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 056/107] SUNRPC: xs_reset_transport must mark the connection as disconnected Ben Hutchings
2015-10-09  0:12 ` Ben Hutchings [this message]
2015-10-09  0:12 ` [PATCH 3.2 088/107] USB: whiteheat: fix potential null-deref at probe Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 101/107] fib_rules: fix fib rule dumps across multiple skbs Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 098/107] ipv6: lock socket in ip6_datagram_connect() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 055/107] IB/qib: Change lkey table allocation to support more MRs Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 094/107] Initialize msg/shm IPC objects before doing ipc_addid() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 082/107] xhci: give command abortion one more chance before killing xhci Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 096/107] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 105/107] parisc: Filter out spurious interrupts in PA-RISC irq handler Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 042/107] NFSv4: don't set SETATTR for O_RDONLY|O_EXCL Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 102/107] perf tools: Fix build with perl 5.18 Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 060/107] drm/i915: Always mark the object as dirty when used by the GPU Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 065/107] fs: create and use seq_show_option for escaping Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 097/107] net: Fix skb csum races when peeking Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 080/107] KVM: x86: trap AMD MSRs for the TSeg base and mask Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 071/107] perf header: Fixup reading of HEADER_NRCPUS feature Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 079/107] s390/compat: correct uc_sigmask of the compat signal frame Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 083/107] usb: xhci: Clear XHCI_STATE_DYING on start Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 093/107] ipc/sem.c: fully initialize sem_array before making it visible Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 041/107] windfarm: decrement client count when unregistering Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 070/107] hfs: fix B-tree corruption after insertion at position 0 Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 084/107] xhci: change xhci 1.0 only restrictions to support xhci 1.1 Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 053/107] drivercore: Fix unregistration path of platform devices Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 107/107] Revert "sctp: Fix race between OOTB responce and route removal" Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 063/107] Input: evdev - do not report errors form flush() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 085/107] cifs: use server timestamp for ntlmv2 authentication Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 052/107] of/address: Don't loop forever in of_find_matching_node_by_address() Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 054/107] xfs: return errors from partial I/O failures to files Ben Hutchings
2015-10-09  0:12 ` [PATCH 3.2 040/107] devres: fix devres_get() Ben Hutchings
2015-10-09  0:56 ` [PATCH 3.2 000/107] 3.2.72-rc1 review Guenter Roeck
2015-10-09  1:17   ` Ben Hutchings
2015-10-09  1:17 ` Ben Hutchings

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=lsq.1444349548.503556510@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=guaneryu@gmail.com \
    --cc=jack@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®