stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Mikulas Patocka <mpatocka@redhat.com>,
	Mike Snitzer <snitzer@redhat.com>
Subject: [PATCH 3.19 62/75] dm snapshot: suspend origin when doing exception handover
Date: Fri, 10 Apr 2015 15:19:28 +0200	[thread overview]
Message-ID: <20150410131710.758950445@linuxfoundation.org> (raw)
In-Reply-To: <20150410131707.794709951@linuxfoundation.org>

3.19-stable review patch.  If anyone has any objections, please let me know.

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

From: Mikulas Patocka <mpatocka@redhat.com>

commit b735fede8d957d9d255e9c5cf3964cfa59799637 upstream.

In the function snapshot_resume we perform exception store handover.  If
there is another active snapshot target, the exception store is moved
from this target to the target that is being resumed.

The problem is that if there is some pending exception, it will point to
an incorrect exception store after that handover, causing a crash due to
dm-snap-persistent.c:get_exception()'s BUG_ON.

This bug can be triggered by repeatedly changing snapshot permissions
with "lvchange -p r" and "lvchange -p rw" while there are writes on the
associated origin device.

To fix this bug, we must suspend the origin device when doing the
exception store handover to make sure that there are no pending
exceptions:
- introduce _origin_hash that keeps track of dm_origin structures.
- introduce functions __lookup_dm_origin, __insert_dm_origin and
  __remove_dm_origin that manipulate the origin hash.
- modify snapshot_resume so that it calls dm_internal_suspend_fast() and
  dm_internal_resume_fast() on the origin device.

NOTE to stable@ people:

When backporting to kernels 3.12-3.18, use dm_internal_suspend and
dm_internal_resume instead of dm_internal_suspend_fast and
dm_internal_resume_fast.

When backporting to kernels older than 3.12, you need to pick functions
dm_internal_suspend and dm_internal_resume from the commit
fd2ed4d252701d3bbed4cd3e3d267ad469bb832a.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/md/dm-snap.c |   93 ++++++++++++++++++++++++++++++++++++++++++++++-----
 drivers/md/dm.c      |    2 +
 2 files changed, 86 insertions(+), 9 deletions(-)

--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -20,6 +20,8 @@
 #include <linux/log2.h>
 #include <linux/dm-kcopyd.h>
 
+#include "dm.h"
+
 #include "dm-exception-store.h"
 
 #define DM_MSG_PREFIX "snapshots"
@@ -291,12 +293,23 @@ struct origin {
 };
 
 /*
+ * This structure is allocated for each origin target
+ */
+struct dm_origin {
+	struct dm_dev *dev;
+	struct dm_target *ti;
+	unsigned split_boundary;
+	struct list_head hash_list;
+};
+
+/*
  * Size of the hash table for origin volumes. If we make this
  * the size of the minors list then it should be nearly perfect
  */
 #define ORIGIN_HASH_SIZE 256
 #define ORIGIN_MASK      0xFF
 static struct list_head *_origins;
+static struct list_head *_dm_origins;
 static struct rw_semaphore _origins_lock;
 
 static DECLARE_WAIT_QUEUE_HEAD(_pending_exceptions_done);
@@ -310,12 +323,22 @@ static int init_origin_hash(void)
 	_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
 			   GFP_KERNEL);
 	if (!_origins) {
-		DMERR("unable to allocate memory");
+		DMERR("unable to allocate memory for _origins");
 		return -ENOMEM;
 	}
-
 	for (i = 0; i < ORIGIN_HASH_SIZE; i++)
 		INIT_LIST_HEAD(_origins + i);
+
+	_dm_origins = kmalloc(ORIGIN_HASH_SIZE * sizeof(struct list_head),
+			      GFP_KERNEL);
+	if (!_dm_origins) {
+		DMERR("unable to allocate memory for _dm_origins");
+		kfree(_origins);
+		return -ENOMEM;
+	}
+	for (i = 0; i < ORIGIN_HASH_SIZE; i++)
+		INIT_LIST_HEAD(_dm_origins + i);
+
 	init_rwsem(&_origins_lock);
 
 	return 0;
@@ -324,6 +347,7 @@ static int init_origin_hash(void)
 static void exit_origin_hash(void)
 {
 	kfree(_origins);
+	kfree(_dm_origins);
 }
 
 static unsigned origin_hash(struct block_device *bdev)
@@ -350,6 +374,30 @@ static void __insert_origin(struct origi
 	list_add_tail(&o->hash_list, sl);
 }
 
