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.12 051/107] dm: wait until embedded kobject is released before destroying a device
Date: Tue, 11 Feb 2014 11:05:17 -0800	[thread overview]
Message-ID: <20140211184749.651719612@linuxfoundation.org> (raw)
In-Reply-To: <20140211184748.191276235@linuxfoundation.org>

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

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

From: Mikulas Patocka <mpatocka@redhat.com>

commit be35f486108227e10fe5d96fd42fb2b344c59983 upstream.

There may be other parts of the kernel holding a reference on the dm
kobject.  We must wait until all references are dropped before
deallocating the mapped_device structure.

The dm_kobject_release method signals that all references are dropped
via completion.  But dm_kobject_release doesn't free the kobject (which
is embedded in the mapped_device structure).

This is the sequence of operations:
* when destroying a DM device, call kobject_put from dm_sysfs_exit
* wait until all users stop using the kobject, when it happens the
  release method is called
* the release method signals the completion and should return without
  delay
* the dm device removal code that waits on the completion continues
* the dm device removal code drops the dm_mod reference the device had
* the dm device removal code frees the mapped_device structure that
  contains the kobject

Using kobject this way should avoid the module unload race that was
mentioned at the beginning of this thread:
https://lkml.org/lkml/2014/1/4/83

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-sysfs.c |   10 +++++++++-
 drivers/md/dm.c       |   11 +++++++++++
 drivers/md/dm.h       |    2 ++
 3 files changed, 22 insertions(+), 1 deletion(-)

--- a/drivers/md/dm-sysfs.c
+++ b/drivers/md/dm-sysfs.c
@@ -79,6 +79,11 @@ static const struct sysfs_ops dm_sysfs_o
 	.show	= dm_attr_show,
 };
 
