Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1359322

[PATCH 3.19.y-ckt 15/70] jffs2: Fix page lock / f->sem deadlock

From Kamal Mostafa <kamal@canonical.com>
Newsgroups linux.kernel
Subject [PATCH 3.19.y-ckt 15/70] jffs2: Fix page lock / f->sem deadlock
Date 2016-03-16 21:30 +0100
Message-ID <rdqeS-5tf-13@gated-at.bofh.it> (permalink)
References <rdpVv-5jX-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


v3.19.8-ckt17 -stable review patch.  If anyone has any objections, please let me know.

---8<------------------------------------------------------------

From: David Woodhouse <David.Woodhouse@intel.com>

commit 49e91e7079febe59a20ca885a87dd1c54240d0f1 upstream.

With this fix, all code paths should now be obtaining the page lock before
f->sem.

Reported-by: Szabó Tamás <sztomi89@gmail.com>
Tested-by: Thomas Betker <thomas.betker@rohde-schwarz.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 fs/jffs2/README.Locking |  5 +----
 fs/jffs2/gc.c           | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/fs/jffs2/README.Locking b/fs/jffs2/README.Locking
index 3ea3655..8918ac9 100644
--- a/fs/jffs2/README.Locking
+++ b/fs/jffs2/README.Locking
@@ -2,10 +2,6 @@
 	JFFS2 LOCKING DOCUMENTATION
 	---------------------------
 
-At least theoretically, JFFS2 does not require the Big Kernel Lock
-(BKL), which was always helpfully obtained for it by Linux 2.4 VFS
-code. It has its own locking, as described below.
-
 This document attempts to describe the existing locking rules for
 JFFS2. It is not expected to remain perfectly up to date, but ought to
 be fairly close.
@@ -69,6 +65,7 @@ Ordering constraints:
 	   any f->sem held.
 	2. Never attempt to lock two file mutexes in one thread.
 	   No ordering rules have been made for doing so.
+	3. Never lock a page cache page with f->sem held.
 
 
 	erase_completion_lock spinlock
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index 5a2dec2..95d5880 100644
--- a/fs/jffs2/gc.c
+++ b/fs/jffs2/gc.c
@@ -1296,14 +1296,17 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
 		BUG_ON(start > orig_start);
 	}
 
-	/* First, use readpage() to read the appropriate page into the page cache */
-	/* Q: What happens if we actually try to GC the _same_ page for which commit_write()
-	 *    triggered garbage collection in the first place?
-	 * A: I _think_ it's OK. read_cache_page shouldn't deadlock, we'll write out the
-	 *    page OK. We'll actually write it out again in commit_write, which is a little
-	 *    suboptimal, but at least we're correct.
-	 */
+	/* The rules state that we must obtain the page lock *before* f->sem, so
+	 * drop f->sem temporarily. Since we also hold c->alloc_sem, nothing's
+	 * actually going to *change* so we're safe; we only allow reading.
+	 *
+	 * It is important to note that jffs2_write_begin() will ensure that its
+	 * page is marked Uptodate before allocating space. That means that if we
+	 * end up here trying to GC the *same* page that jffs2_write_begin() is
+	 * trying to write out, read_cache_page() will not deadlock. */
+	mutex_unlock(&f->sem);
 	pg_ptr = jffs2_gc_fetch_page(c, f, start, &pg);
