diff mbox series

[2/6] null_blk: check for valid poll_queue value

Message ID 20221007063036.13428-3-kch@nvidia.com (mailing list archive)
State New, archived
Headers show
Series null_blk: add modparam vefication | expand

Commit Message

Chaitanya Kulkarni Oct. 7, 2022, 6:30 a.m. UTC
Right now we don't check for valid module parameter value for
poll_queue, that allows user to set negative values.

Add a callback to error out when poll_queue value is set < 1 before
module is loaded.

This fixes OOPs with invalid poll_queue value of -2 :-

Entering kdb (current=0xffff88817eaed100, pid 5624) on processor 12 Oops: (null)
due to oops @ 0xffffffff8165093f
CPU: 12 PID: 5624 Comm: modprobe Tainted: G           OE      6.0.0-rc7blk+ #53
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
RIP: 0010:blk_mq_alloc_tag_set+0x14f/0x380
Code: 83 c5 01 3b 6b 40 0f 83 9a 01 00 00 48 8b 43 68 4c 63 e5 4e 8d 34 e0 f6 43 58 08 75 d7 8b 53 44 89 ee 48 89 df e8 d1 ed ff ff <49> 89 06 48 8b 43 68 4a 83 3c e0 00 75 c3 83 ed 01 78 0f 89 ee 48
RSP: 0018:ffffc90002eefd70 EFLAGS: 00010282
RAX: ffff888112b155c0 RBX: ffff88811069dc38 RCX: 0000000000000003
RDX: ffff88811069d000 RSI: ffff88810ed60000 RDI: 00000000000001f8
RBP: 0000000000000000 R08: 0000000000000003 R09: ffff888112b15650
R10: 000000000010ed60 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000040 R14: 0000000000000000 R15: 0000000000000000
FS:  00007f71e4147b80(0000) GS:ffff888fff500000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000014d81c000 CR4: 0000000000350ee0
Call Trace:
 <TASK>
 null_add_dev+0x7a7/0x870 [null_blk]
 null_init+0x1de/0x1000 [null_blk]
 ? 0xffffffffc03a9000
 do_one_initcall+0x44/0x210
 ? kmem_cache_alloc_trace+0x15b/0x2b0
 do_init_module+0x4c/0x1f0
 __do_sys_finit_module+0xb4/0x130
 do_syscall_64+0x3b/0x90
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f71e426e15d
Code: c5 0c 00 0f 05 eb a9 66 0f 1f 44 00 00 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d e3 7c 0c 00 f7 d8 64 89 01 48
RSP: 002b:00007fffb29f27a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
RAX: ffffffffffffffda RBX: 0000564b29d78b90 RCX: 00007f71e426e15d
RDX: 0000000000000000 RSI: 0000564b29d78f00 RDI: 0000000000000003
RBP: 0000000000040000 R08: 0000000000000000 R09: 0000000000000020
R10: 0000000000000003 R11: 0000000000000246 R12: 0000564b29d78f00
R13: 0000564b29d78cc0 R14: 0000564b29d78b90 R15: 0000564b29d78f20
 </TASK>

[12]kdb>

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index c8dbff120c65..29e43444cf66 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -114,7 +114,18 @@  device_param_cb(submit_queues, &null_submit_queues_param_ops, &g_submit_queues,
 MODULE_PARM_DESC(submit_queues, "Number of submission queues");
 
 static int g_poll_queues = 1;
-module_param_named(poll_queues, g_poll_queues, int, 0444);
+
+static int null_set_poll_queues(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_poll_queues, 1, INT_MAX);
+}
+
+static const struct kernel_param_ops null_poll_queues_param_ops = {
+	.set	= null_set_poll_queues,
+	.get	= param_get_int,
+};
+
+device_param_cb(poll_queues, &null_poll_queues_param_ops, &g_poll_queues, 0444);
 MODULE_PARM_DESC(poll_queues, "Number of IOPOLL submission queues");
 
 static int g_home_node = NUMA_NO_NODE;