dm sysfs: fix a module unload race
authorMikulas Patocka <mpatocka@redhat.com>
Tue, 14 Jan 2014 00:37:54 +0000 (19:37 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Feb 2014 21:50:22 +0000 (13:50 -0800)
commit1a46dbe17b9771a38d702143d7e03b86e4377f7e
tree71f0749d681ec18e1ebd6082889b9353554f14b8
parentaecead3a1e5cf7698854f1c47e725e808212de61
dm sysfs: fix a module unload race

commit 2995fa78e423d7193f3b57835f6c1c75006a0315 upstream.

This reverts commit be35f48610 ("dm: wait until embedded kobject is
released before destroying a device") and provides an improved fix.

The kobject release code that calls the completion must be placed in a
non-module file, otherwise there is a module unload race (if the process
calling dm_kobject_release is preempted and the DM module unloaded after
the completion is triggered, but before dm_kobject_release returns).

To fix this race, this patch moves the completion code to dm-builtin.c
which is always compiled directly into the kernel if BLK_DEV_DM is
selected.

The patch introduces a new dm_kobject_holder structure, its purpose is
to keep the completion and kobject in one place, so that it can be
accessed from non-module code without the need to export the layout of
struct mapped_device to that code.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/Kconfig
drivers/md/Makefile
drivers/md/dm-builtin.c [new file with mode: 0644]
drivers/md/dm-sysfs.c
drivers/md/dm.c
drivers/md/dm.h