* [PATCH] lightnvm: prevent target type module removal when in use
@ 2017-09-08 12:35 Rakesh Pandit
2017-09-08 13:01 ` Matias Bjørling
0 siblings, 1 reply; 2+ messages in thread
From: Rakesh Pandit @ 2017-09-08 12:35 UTC (permalink / raw)
To: linux-block, linux-kernel; +Cc: Matias Bjørling, Javier González
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: Rakesh Pandit <rakesh@tuxera.com>
---
drivers/lightnvm/core.c | 4 ++++
drivers/lightnvm/pblk-init.c | 1 +
include/linux/lightnvm.h | 1 +
3 files changed, 6 insertions(+)
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index bbea2c8..c39f87d 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -22,6 +22,7 @@
#include <linux/types.h>
#include <linux/sem.h>
#include <linux/bitmap.h>
+#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/miscdevice.h>
#include <linux/lightnvm.h>
@@ -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);
mutex_unlock(&dev->mlock);
+ __module_get(tt->owner);
+
return 0;
err_sysfs:
if (tt->exit)
@@ -351,6 +354,7 @@ static void __nvm_remove_target(struct nvm_target *t)
nvm_remove_tgt_dev(t->dev, 1);
put_disk(tdisk);
+ module_put(t->type->owner);
list_del(&t->list);
kfree(t);
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 5fe926b..77d6120 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -1059,6 +1059,7 @@ static struct nvm_tgt_type tt_pblk = {
.sysfs_init = pblk_sysfs_init,
.sysfs_exit = pblk_sysfs_exit,
+ .owner = THIS_MODULE,
};
static int __init pblk_module_init(void)
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 81b71c6d..78a22e0 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -461,6 +461,7 @@ struct nvm_tgt_type {
/* For internal use */
struct list_head list;
+ struct module *owner;
};
extern struct nvm_tgt_type *nvm_find_target_type(const char *, int);
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] lightnvm: prevent target type module removal when in use
2017-09-08 12:35 [PATCH] lightnvm: prevent target type module removal when in use Rakesh Pandit
@ 2017-09-08 13:01 ` Matias Bjørling
0 siblings, 0 replies; 2+ messages in thread
From: Matias Bjørling @ 2017-09-08 13:01 UTC (permalink / raw)
To: Rakesh Pandit, linux-block, linux-kernel; +Cc: Javier González
On 09/08/2017 02:35 PM, Rakesh Pandit wrote:
> 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: Rakesh Pandit <rakesh@tuxera.com>
> ---
> drivers/lightnvm/core.c | 4 ++++
> drivers/lightnvm/pblk-init.c | 1 +
> include/linux/lightnvm.h | 1 +
> 3 files changed, 6 insertions(+)
>
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index bbea2c8..c39f87d 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -22,6 +22,7 @@
> #include <linux/types.h>
> #include <linux/sem.h>
> #include <linux/bitmap.h>
> +#include <linux/module.h>
> #include <linux/moduleparam.h>
> #include <linux/miscdevice.h>
> #include <linux/lightnvm.h>
> @@ -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);
> mutex_unlock(&dev->mlock);
>
> + __module_get(tt->owner);
> +
> return 0;
> err_sysfs:
> if (tt->exit)
> @@ -351,6 +354,7 @@ static void __nvm_remove_target(struct nvm_target *t)
>
> nvm_remove_tgt_dev(t->dev, 1);
> put_disk(tdisk);
> + module_put(t->type->owner);
>
> list_del(&t->list);
> kfree(t);
> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
> index 5fe926b..77d6120 100644
> --- a/drivers/lightnvm/pblk-init.c
> +++ b/drivers/lightnvm/pblk-init.c
> @@ -1059,6 +1059,7 @@ static struct nvm_tgt_type tt_pblk = {
>
> .sysfs_init = pblk_sysfs_init,
> .sysfs_exit = pblk_sysfs_exit,
> + .owner = THIS_MODULE,
> };
>
> static int __init pblk_module_init(void)
> diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
> index 81b71c6d..78a22e0 100644
> --- a/include/linux/lightnvm.h
> +++ b/include/linux/lightnvm.h
> @@ -461,6 +461,7 @@ struct nvm_tgt_type {
>
> /* For internal use */
> struct list_head list;
> + struct module *owner;
> };
>
> extern struct nvm_tgt_type *nvm_find_target_type(const char *, int);
>
Thanks Rakesh. I've picked it up for 4.15.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-08 13:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-08 12:35 [PATCH] lightnvm: prevent target type module removal when in use Rakesh Pandit
2017-09-08 13:01 ` Matias Bjørling
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®