linux-uconsole/drivers/md
Mikulas Patocka fbb41f55c4 dm raid1: fix crash with mirror recovery and discard
commit 751f188dd5 upstream.

This patch fixes a crash when a discard request is sent during mirror
recovery.

Firstly, some background.  Generally, the following sequence happens during
mirror synchronization:
- function do_recovery is called
- do_recovery calls dm_rh_recovery_prepare
- dm_rh_recovery_prepare uses a semaphore to limit the number
  simultaneously recovered regions (by default the semaphore value is 1,
  so only one region at a time is recovered)
- dm_rh_recovery_prepare calls __rh_recovery_prepare,
  __rh_recovery_prepare asks the log driver for the next region to
  recover. Then, it sets the region state to DM_RH_RECOVERING. If there
  are no pending I/Os on this region, the region is added to
  quiesced_regions list. If there are pending I/Os, the region is not
  added to any list. It is added to the quiesced_regions list later (by
  dm_rh_dec function) when all I/Os finish.
- when the region is on quiesced_regions list, there are no I/Os in
  flight on this region. The region is popped from the list in
  dm_rh_recovery_start function. Then, a kcopyd job is started in the
  recover function.
- when the kcopyd job finishes, recovery_complete is called. It calls
  dm_rh_recovery_end. dm_rh_recovery_end adds the region to
  recovered_regions or failed_recovered_regions list (depending on
  whether the copy operation was successful or not).

The above mechanism assumes that if the region is in DM_RH_RECOVERING
state, no new I/Os are started on this region. When I/O is started,
dm_rh_inc_pending is called, which increases reg->pending count. When
I/O is finished, dm_rh_dec is called. It decreases reg->pending count.
If the count is zero and the region was in DM_RH_RECOVERING state,
dm_rh_dec adds it to the quiesced_regions list.

Consequently, if we call dm_rh_inc_pending/dm_rh_dec while the region is
in DM_RH_RECOVERING state, it could be added to quiesced_regions list
multiple times or it could be added to this list when kcopyd is copying
data (it is assumed that the region is not on any list while kcopyd does
its jobs). This results in memory corruption and crash.

There already exist bypasses for REQ_FLUSH requests: REQ_FLUSH requests
do not belong to any region, so they are always added to the sync list
in do_writes. dm_rh_inc_pending does not increase count for REQ_FLUSH
requests. In mirror_end_io, dm_rh_dec is never called for REQ_FLUSH
requests. These bypasses avoid the crash possibility described above.

These bypasses were improperly implemented for REQ_DISCARD when
the mirror target gained discard support in commit
5fc2ffeabb (dm raid1: support discard).

In do_writes, REQ_DISCARD requests is always added to the sync queue and
immediately dispatched (even if the region is in DM_RH_RECOVERING).  However,
dm_rh_inc and dm_rh_dec is called for REQ_DISCARD resusts.  So it violates the
rule that no I/Os are started on DM_RH_RECOVERING regions, and causes the list
corruption described above.

This patch changes it so that REQ_DISCARD requests follow the same path
as REQ_FLUSH. This avoids the crash.

