Commit 90014829 authored by Rakesh Pandit's avatar Rakesh Pandit Committed by Jens Axboe

lightnvm: prevent target type module removal when in use

If target type module e.g. pblk here is unloaded (rmmod) while module
is in use (after creating target) system crashes.  We fix this by
using module API refcnt.
Signed-off-by: default avatarRakesh Pandit <rakesh@tuxera.com>
Signed-off-by: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 47bc227d
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/sem.h> #include <linux/sem.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/lightnvm.h> #include <linux/lightnvm.h>
...@@ -316,6 +317,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) ...@@ -316,6 +317,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
list_add_tail(&t->list, &dev->targets); list_add_tail(&t->list, &dev->targets);
mutex_unlock(&dev->mlock); mutex_unlock(&dev->mlock);
__module_get(tt->owner);
return 0; return 0;
err_sysfs: err_sysfs:
if (tt->exit) if (tt->exit)
...@@ -351,6 +354,7 @@ static void __nvm_remove_target(struct nvm_target *t) ...@@ -351,6 +354,7 @@ static void __nvm_remove_target(struct nvm_target *t)
nvm_remove_tgt_dev(t->dev, 1); nvm_remove_tgt_dev(t->dev, 1);
put_disk(tdisk); put_disk(tdisk);
module_put(t->type->owner);
list_del(&t->list); list_del(&t->list);
kfree(t); kfree(t);
......
...@@ -1044,6 +1044,7 @@ static struct nvm_tgt_type tt_pblk = { ...@@ -1044,6 +1044,7 @@ static struct nvm_tgt_type tt_pblk = {
.sysfs_init = pblk_sysfs_init, .sysfs_init = pblk_sysfs_init,
.sysfs_exit = pblk_sysfs_exit, .sysfs_exit = pblk_sysfs_exit,
.owner = THIS_MODULE,
}; };
static int __init pblk_module_init(void) static int __init pblk_module_init(void)
......
...@@ -460,6 +460,7 @@ struct nvm_tgt_type { ...@@ -460,6 +460,7 @@ struct nvm_tgt_type {
/* For internal use */ /* For internal use */
struct list_head list; struct list_head list;
struct module *owner;
}; };
extern struct nvm_tgt_type *nvm_find_target_type(const char *, int); extern struct nvm_tgt_type *nvm_find_target_type(const char *, int);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment