* [PATCH V3 0/3] nvme: fix module ref count Oops
@ 2020-09-17 1:10 Chaitanya Kulkarni
2020-09-17 1:11 ` [PATCH V3 1/3] nvme-core: get/put ctrl in nvme_dev_open/release() Chaitanya Kulkarni
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2020-09-17 1:10 UTC (permalink / raw)
To: linux-nvme; +Cc: logang, hch, Chaitanya Kulkarni, sagi
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 1664 bytes --]
Hi,
I found the module ref count patch in the git without the ctrl get/put in
the nvme_dev_open/nvme_dev_release() with latest pull.
commit dfa76f46dad568ed81368c3cb810d95f820debc5 (origin/nvme-5.9)
Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Date: Tue Sep 15 20:53:25 2020 -0700
nvme-core: fix nvme module ref count Oops
In this series, the first patch which adds the ctrl get/put in
nvme_dev_open/release() which can be folded onto the git HEAD on
nvme-5.9 or applied separately deesn't matter.
The last two patches are Christoph's suggestion added on the top
host-core module count fix to decouple :-
a. code for modue_get/put() in the passthru.
b. lifting the file opening from the nvme-core.
Regards,
Chaitanya
Changes from V2:-
1. Add a patch to get/put ctrl reference in the nvme_dev_open/release().
2. Use Chritoph's suggestion to split the 2nd patch from V2 into :-
a. module_get/put() in passthru enable/disable path.
b. lifting the file open/close code from host/core for char device.
3. Update patch subject.
Changes from V1: -
1. Move last patch to get the module refcount to start of the series.
2. De-couple the module refcount get/put from nvme_dev_open() and
nvme_dev_release().
Chaitanya Kulkarni (3):
nvme-core: get/put ctrl in nvme_dev_open/release()
nvmet: get transport reference for passthru ctrl
nvme: lift file open code from nvme_ctrl_get_by_path
drivers/nvme/host/core.c | 27 +++++++--------------------
drivers/nvme/host/nvme.h | 2 +-
drivers/nvme/target/passthru.c | 29 ++++++++++++++++++-----------
3 files changed, 26 insertions(+), 32 deletions(-)
--
2.22.1
[-- Attachment #2: Type: text/plain, Size: 158 bytes --]
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH V3 1/3] nvme-core: get/put ctrl in nvme_dev_open/release()
2020-09-17 1:10 [PATCH V3 0/3] nvme: fix module ref count Oops Chaitanya Kulkarni
@ 2020-09-17 1:11 ` Chaitanya Kulkarni
2020-09-17 8:42 ` Christoph Hellwig
2020-09-17 1:11 ` [PATCH V3 2/3] nvmet: get transport reference for passthru ctrl Chaitanya Kulkarni
2020-09-17 1:11 ` [PATCH V3 3/3] nvme: lift file open code from nvme_ctrl_get_by_path Chaitanya Kulkarni
2 siblings, 1 reply; 7+ messages in thread
From: Chaitanya Kulkarni @ 2020-09-17 1:11 UTC (permalink / raw)
To: linux-nvme; +Cc: logang, hch, Chaitanya Kulkarni, sagi
Get and put the reference to the ctrl in the nvme_dev_open() and
nvme_dev_release() before and after module get/put for ctrl in char
device file operations.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/nvme/host/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index c5f9d64b2bec..c013eb52fdc8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3261,6 +3261,7 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
return -EWOULDBLOCK;
}
+ nvme_get_ctrl(ctrl);
if (!try_module_get(ctrl->ops->module))
return -EINVAL;
@@ -3274,6 +3275,7 @@ static int nvme_dev_release(struct inode *inode, struct file *file)
container_of(inode->i_cdev, struct nvme_ctrl, cdev);
module_put(ctrl->ops->module);
+ nvme_put_ctrl(ctrl);
return 0;
}
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH V3 2/3] nvmet: get transport reference for passthru ctrl
2020-09-17 1:10 [PATCH V3 0/3] nvme: fix module ref count Oops Chaitanya Kulkarni
2020-09-17 1:11 ` [PATCH V3 1/3] nvme-core: get/put ctrl in nvme_dev_open/release() Chaitanya Kulkarni
@ 2020-09-17 1:11 ` Chaitanya Kulkarni
2020-09-17 8:42 ` Christoph Hellwig
2020-09-17 1:11 ` [PATCH V3 3/3] nvme: lift file open code from nvme_ctrl_get_by_path Chaitanya Kulkarni
2 siblings, 1 reply; 7+ messages in thread
From: Chaitanya Kulkarni @ 2020-09-17 1:11 UTC (permalink / raw)
To: linux-nvme; +Cc: logang, hch, Chaitanya Kulkarni, sagi
From: Christoph Hellwig <hch@lst.de>
Grab a reference to the transport driver to ensure it can't be unloaded
while a passthrough controller is active.
Fixes: c1fef73f793b ("nvmet: add passthru code to process commands")
Reported-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
---
drivers/nvme/target/passthru.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index 8bd7f656e240..dacfa7435d0b 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -517,6 +517,7 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
subsys->ver = NVME_VS(1, 2, 1);
}
+ __module_get(subsys->passthru_ctrl->ops->module);
mutex_unlock(&subsys->lock);
return 0;
@@ -531,6 +532,7 @@ static void __nvmet_passthru_ctrl_disable(struct nvmet_subsys *subsys)
{
if (subsys->passthru_ctrl) {
xa_erase(&passthru_subsystems, subsys->passthru_ctrl->cntlid);
+ module_put(subsys->passthru_ctrl->ops->module);
nvme_put_ctrl(subsys->passthru_ctrl);
}
subsys->passthru_ctrl = NULL;
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH V3 3/3] nvme: lift file open code from nvme_ctrl_get_by_path
2020-09-17 1:10 [PATCH V3 0/3] nvme: fix module ref count Oops Chaitanya Kulkarni
2020-09-17 1:11 ` [PATCH V3 1/3] nvme-core: get/put ctrl in nvme_dev_open/release() Chaitanya Kulkarni
2020-09-17 1:11 ` [PATCH V3 2/3] nvmet: get transport reference for passthru ctrl Chaitanya Kulkarni
@ 2020-09-17 1:11 ` Chaitanya Kulkarni
2020-09-17 8:42 ` Christoph Hellwig
2 siblings, 1 reply; 7+ messages in thread
From: Chaitanya Kulkarni @ 2020-09-17 1:11 UTC (permalink / raw)
To: linux-nvme; +Cc: logang, hch, Chaitanya Kulkarni, sagi
Lift opening the file open/close code from nvme_ctrl_get_by_path into
the caller, just keeping a simple nvme_ctrl_from_file() helper.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
[hch: refactored a bit, split the bug fixes into a separate prep patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
---
drivers/nvme/host/core.c | 25 +++++--------------------
drivers/nvme/host/nvme.h | 2 +-
drivers/nvme/target/passthru.c | 27 ++++++++++++++++-----------
3 files changed, 22 insertions(+), 32 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index c013eb52fdc8..9beb9c94eeef 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4651,28 +4651,13 @@ void nvme_sync_queues(struct nvme_ctrl *ctrl)
}
EXPORT_SYMBOL_GPL(nvme_sync_queues);
-struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path)
+struct nvme_ctrl *nvme_ctrl_from_file(struct file *file)
{
- struct nvme_ctrl *ctrl;
- struct file *f;
-
- f = filp_open(path, O_RDWR, 0);
- if (IS_ERR(f))
- return ERR_CAST(f);
-
- if (f->f_op != &nvme_dev_fops) {
- ctrl = ERR_PTR(-EINVAL);
- goto out_close;
- }
-
- ctrl = f->private_data;
- nvme_get_ctrl(ctrl);
-
-out_close:
- filp_close(f, NULL);
- return ctrl;
+ if (file->f_op != &nvme_dev_fops)
+ return NULL;
+ return file->private_data;
}
-EXPORT_SYMBOL_NS_GPL(nvme_ctrl_get_by_path, NVME_TARGET_PASSTHRU);
+EXPORT_SYMBOL_NS_GPL(nvme_ctrl_from_file, NVME_TARGET_PASSTHRU);
/*
* Check we didn't inadvertently grow the command structure sizes:
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 9fd45ff656da..1e6aaa710262 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -835,7 +835,7 @@ static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { }
u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
u8 opcode);
void nvme_execute_passthru_rq(struct request *rq);
-struct nvme_ctrl *nvme_ctrl_get_by_path(const char *path);
+struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid);
void nvme_put_ns(struct nvme_ns *ns);
diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index dacfa7435d0b..e3a5f8499a0b 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -474,6 +474,7 @@ u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req)
int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
{
struct nvme_ctrl *ctrl;
+ struct file *file;
int ret = -EINVAL;
void *old;
@@ -488,24 +489,29 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
goto out_unlock;
}
- ctrl = nvme_ctrl_get_by_path(subsys->passthru_ctrl_path);
- if (IS_ERR(ctrl)) {
- ret = PTR_ERR(ctrl);
+ file = filp_open(subsys->passthru_ctrl_path, O_RDWR, 0);
+ if (IS_ERR(file)) {
+ ret = PTR_ERR(file);
+ goto out_unlock;
+ }
+
+ ctrl = nvme_ctrl_from_file(file);
+ if (!ctrl) {
pr_err("failed to open nvme controller %s\n",
subsys->passthru_ctrl_path);
- goto out_unlock;
+ goto out_put_file;
}
old = xa_cmpxchg(&passthru_subsystems, ctrl->cntlid, NULL,
subsys, GFP_KERNEL);
if (xa_is_err(old)) {
ret = xa_err(old);
- goto out_put_ctrl;
+ goto out_put_file;
}
if (old)
- goto out_put_ctrl;
+ goto out_put_file;
subsys->passthru_ctrl = ctrl;
subsys->ver = ctrl->vs;
@@ -516,13 +522,12 @@ int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys)
NVME_TERTIARY(subsys->ver));
subsys->ver = NVME_VS(1, 2, 1);
}
-
+ nvme_get_ctrl(ctrl);
__module_get(subsys->passthru_ctrl->ops->module);
- mutex_unlock(&subsys->lock);
- return 0;
+ ret = 0;
-out_put_ctrl:
- nvme_put_ctrl(ctrl);
+out_put_file:
+ filp_close(file, NULL);
out_unlock:
mutex_unlock(&subsys->lock);
return ret;
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V3 1/3] nvme-core: get/put ctrl in nvme_dev_open/release()
2020-09-17 1:11 ` [PATCH V3 1/3] nvme-core: get/put ctrl in nvme_dev_open/release() Chaitanya Kulkarni
@ 2020-09-17 8:42 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-09-17 8:42 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: logang, hch, linux-nvme, sagi
I've folded this into the previous module_get patch, and re-applied the
result to nvme-5.9.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V3 2/3] nvmet: get transport reference for passthru ctrl
2020-09-17 1:11 ` [PATCH V3 2/3] nvmet: get transport reference for passthru ctrl Chaitanya Kulkarni
@ 2020-09-17 8:42 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-09-17 8:42 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: logang, hch, linux-nvme, sagi
On Wed, Sep 16, 2020 at 06:11:01PM -0700, Chaitanya Kulkarni wrote:
> From: Christoph Hellwig <hch@lst.de>
>
> Grab a reference to the transport driver to ensure it can't be unloaded
> while a passthrough controller is active.
Applied to nvme-5.9.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V3 3/3] nvme: lift file open code from nvme_ctrl_get_by_path
2020-09-17 1:11 ` [PATCH V3 3/3] nvme: lift file open code from nvme_ctrl_get_by_path Chaitanya Kulkarni
@ 2020-09-17 8:42 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-09-17 8:42 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: logang, hch, linux-nvme, sagi
On Wed, Sep 16, 2020 at 06:11:02PM -0700, Chaitanya Kulkarni wrote:
> Lift opening the file open/close code from nvme_ctrl_get_by_path into
> the caller, just keeping a simple nvme_ctrl_from_file() helper.
And I've applied this one to nvme-5.10 as a pure cleanup.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-09-17 8:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 1:10 [PATCH V3 0/3] nvme: fix module ref count Oops Chaitanya Kulkarni
2020-09-17 1:11 ` [PATCH V3 1/3] nvme-core: get/put ctrl in nvme_dev_open/release() Chaitanya Kulkarni
2020-09-17 8:42 ` Christoph Hellwig
2020-09-17 1:11 ` [PATCH V3 2/3] nvmet: get transport reference for passthru ctrl Chaitanya Kulkarni
2020-09-17 8:42 ` Christoph Hellwig
2020-09-17 1:11 ` [PATCH V3 3/3] nvme: lift file open code from nvme_ctrl_get_by_path Chaitanya Kulkarni
2020-09-17 8:42 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.