Reference: https://bugzilla.redhat.com/837607

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-08-01 12:26:54 -07:00
..
bitmap.c md/bitmap: prevent bitmap_daemon_work running while initialising bitmap 2012-04-22 16:21:44 -07:00
bitmap.h md/bitmap: remove unused fields from struct bitmap 2011-06-09 11:43:01 +10:00
dm-bio-record.h
dm-crypt.c dm crypt: add missing error handling 2012-04-02 09:27:19 -07:00
dm-delay.c dm: convert workqueues to alloc_ordered 2011-01-13 19:59:57 +00:00
dm-exception-store.c dm exception store: fix init error path 2012-04-02 09:27:19 -07:00
dm-exception-store.h dm snapshot: test chunk size against both origin and snapshot 2010-08-12 04:13:51 +01:00
dm-flakey.c dm: do not forward ioctls from logical volumes to the underlying device 2012-01-25 17:24:54 -08:00
dm-io.c dm io: fix discard support 2012-03-12 10:33:01 -07:00
dm-ioctl.c dm ioctl: add flag to wipe buffers for secure data 2011-03-24 13:54:30 +00:00
dm-kcopyd.c dm kcopyd: return client directly and not through a pointer 2011-05-29 13:03:13 +01:00
dm-linear.c dm: do not forward ioctls from logical volumes to the underlying device 2012-01-25 17:24:54 -08:00
dm-log-userspace-base.c dm log userspace: add version number to comms 2011-01-13 19:59:52 +00:00
dm-log-userspace-transfer.c netlink: kill eff_cap from struct netlink_skb_parms 2011-03-03 13:32:07 -08:00
dm-log-userspace-transfer.h dm log: userspace add luid to distinguish between concurrent log instances 2009-09-04 20:40:34 +01:00
dm-log.c dm io: use fixed initial mempool size 2011-05-29 13:03:09 +01:00
dm-mpath.c dm: do not forward ioctls from logical volumes to the underlying device 2012-01-25 17:24:54 -08:00
dm-mpath.h
dm-path-selector.c
dm-path-selector.h dm mpath: add start_io and nr_bytes to path selectors 2009-06-22 10:12:27 +01:00
dm-queue-length.c dm mpath: add queue length load balancer 2009-06-22 10:12:27 +01:00
dm-raid.c dm raid: fix flush support 2012-03-12 10:33:01 -07:00
dm-raid1.c dm raid1: fix crash with mirror recovery and discard 2012-08-01 12:26:54 -07:00
dm-region-hash.c dm raid1: fix crash with mirror recovery and discard 2012-08-01 12:26:54 -07:00
dm-round-robin.c dm mpath: add start_io and nr_bytes to path selectors 2009-06-22 10:12:27 +01:00
dm-service-time.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
dm-snap-persistent.c dm snapshot: flush disk cache when merging 2011-08-04 21:58:42 -07:00
dm-snap-transient.c dm snapshot: move cow ref from exception store to snap core 2009-12-10 23:52:12 +00:00
dm-snap.c dm kcopyd: return client directly and not through a pointer 2011-05-29 13:03:13 +01:00
dm-stripe.c dm stripe: implement merge method 2011-03-24 13:54:35 +00:00
dm-sysfs.c Driver core: Constify struct sysfs_ops in struct kobj_type 2010-03-07 17:04:49 -08:00
dm-table.c dm table: avoid crash if integrity profile changes 2011-10-16 14:14:53 -07:00
dm-target.c dm: error return error for discards 2010-08-12 04:14:14 +01:00
dm-uevent.c dm table: remove dm_get from dm_table_get_md 2010-03-06 02:29:52 +00:00
dm-uevent.h
dm-zero.c dm: zero silently drop discards 2010-08-12 04:14:12 +01:00
dm.c dm: fix idr leak on module removal 2011-08-04 21:58:43 -07:00
dm.h block: Require subsystems to explicitly allocate bio_set integrity mempool 2011-03-17 11:11:05 +01:00
faulty.c Fix common misspellings 2011-03-31 11:26:23 -03:00
Kconfig dm: add flakey target 2011-03-24 13:54:24 +00:00
linear.c block: Require subsystems to explicitly allocate bio_set integrity mempool 2011-03-17 11:11:05 +01:00
linear.h md/linear: avoid corrupting structure while waiting for rcu_free to complete. 2011-10-03 11:40:03 -07:00
Makefile dm: add flakey target 2011-03-24 13:54:24 +00:00
md.c md: using GFP_NOIO to allocate bio for flush request 2012-06-01 15:12:56 +08:00
md.h md: Avoid waking up a thread after it has been freed. 2011-10-16 14:14:53 -07:00
multipath.c md: Avoid waking up a thread after it has been freed. 2011-10-16 14:14:53 -07:00
multipath.h md/multipath: discard ->working_disks in favour of ->degraded 2011-05-11 14:38:02 +10:00
raid0.c block: Require subsystems to explicitly allocate bio_set integrity mempool 2011-03-17 11:11:05 +01:00
raid0.h md: fix handling of array level takeover that re-arranges devices. 2010-06-24 13:33:24 +10:00
raid1.c md/raid1,raid10: avoid deadlock during resync/recovery. 2012-04-02 09:27:11 -07:00
raid1.h MD: raid1 changes to allow use by device mapper 2011-06-08 15:11:31 +10:00
raid5.c md/raid5: Do not add data_offset before call to is_badblock 2012-07-16 08:47:51 -07:00
raid5.h md - remove old plugging code. 2011-04-18 18:25:42 +10:00
raid10.c md/raid10: Don't try to recovery unmatched (and unused) chunks. 2012-07-16 08:47:52 -07:00
raid10.h Fix common misspellings 2011-03-31 11:26:23 -03:00