All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
To: linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, logang@deltatee.com, hch@lst.de,
	Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>,
	sagi@grimberg.me
Subject: [PATCH V2 09/12] nvmet: fix nvme module ref count Oops
Date: Mon, 31 Aug 2020 15:27:04 -0700	[thread overview]
Message-ID: <20200831222707.35611-10-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20200831222707.35611-1-chaitanya.kulkarni@wdc.com>

In the passthru controller enable path current code doesn't take the
reference to the passthru ctrl module. Which produces following Oops :-

Entering kdb (current=0xffff8887f8290000, pid 3128) on processor 30 Oops: (null)
due to oops @ 0xffffffffa01019ad
CPU: 30 PID: 3128 Comm: bash Tainted: G        W  OE     5.8.0-rc4nvme-5.9+ #35
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-59-gc9ba5276e321-prebuilt.qemu.4
RIP: 0010:nvme_free_ctrl+0x234/0x285 [nvme_core]
Code: 57 10 a0 e8 73 bf 02 e1 ba 3d 11 00 00 48 c7 c6 98 33 10 a0 48 c7 c7 1d 57 10 a0 e8 5b bf 02 e1 8
RSP: 0018:ffffc90001d63de0 EFLAGS: 00010246
RAX: ffffffffa05c0440 RBX: ffff8888119e45a0 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffff8888177e9550 RDI: ffff8888119e43b0
RBP: ffff8887d4768000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: ffffc90001d63c90 R12: ffff8888119e43b0
R13: ffff8888119e5108 R14: dead000000000100 R15: ffff8888119e5108
FS:  00007f1ef27b0740(0000) GS:ffff888817600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffa05c0470 CR3: 00000007f6bee000 CR4: 00000000003406e0
Call Trace:
 device_release+0x27/0x80
 kobject_put+0x98/0x170
 nvmet_passthru_ctrl_disable+0x4a/0x70 [nvmet]
 nvmet_passthru_enable_store+0x4c/0x90 [nvmet]
 configfs_write_file+0xe6/0x150
 vfs_write+0xba/0x1e0
 ksys_write+0x5f/0xe0
 do_syscall_64+0x52/0xb0
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f1ef1eb2840
Code: Bad RIP value.
RSP: 002b:00007fffdbff0eb8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007f1ef1eb2840
RDX: 0000000000000002 RSI: 00007f1ef27d2000 RDI: 0000000000000001
RBP: 00007f1ef27d2000 R08: 000000000000000a R09: 00007f1ef27b0740
R10: 0000000000000001 R11: 0000000000000246 R12: 00007f1ef2186400
R13: 0000000000000002 R14: 0000000000000001 R15: 0000000000000000

We fix that by taking a module ref count in nvme_dev_open() and release
that ref count in nvme_dev_release().

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/host/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f82c6a283b15..c940f49a30bf 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3263,6 +3263,12 @@ static int nvme_dev_open(struct inode *inode, struct file *file)
 
 	file->private_data = ctrl;
 	nvme_get_ctrl(ctrl);
+	if (!try_module_get(ctrl->ops->module)) {
+		pr_err("try_module_get failed for cntlid 0x%x\n", ctrl->cntlid);
+		nvme_put_ctrl(ctrl);
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
@@ -3271,6 +3277,7 @@ static int nvme_dev_release(struct inode *inode, struct file *file)
 	struct nvme_ctrl *ctrl =
 		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

  parent reply	other threads:[~2020-08-31 22:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 22:26 [PATCH V2 00/12] nvmet: passthru fixes and improvements Chaitanya Kulkarni
2020-08-31 22:26 ` [PATCH V2 01/12] nvme-core: annotate nvme_alloc_request() Chaitanya Kulkarni
2020-09-01  1:56   ` Baolin Wang
2020-09-01 17:21     ` Sagi Grimberg
2020-09-01 21:16       ` Chaitanya Kulkarni
2020-09-02  3:28       ` Chaitanya Kulkarni
2020-09-02 22:02       ` Chaitanya Kulkarni
2020-09-03 16:17   ` Christoph Hellwig
2020-09-03 19:40     ` Chaitanya Kulkarni
2020-09-08  8:57       ` Christoph Hellwig
2020-08-31 22:26 ` [PATCH V2 02/12] nvmet: for pt I/O commands use likely for ns check Chaitanya Kulkarni
2020-09-03 16:18   ` Christoph Hellwig
2020-09-03 18:21     ` Chaitanya Kulkarni
2020-08-31 22:26 ` [PATCH V2 03/12] nvmet: use consistent type with id->nlbaf Chaitanya Kulkarni
2020-09-01 15:55   ` Keith Busch
2020-09-01 21:17     ` Chaitanya Kulkarni
2020-09-01 21:31       ` Logan Gunthorpe
2020-09-01 22:03       ` Keith Busch
2020-08-31 22:26 ` [PATCH V2 04/12] nvmet: use consistent type for op_flag Chaitanya Kulkarni
2020-09-03 16:20   ` Christoph Hellwig
2020-09-03 18:35     ` Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 05/12] nvmet: use unlikely for uncommon commands Chaitanya Kulkarni
2020-09-03 16:20   ` Christoph Hellwig
2020-09-03 18:37     ` Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 06/12] nvmet: remove op_flags for write commands Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 07/12] nvmet: decouple nvme_ctrl_get_by_path() Chaitanya Kulkarni
2020-09-01 17:00   ` Logan Gunthorpe
2020-08-31 22:27 ` [PATCH V2 08/12] nvmet: move get/put ctrl into dev open/release Chaitanya Kulkarni
2020-09-01 17:02   ` Logan Gunthorpe
2020-09-01 17:18     ` Sagi Grimberg
2020-09-02  0:31       ` Chaitanya Kulkarni
2020-09-03 16:21       ` Christoph Hellwig
2020-09-03 18:22         ` Chaitanya Kulkarni
2020-08-31 22:27 ` Chaitanya Kulkarni [this message]
2020-09-01 17:23   ` [PATCH V2 09/12] nvmet: fix nvme module ref count Oops Logan Gunthorpe
2020-08-31 22:27 ` [PATCH V2 10/12] block: move blk_rq_bio_prep() to linux/blk-mq.h Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 11/12] nvmet: use minimized version of blk_rq_append_bio Chaitanya Kulkarni
2020-09-03 16:23   ` Christoph Hellwig
2020-09-03 18:23     ` Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 12/12] nvmet: use inline bio for passthru fast path Chaitanya Kulkarni
2020-09-01 17:29   ` Logan Gunthorpe
2020-09-02  0:39     ` Chaitanya Kulkarni
2020-09-02 15:41       ` Logan Gunthorpe
2020-09-02 21:04         ` Chaitanya Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200831222707.35611-10-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=logang@deltatee.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.