+	mutex_lock(&f->sem);
 
 	if (IS_ERR(pg_ptr)) {
 		pr_warn("read_cache_page() returned error: %ld\n",
-- 
2.7.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[3.19.y-ckt stable] Linux v3.19.8-ckt17 stable review Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 03/70] wext: fix message delay/ordering Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 58/70] tracing: Fix check for cpu online when event is disabled Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 53/70] ARM: dts: dra7: do not gate cpsw clock due to errata i877 Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 09/70] ahci: add new Intel device IDs Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 47/70] ovl: fix getcwd() failure after unsuccessful rmdir Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 54/70] Revert "drm/radeon: call hpd_irq_event on resume" Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 16/70] Fix directory hardlinks from deleted directories Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 44/70] drm/radeon/pm: update current crtc info after setting the powerstate Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 23/70] ALSA: rawmidi: Fix ioctls X32 ABI Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 69/70] mld, igmp: Fix reserved tailroom calculation Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:10 +0100
  [PATCH 3.19.y-ckt 61/70] gpio: rcar: Add Runtime PM handling for interrupts Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 56/70] jffs2: reduce the breakage on recovery from halfway failed rename() Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 65/70] ipv6: re-enable fragment header matching in ipv6_find_hdr Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 66/70] cdc_ncm: do not call usbnet_link_change from cdc_ncm_bind Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 51/70] target: Drop incorrect ABORT_TASK put for completed commands Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 55/70] KVM: PPC: Book3S HV: Sanitize special-purpose register values on guest exit Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 46/70] ALSA: hda - Fix mic issues on Acer Aspire E1-472 Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 29/70] arm/arm64: KVM: Fix ioctl error handling Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 52/70] ARM: OMAP2+: hwmod: Introduce ti,no-idle dt property Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 34/70] USB: cp210x: Add ID for Parrot NMEA GPS Flight Recorder Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 24/70] ALSA: timer: Fix broken compat timer user status ioctl Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 57/70] KVM: VMX: disable PEBS before a guest entry Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 50/70] ubi: Fix out of bounds write in volume update code Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 67/70] net: qca_spi: Don't clear IFF_BROADCAST Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 43/70] USB: qcserial: add Sierra Wireless EM74xx device ID Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 45/70] PM / sleep / x86: Fix crash on graph trace through x86 suspend Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 39/70] USB: serial: option: add support for Quectel UC20 Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 62/70] tcp: convert cached rtt from usec to jiffies when feeding initial rto Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 64/70] net/mlx4_core: Allow resetting VF admin mac to zero Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 59/70] KVM: MMU: fix ept=0/pte.u=1/pte.w=0/CR0.WP=0/CR4.SMEP=1/EFER.NX=0 combo Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 63/70] ext4: iterate over buffer heads correctly in move_extent_per_page() Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 49/70] MIPS: traps: Fix SIGFPE information leak from `do_ov' and `do_trap_or_bp' Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 42/70] drm/ast: Fix incorrect register check for DRAM width Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 40/70] mac80211: Fix Public Action frame RX in AP mode Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 41/70] ALSA: seq: oss: Don't drain at closing a client Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 32/70] ALSA: hdsp: Fix wrong boolean ctl value accesses Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 60/70] MIPS: Fix build error when SMP is used without GIC Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 38/70] USB: serial: option: add support for Telit LE922 PID 0x1045 Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 48/70] ovl: copy new uid/gid into overlayfs runtime inode Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:20 +0100
  [PATCH 3.19.y-ckt 04/70] cfg80211/wext: fix message ordering Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 11/70] Adding Intel Lewisburg device IDs for SATA Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 30/70] ALSA: hdspm: Fix wrong boolean ctl value accesses Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 15/70] jffs2: Fix page lock / f->sem deadlock Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 05/70] mac80211: fix use of uninitialised values in RX aggregation Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 18/70] iommu/amd: Apply workaround for ATS write permission check Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 28/70] Fix cifs_uniqueid_to_ino_t() function for s390x Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 10/70] ahci: Order SATA device IDs for codename Lewisburg Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 33/70] USB: qcserial: add Dell Wireless 5809e Gobi 4G HSPA+ (rev3) Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 37/70] ASoC: wm_adsp: Fix enum ctl accesses in a wrong type Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 26/70] cifs: fix out-of-bounds access in lease parsing Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 22/70] ALSA: ctl: Fix ioctls for X32 ABI Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 02/70] Input: aiptek - fix crash on detecting device without endpoints Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 06/70] libata: fix HDIO_GET_32BIT ioctl Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 20/70] can: gs_usb: fixed disconnect bug by removing erroneous use of kfree() Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 25/70] ALSA: timer: Fix ioctls for X32 ABI Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 31/70] ALSA: hdspm: Fix zero-division Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 14/70] Revert "jffs2: Fix lock acquisition order bug in jffs2_write_begin" Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 27/70] CIFS: Fix SMB2+ interim response processing for read requests Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 36/70] ASoC: wm8994: Fix enum ctl accesses in a wrong type Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 12/70] mac80211: minstrel_ht: set default tx aggregation timeout to 0 Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 17/70] iommu/amd: Fix boot warning when device 00:00.0 is not iommu covered Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 21/70] vfio: fix ioctl error handling Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 13/70] usb: chipidea: otg: change workqueue ci_otg as freezable Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 35/70] ASoC: wm8958: Fix enum ctl accesses in a wrong type Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 07/70] iwlwifi: mvm: inc pending frames counter also when txing non-sta Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100
  [PATCH 3.19.y-ckt 19/70] libata: Align ata_device's id on a cacheline Kamal Mostafa <kamal@canonical.com> - 2016-03-16 21:30 +0100

csiph-web