+static struct dm_origin *__lookup_dm_origin(struct block_device *origin)
+{
+	struct list_head *ol;
+	struct dm_origin *o;
+
+	ol = &_dm_origins[origin_hash(origin)];
+	list_for_each_entry (o, ol, hash_list)
+		if (bdev_equal(o->dev->bdev, origin))
+			return o;
+
+	return NULL;
+}
+
+static void __insert_dm_origin(struct dm_origin *o)
+{
+	struct list_head *sl = &_dm_origins[origin_hash(o->dev->bdev)];
+	list_add_tail(&o->hash_list, sl);
+}
+
+static void __remove_dm_origin(struct dm_origin *o)
+{
+	list_del(&o->hash_list);
+}
+
 /*
  * _origins_lock must be held when calling this function.
  * Returns number of snapshots registered using the supplied cow device, plus:
@@ -1841,8 +1889,20 @@ static void snapshot_resume(struct dm_ta
 {
 	struct dm_snapshot *s = ti->private;
 	struct dm_snapshot *snap_src = NULL, *snap_dest = NULL;
+	struct dm_origin *o;
+	struct mapped_device *origin_md = NULL;
 
 	down_read(&_origins_lock);
+
+	o = __lookup_dm_origin(s->origin->bdev);
+	if (o)
+		origin_md = dm_table_get_md(o->ti->table);
+	if (origin_md == dm_table_get_md(ti->table))
+		origin_md = NULL;
+
+	if (origin_md)
+		dm_internal_suspend_fast(origin_md);
+
 	(void) __find_snapshots_sharing_cow(s, &snap_src, &snap_dest, NULL);
 	if (snap_src && snap_dest) {
 		down_write(&snap_src->lock);
@@ -1851,6 +1911,10 @@ static void snapshot_resume(struct dm_ta
 		up_write(&snap_dest->lock);
 		up_write(&snap_src->lock);
 	}
+
+	if (origin_md)
+		dm_internal_resume_fast(origin_md);
+
 	up_read(&_origins_lock);
 
 	/* Now we have correct chunk size, reregister */
