[PATCH 2/4] nvme-pci: don't use ctrl page size value in probe
Chaitanya Kulkarni
chaitanya.kulkarni at wdc.com
Tue Jul 7 20:58:29 EDT 2020
In nvme_probe() when calculating mempool size nvme_npages uses
dev->ctrl.page_size which is initialized in the following code path:-
Ctx insmod :
nvme_probe()
nvme_reset_ctrl()
queue_work(nvme_reset_work()
Ctx Workqueue :
nvme_reset_work()
nvme_pci_configure_admin_queue()
nvme_enable_ctrl()
ctrl->page_size = 1 << NVME_CTRL_PAGE_SHIFT.
When nvme_pci_iod_alloc_size() is called with false as last argument it
results in following oops since dev->ctrl.page_size used before we set
it in the nvme_enable_ctrl() in above path :-
Entering kdb (current=0xffff88881fc0c980, pid 339) on processor 0 Oops: (null)
due to oops @ 0xffffffffa05f1723
CPU: 0 PID: 339 Comm: kworker/0:2 Tainted: G W OE 5.8.0-rc1nvme-5.9+ #20
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.0-59-gc9ba5276e321-prebuilt.qemu.4
Workqueue: events work_for_cpu_fn
RIP: 0010:nvme_probe+0x263/0x502 [nvme]
Code: 00 00 66 41 81 7c 24 3c 4d 14 0f 84 98 01 00 00 3d 0f 1e 01 00 0f 84 aa 01 00 00 8b 8b a0 0c 00 2
RSP: 0018:ffffc90000d9bdd8 EFLAGS: 00010246
RAX: 0000000000000fff RBX: ffff8887da128000 RCX: 0000000000000000
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000246
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: ffff8887c29f5570 R12: ffff888813c37000
R13: 0000000000000202 R14: 0000000fffffffe0 R15: ffff888813c370b0
FS: 0000000000000000(0000) GS:ffff88880fe00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f23185131a0 CR3: 0000000811c54000 CR4: 00000000003406f0
Call Trace:
local_pci_probe+0x42/0x80
work_for_cpu_fn+0x16/0x20
process_one_work+0x24e/0x5a0
? __schedule+0x353/0x840
worker_thread+0x1d5/0x380
? process_one_work+0x5a0/0x5a0
kthread+0x135/0x150
? kthread_create_on_node+0x60/0x60
ret_from_fork+0x22/0x30
This patch uses local variable instead of dev->ctrl.page_size with the
same value which we set in the nvme_enable_ctrl().
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
drivers/nvme/host/pci.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 1ac0717c04d3..cef87ad2323f 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -348,8 +348,15 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, u32 *dbbuf_db,
*/
static int nvme_npages(unsigned size, struct nvme_dev *dev)
{
- unsigned nprps = DIV_ROUND_UP(size + dev->ctrl.page_size,
- dev->ctrl.page_size);
+ /*
+ * At this point ctrl->page_size is not initialized. Use same the
+ * values present in nvme_enable_ctrl() ctrl->page_size. Any change in
+ * the value of ctrl->page_size in nvme_enable_ctrl() should reflect
+ * here.
+ */
+ unsigned int page_size = 1 << NVME_CTRL_PAGE_SHIFT;
+ unsigned nprps = DIV_ROUND_UP(size + page_size, page_size);
+
return DIV_ROUND_UP(8 * nprps, PAGE_SIZE - 8);
}
--
2.26.0
More information about the Linux-nvme
mailing list