mirror of
https://github.com/torvalds/linux.git
synced 2024-11-14 16:12:02 +00:00
aea9058801
Fix refcount corruption in dm-path-selector Refcounting with non-atomic ops under shared lock will corrupt the counter in multi-processor system and may trigger BUG_ON(). Use module refcount. # same approach as dm-target-use-module-refcount-directly.patch here # https://www.redhat.com/archives/dm-devel/2008-December/msg00075.html Typical oops: kernel BUG at linux-2.6.29-rc3/drivers/md/dm-path-selector.c:90! Pid: 11148, comm: dmsetup Not tainted 2.6.29-rc3-nm #1 dm_put_path_selector+0x4d/0x61 [dm_multipath] Call Trace: [<ffffffffa031d3f9>] free_priority_group+0x33/0xb3 [dm_multipath] [<ffffffffa031d4aa>] free_multipath+0x31/0x67 [dm_multipath] [<ffffffffa031d50d>] multipath_dtr+0x2d/0x32 [dm_multipath] [<ffffffffa015d6c2>] dm_table_destroy+0x64/0xd8 [dm_mod] [<ffffffffa015b73a>] __unbind+0x46/0x4b [dm_mod] [<ffffffffa015b79f>] dm_swap_table+0x60/0x14d [dm_mod] [<ffffffffa015f963>] dev_suspend+0xfd/0x177 [dm_mod] [<ffffffffa0160250>] dm_ctl_ioctl+0x24c/0x29c [dm_mod] [<ffffffff80288cd3>] ? get_page_from_freelist+0x49c/0x61d [<ffffffffa015f866>] ? dev_suspend+0x0/0x177 [dm_mod] [<ffffffff802bf05c>] vfs_ioctl+0x2a/0x77 [<ffffffff802bf4f1>] do_vfs_ioctl+0x448/0x4a0 [<ffffffff802bf5a0>] sys_ioctl+0x57/0x7a [<ffffffff8020c05b>] system_call_fastpath+0x16/0x1b Cc: stable@kernel.org Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
140 lines
2.4 KiB
C
140 lines
2.4 KiB
C
/*
|
|
* Copyright (C) 2003 Sistina Software.
|
|
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* Module Author: Heinz Mauelshagen
|
|
*
|
|
* This file is released under the GPL.
|
|
*
|
|
* Path selector registration.
|
|
*/
|
|
|
|
#include <linux/device-mapper.h>
|
|
|
|
#include "dm-path-selector.h"
|
|
|
|
#include <linux/slab.h>
|
|
|
|
struct ps_internal {
|
|
struct path_selector_type pst;
|
|
struct list_head list;
|
|
};
|
|
|
|
#define pst_to_psi(__pst) container_of((__pst), struct ps_internal, pst)
|
|
|
|
static LIST_HEAD(_path_selectors);
|
|
static DECLARE_RWSEM(_ps_lock);
|
|
|
|
static struct ps_internal *__find_path_selector_type(const char *name)
|
|
{
|
|
struct ps_internal *psi;
|
|
|
|
list_for_each_entry(psi, &_path_selectors, list) {
|
|
if (!strcmp(name, psi->pst.name))
|
|
return psi;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static struct ps_internal *get_path_selector(const char *name)
|
|
{
|
|
struct ps_internal *psi;
|
|
|
|
down_read(&_ps_lock);
|
|
psi = __find_path_selector_type(name);
|
|
if (psi && !try_module_get(psi->pst.module))
|
|
psi = NULL;
|
|
up_read(&_ps_lock);
|
|
|
|
return psi;
|
|
}
|
|
|
|
struct path_selector_type *dm_get_path_selector(const char *name)
|
|
{
|
|
struct ps_internal *psi;
|
|
|
|
if (!name)
|
|
return NULL;
|
|
|
|
psi = get_path_selector(name);
|
|
if (!psi) {
|
|
request_module("dm-%s", name);
|
|
psi = get_path_selector(name);
|
|
}
|
|
|
|
return psi ? &psi->pst : NULL;
|
|
}
|
|
|
|
void dm_put_path_selector(struct path_selector_type *pst)
|
|
{
|
|
struct ps_internal *psi;
|
|
|
|
if (!pst)
|
|
return;
|
|
|
|
down_read(&_ps_lock);
|
|
psi = __find_path_selector_type(pst->name);
|
|
if (!psi)
|
|
goto out;
|
|
|
|
module_put(psi->pst.module);
|
|
out:
|
|
up_read(&_ps_lock);
|
|
}
|
|
|
|
static struct ps_internal *_alloc_path_selector(struct path_selector_type *pst)
|
|
{
|
|
struct ps_internal *psi = kzalloc(sizeof(*psi), GFP_KERNEL);
|
|
|
|
if (psi)
|
|
psi->pst = *pst;
|
|
|
|
return psi;
|
|
}
|
|
|
|
int dm_register_path_selector(struct path_selector_type *pst)
|
|
{
|
|
int r = 0;
|
|
struct ps_internal *psi = _alloc_path_selector(pst);
|
|
|
|
if (!psi)
|
|
return -ENOMEM;
|
|
|
|
down_write(&_ps_lock);
|
|
|
|
if (__find_path_selector_type(pst->name)) {
|
|
kfree(psi);
|
|
r = -EEXIST;
|
|
} else
|
|
list_add(&psi->list, &_path_selectors);
|
|
|
|
up_write(&_ps_lock);
|
|
|
|
return r;
|
|
}
|
|
|
|
int dm_unregister_path_selector(struct path_selector_type *pst)
|
|
{
|
|
struct ps_internal *psi;
|
|
|
|
down_write(&_ps_lock);
|
|
|
|
psi = __find_path_selector_type(pst->name);
|
|
if (!psi) {
|
|
up_write(&_ps_lock);
|
|
return -EINVAL;
|
|
}
|
|
|
|
list_del(&psi->list);
|
|
|
|
up_write(&_ps_lock);
|
|
|
|
kfree(psi);
|
|
|
|
return 0;
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_register_path_selector);
|
|
EXPORT_SYMBOL_GPL(dm_unregister_path_selector);
|