+static void dm_kobject_release(struct kobject *kobj)
+{
+	complete(dm_get_completion_from_kobject(kobj));
+}
+
 /*
  * dm kobject is embedded in mapped_device structure
  * no need to define release function here
@@ -86,6 +91,7 @@ static const struct sysfs_ops dm_sysfs_o
 static struct kobj_type dm_ktype = {
 	.sysfs_ops	= &dm_sysfs_ops,
 	.default_attrs	= dm_attrs,
+	.release	= dm_kobject_release,
 };
 
 /*
@@ -104,5 +110,7 @@ int dm_sysfs_init(struct mapped_device *
  */
 void dm_sysfs_exit(struct mapped_device *md)
 {
-	kobject_put(dm_kobject(md));
+	struct kobject *kobj = dm_kobject(md);
+	kobject_put(kobj);
+	wait_for_completion(dm_get_completion_from_kobject(kobj));
 }
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -197,6 +197,9 @@ struct mapped_device {
 	/* sysfs handle */
 	struct kobject kobj;
 
+	/* wait until the kobject is released */
+	struct completion kobj_completion;
+
 	/* zero-length flush that will be cloned and submitted to targets */
 	struct bio flush_bio;
 
@@ -2005,6 +2008,7 @@ static struct mapped_device *alloc_dev(i
 	init_waitqueue_head(&md->wait);
 	INIT_WORK(&md->work, dm_wq_work);
 	init_waitqueue_head(&md->eventq);
+	init_completion(&md->kobj_completion);
 
 	md->disk->major = _major;
 	md->disk->first_minor = minor;
@@ -2889,6 +2893,13 @@ struct mapped_device *dm_get_from_kobjec
 	return md;
 }
 
+struct completion *dm_get_completion_from_kobject(struct kobject *kobj)
+{
+	struct mapped_device *md = container_of(kobj, struct mapped_device, kobj);
+
+	return &md->kobj_completion;
+}
+
 int dm_suspended_md(struct mapped_device *md)
 {
 	return test_bit(DMF_SUSPENDED, &md->flags);
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -15,6 +15,7 @@
 #include <linux/list.h>
 #include <linux/blkdev.h>
 #include <linux/hdreg.h>
+#include <linux/completion.h>
 
 #include "dm-stats.h"
 
@@ -142,6 +143,7 @@ int dm_sysfs_init(struct mapped_device *
 void dm_sysfs_exit(struct mapped_device *md);
 struct kobject *dm_kobject(struct mapped_device *md);
 struct mapped_device *dm_get_from_kobject(struct kobject *kobj);
+struct completion *dm_get_completion_from_kobject(struct kobject *kobj);
 
 /*
  * Targets for linear and striped mappings



  parent reply	other threads:[~2014-02-11 19:05 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-11 19:04 [PATCH 3.12 000/107] 3.12.11-stable review Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 001/107] SELinux: Fix memory leak upon loading policy Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 002/107] tracing: Have trace buffer point back to trace_array Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 003/107] tracing: Check if tracing is enabled in trace_puts() Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 004/107] arch/sh/kernel/kgdb.c: add missing #include <linux/sched.h> Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 005/107] intel-iommu: fix off-by-one in pagetable freeing Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 006/107] Revert "EISA: Initialize device before its resources" Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 007/107] fuse: fix pipe_buf_operations Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 008/107] audit: reset audit backlog wait time after error recovery Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 009/107] audit: correct a type mismatch in audit_syscall_exit() Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 010/107] xen/pvhvm: If xen_platform_pci=0 is set dont blow up (v4) Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 011/107] mm/memory-failure.c: shift page lock from head page to tail page after thp split Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 012/107] mm/memcg: iteration skip memcgs not yet fully initialized Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 013/107] mm/page-writeback.c: fix dirty_balance_reserve subtraction from dirtyable memory Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 014/107] mm/page-writeback.c: do not count anon pages as " Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 015/107] memcg: fix endless loop caused by mem_cgroup_iter Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 016/107] memcg: fix css reference leak and endless loop in mem_cgroup_iter Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 017/107] mm: ignore VM_SOFTDIRTY on VMA merging Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 018/107] mm: dont lose the SOFT_DIRTY flag on mprotect Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 019/107] mmc: fix host release issue after discard operation Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 020/107] mmc: atmel-mci: fix timeout errors in SDIO mode when using DMA Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 021/107] mmc: core: sd: implement proper support for sd3.0 au sizes Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 022/107] ARM: orion: provide C-style interrupt handler for MULTI_IRQ_HANDLER Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 023/107] ARM: mvebu: Fix kernel hang in mvebu_soc_id_init() when of_iomap failed Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 024/107] slub: Fix calculation of cpu slabs Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 025/107] turbostat: Dont put unprocessed uapi headers in the include path Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 027/107] ACPI / init: Flag use of ACPI and ACPI idioms for power supplies to regulator API Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 028/107] compat: fix sys_fanotify_mark Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 029/107] fs/compat: fix parameter handling for compat readv/writev syscalls Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 030/107] fs/compat: fix lookup_dcookie() parameter handling Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 031/107] tile: remove compat_sys_lookup_dcookie declaration to fix compile error Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 032/107] mtd: mxc_nand: remove duplicated ecc_stats counting Greg Kroah-Hartman
2014-02-11 19:04 ` [PATCH 3.12 033/107] ore: Fix wrong math in allocation of per device BIO Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 034/107] xtensa: xtfpga: fix definitions of platform devices Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 035/107] IB/qib: Fix QP check when looping back to/from QP1 Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 036/107] spi/bcm63xx: dont substract prepend length from total length Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 037/107] spidev: fix hang when transfer_one_message fails Greg Kroah-Hartman
2014-02-20 12:42   ` Geert Uytterhoeven
2014-02-20 21:41     ` Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 038/107] spi/pxa2xx: initialize DMA channels to -1 to prevent inadvertent match Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 039/107] NFSv4: OPEN must handle the NFS4ERR_IO return code correctly Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 040/107] nfs4.1: properly handle ENOTSUP in SECINFO_NO_NAME Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 042/107] NFSv4.1: Handle errors correctly in nfs41_walk_client_list Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 043/107] nfs4: fix discover_server_trunking use after free Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 044/107] pnfs: Proper delay for NFS4ERR_RECALLCONFLICT in layout_get_done Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 045/107] NFSv4: Fix a slot leak in nfs40_sequence_done Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 046/107] sunrpc: Fix infinite loop in RPC state machine Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 047/107] sunrpc: dont wait for write before allowing reads from use-gss-proxy file Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 048/107] dm thin: fix discard support to a previously shared block Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 049/107] dm thin: initialize dm_thin_new_mapping returned by get_next_mapping Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 050/107] dm thin: fix set_pool_mode exposed pool operation races Greg Kroah-Hartman
2014-02-11 19:05 ` Greg Kroah-Hartman [this message]
2014-02-11 19:05 ` [PATCH 3.12 052/107] dm space map common: make sure new space is used during extend Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 053/107] dm space map metadata: fix extending the space map Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 054/107] dm space map metadata: fix bug in resizing of thin metadata Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 056/107] drm/radeon/dpm: disable mclk switching on desktop RV770 Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 058/107] mei: mei_hbm_dispatch() returns void Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 059/107] percpu_ida: Make percpu_ida_alloc + callers accept task state bitmask Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 060/107] iscsi-target: Fix connection reset hang with percpu_ida_alloc Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 061/107] mm, oom: base root bonus on current usage Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 062/107] media: media: v4l2-dev: fix video device index assignment Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 063/107] media: anysee: fix non-working E30 Combo Plus DVB-T Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 064/107] [media] dib8000: make 32 bits read atomic Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 065/107] [media] media: s5p_mfc: remove s5p_mfc_get_node_type() function Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 066/107] [media] it913x: Add support for Avermedia H335 id 0x0335 Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 067/107] [media] nxt200x: increase write buffer size Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 068/107] [media] dib8000: fix regression with dib807x Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 069/107] [media] m88rs2000: add m88rs2000_set_carrieroffset Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 070/107] [media] m88rs2000: set symbol rate accurately Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 072/107] drm/radeon: disable ss on DP for DCE3.x Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 073/107] drm/radeon: fix surface sync in fence on cayman (v2) Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 074/107] drm/radeon: set the full cache bit for fences on r7xx+ Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 075/107] drm/radeon: add UVD support for OLAND Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 076/107] drm/radeon: fix DAC interrupt handling on DCE5+ Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 077/107] drm/radeon/DCE4+: clear bios scratch dpms bit (v2) Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 078/107] drm/radeon/dce8: workaround for atom BlankCrtc table Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 079/107] dm sysfs: fix a module unload race Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 080/107] drm/nouveau: fix m2mf copy to tiled gart Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 081/107] drm/nouveau/falcon: use vmalloc to create firwmare copies Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 082/107] drm/i915: Flush outstanding requests before allocating new seqno Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 083/107] drm/i915: Fix the offset issue for the stolen GEM objects Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 084/107] drm/i915: VLV2 - Fix hotplug detect bits Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 085/107] i915: remove pm_qos request on error Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 087/107] drm/cirrus: correct register values for 16bpp Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 088/107] drm/gem: Always initialize the gem object in object_init Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 089/107] drm/rcar-du: Update plane pitch in .mode_set_base() operation Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 090/107] drm/gma500: Lock struct_mutex around cursor updates Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 091/107] drm: ast,cirrus,mgag200: use drm_can_sleep Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 092/107] drm/vmwgfx: Fix regression caused by "drm/ttm: make ttm reservation calls behave like reservation calls" Greg Kroah-Hartman
2014-02-11 19:05 ` [PATCH 3.12 093/107] drm/mgag200: fix oops in cursor code Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 094/107] drm/mgag200: fix typo causing bw limits to be ignored on some chips Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 095/107] drm/mgag200,ast,cirrus: fix regression with drm_can_sleep conversion Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 096/107] ftrace: Synchronize setting function_trace_op with ftrace_trace_function Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 097/107] ftrace: Fix synchronization location disabling and freeing ftrace_ops Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 098/107] ftrace: Have function graph only trace based on global_ops filters Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 099/107] timekeeping: Fix lost updates to tai adjustment Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 100/107] timekeeping: Fix potential lost pv notification of time change Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 101/107] timekeeping: Avoid possible deadlock from clock_was_set_delayed Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 102/107] 3.13.y: timekeeping: Fix clock_set/clock_was_set think-o Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 103/107] timekeeping: Fix CLOCK_TAI timer/nanosleep delays Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 104/107] timekeeping: Fix missing timekeeping_update in suspend path Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 105/107] rtc-cmos: Add an alarm disable quirk Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 106/107] mmc: sdhci-pci: Fix BYT sd card getting stuck in runtime suspend Greg Kroah-Hartman
2014-02-11 19:06 ` [PATCH 3.12 107/107] mmc: sdhci-pci: Fix possibility of chip->fixes being null Greg Kroah-Hartman
2014-02-12  4:21 ` [PATCH 3.12 000/107] 3.12.11-stable review Guenter Roeck
2014-02-12 18:49 ` Shuah Khan

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=20140211184749.651719612@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).