@@ -2133,11 +2197,6 @@ static int origin_write_extent(struct dm
  * Origin: maps a linear range of a device, with hooks for snapshotting.
  */
 
-struct dm_origin {
-	struct dm_dev *dev;
-	unsigned split_boundary;
-};
-
 /*
  * Construct an origin mapping: <dev_path>
  * The context for an origin is merely a 'struct dm_dev *'
@@ -2166,6 +2225,7 @@ static int origin_ctr(struct dm_target *
 		goto bad_open;
 	}
 
+	o->ti = ti;
 	ti->private = o;
 	ti->num_flush_bios = 1;
 
@@ -2180,6 +2240,7 @@ bad_alloc:
 static void origin_dtr(struct dm_target *ti)
 {
 	struct dm_origin *o = ti->private;
+
 	dm_put_device(ti, o->dev);
 	kfree(o);
 }
@@ -2216,6 +2277,19 @@ static void origin_resume(struct dm_targ
 	struct dm_origin *o = ti->private;
 
 	o->split_boundary = get_origin_minimum_chunksize(o->dev->bdev);
+
+	down_write(&_origins_lock);
+	__insert_dm_origin(o);
+	up_write(&_origins_lock);
+}
+
+static void origin_postsuspend(struct dm_target *ti)
+{
+	struct dm_origin *o = ti->private;
+
+	down_write(&_origins_lock);
+	__remove_dm_origin(o);
+	up_write(&_origins_lock);
 }
 
 static void origin_status(struct dm_target *ti, status_type_t type,
@@ -2258,12 +2332,13 @@ static int origin_iterate_devices(struct
 
 static struct target_type origin_target = {
 	.name    = "snapshot-origin",
-	.version = {1, 8, 1},
+	.version = {1, 9, 0},
 	.module  = THIS_MODULE,
 	.ctr     = origin_ctr,
 	.dtr     = origin_dtr,
 	.map     = origin_map,
 	.resume  = origin_resume,
+	.postsuspend = origin_postsuspend,
 	.status  = origin_status,
 	.merge	 = origin_merge,
 	.iterate_devices = origin_iterate_devices,
@@ -2271,7 +2346,7 @@ static struct target_type origin_target
 
 static struct target_type snapshot_target = {
 	.name    = "snapshot",
-	.version = {1, 12, 0},
+	.version = {1, 13, 0},
 	.module  = THIS_MODULE,
 	.ctr     = snapshot_ctr,
 	.dtr     = snapshot_dtr,
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -3007,6 +3007,7 @@ void dm_internal_suspend_fast(struct map
 	flush_workqueue(md->wq);
 	dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE);
 }
+EXPORT_SYMBOL_GPL(dm_internal_suspend_fast);
 
 void dm_internal_resume_fast(struct mapped_device *md)
 {
@@ -3018,6 +3019,7 @@ void dm_internal_resume_fast(struct mapp
 done:
 	mutex_unlock(&md->suspend_lock);
 }
+EXPORT_SYMBOL_GPL(dm_internal_resume_fast);
 
 /*-----------------------------------------------------------------
  * Event notification.



  parent reply	other threads:[~2015-04-10 13:19 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10 13:18 [PATCH 3.19 00/75] 3.19.4-stable review Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 01/75] ASoC: da732x: Fix control-less DAPM routes Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 02/75] ASoC: ak4671: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 03/75] ASoC: sn95031: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 04/75] ASoC: sgtl5000: remove useless register write clearing CHRGPUMP_POWERUP Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 05/75] ASoC: pcm1681: Fix wrong value references for boolean kctl Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 06/75] ASoC: cs4271: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 07/75] ASoC: es8238: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 08/75] ASoC: wm8960: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 09/75] ASoC: tas5086: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 10/75] ASoC: wm8731: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 11/75] ASoC: wm2000: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 12/75] ASoC: wm8903: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 13/75] ASoC: wm8904: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 14/75] ASoC: ak4641: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 15/75] ASoC: adav80x: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 16/75] ASoC: wm8955: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 17/75] ASoC: wm9712: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 18/75] ASoC: wm9713: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 19/75] virtio_balloon: set DRIVER_OK before using device Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 20/75] virtio-balloon: do not call blocking ops when !TASK_RUNNING Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 21/75] clockevents: sun5i: Fix setup_irq init sequence Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 22/75] regmap: regcache-rbtree: Fix present bitmap resize Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 23/75] regmap: introduce regmap_name to fix syscon regmap trace events Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 25/75] tcm_fc: missing curly braces in ft_invl_hw_context() Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 26/75] tcm_qla2xxx: Fix incorrect use of __transport_register_session Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 27/75] Input: synaptics - split synaptics_resolution(), query first Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 28/75] Input: synaptics - log queried and quirked dimension values Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 29/75] Input: synaptics - query min dimensions for fw v8.1 Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 30/75] Input: synaptics - remove obsolete min/max quirk for X240 Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 31/75] Input: synaptics - support min/max board id in min_max_pnpid_table Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 32/75] Input: synaptics - skip quirks when post-2013 dimensions Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 33/75] Input: synaptics - fix middle button on Lenovo 2015 products Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 34/75] Input: synaptics - handle spurious release of trackstick buttons Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 35/75] Input: synaptics - do not retrieve the board id on old firmwares Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 36/75] nl80211: ignore HT/VHT capabilities without QoS/WMM Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 37/75] mac80211: disable u-APSD queues by default Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 38/75] mac80211: drop unencrypted frames in mesh fwding Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 39/75] mac80211: count interfaces correctly for combination checks Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 40/75] powercap / RAPL: handle domains with different energy units Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 41/75] iwlwifi: mvm: rs: fix BT Coex check to look at the correct ant Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 42/75] iwlwifi: fix max_ht_ampdu_exponent for older devices Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 43/75] iwlwifi: mvm: BT Coex - fix a NULL pointer exception Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 44/75] iwlwifi: mvm: Fix ROC removal Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 45/75] uas: Add US_FL_NO_ATA_1X for Initio Corporation controllers / devices Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 46/75] usb: phy: am335x-control: check return value of bus_find_device Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 47/75] usb: chipidea: otg: add a_alt_hnp_support response for B device Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 48/75] usb: common: otg-fsm: only signal connect after switching to peripheral Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 49/75] phy: Find the right match in devm_phy_destroy() Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 50/75] rtlwifi: Improve handling of IPv6 packets Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 51/75] cpuidle: mvebu: Fix the CPU PM notifier usage Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 52/75] brcmfmac: Perform bound checking on vendor command buffer Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 53/75] of/irq: Fix of_irq_parse_one() returned error codes Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 54/75] perf: Fix irq_work tail recursion Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 55/75] staging: vt6656: vnt_rf_setpower: fix missing rate RATE_12M Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 56/75] vt6655: RFbSetPower " Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 57/75] vt6655: Fix late setting of byRFType Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 58/75] dmaengine: dw: append MODULE_ALIAS for platform driver Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 59/75] dm: hold suspend_lock while suspending device during device deletion Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 60/75] dm io: deal with wandering queue limits when handling REQ_DISCARD and REQ_WRITE_SAME Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 61/75] dm thin: fix to consistently zero-fill reads to unprovisioned blocks Greg Kroah-Hartman
2015-04-10 13:19 ` Greg Kroah-Hartman [this message]
2015-04-10 13:19 ` [PATCH 3.19 63/75] dm snapshot: suspend merging snapshot when doing exception handover Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 64/75] spi: qup: Fix cs-num DT property parsing Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 65/75] spi: dw-mid: clear BUSY flag fist and test other one Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 67/75] hfsplus: fix B-tree corruption after insertion at position 0 Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 68/75] powerpc/book3s: Fix the MCE code to use CONFIG_KVM_BOOK3S_64_HANDLER Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 69/75] regulator: palmas: Correct TPS659038 register definition for REGEN2 Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 70/75] arm64: Use the reserved TTBR0 if context switching to the init_mm Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 71/75] arm64: percpu: Make this_cpu accessors pre-empt safe Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 72/75] powerpc/pseries: Little endian fixes for post mobility device tree update Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 73/75] powerpc/mpc85xx: Add ranges to etsec2 nodes Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 74/75] net: ethernet: pcnet32: Setup the SRAM and NOUFLO on Am79C97{3, 5} Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 75/75] mfd: kempld-core: Fix callback return value check Greg Kroah-Hartman
2015-04-10 18:03 ` [PATCH 3.19 00/75] 3.19.4-stable review Guenter Roeck
2015-04-11  7:33   ` Greg Kroah-Hartman

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=20150410131710.758950445@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).