[PATCH V2 3/9] null_blk: check for valid poll_queue value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 following message with invalid poll_queues value set more
than num_online_cpus():

$echo $(nproc)
48
$ for i in `seq 45 49`; do
          modprobe -r null_blk
          modprobe null_blk poll_queues=$i
          echo "poll_queues = $i"
          dmesg -c
  done
poll_queues = 45
 blk_queue_max_hw_sectors: set to minimum 8
 null_blk: disk nullb0 created
 null_blk: module loaded
 blk_queue_max_hw_sectors: set to minimum 8
 null_blk: disk nullb0 created
 null_blk: module loaded
46
 blk_queue_max_hw_sectors: set to minimum 8
 null_blk: disk nullb0 created
 null_blk: module loaded
47
 blk_queue_max_hw_sectors: set to minimum 8
 null_blk: disk nullb0 created
 null_blk: module loaded
48
 blk_queue_max_hw_sectors: set to minimum 8
 null_blk: disk nullb0 created
 null_blk: module loaded
49
 ------------[ cut here ]------------
 WARNING: CPU: 23 PID: 36379 at lib/group_cpus.c:400 group_cpus_evenly+0x26e/0x280
 CPU: 23 PID: 36379 Comm: modprobe Tainted: G        W  O     N 6.3.0-rc1lblk+ #2
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
 RIP: 0010:group_cpus_evenly+0x26e/0x280
 Code: b1 ff 48 8b 7c 24 08 e8 20 d1 5d 00 48 8b 3c 24 e8 17 d1 5d 00 45 85 ed 0f 89 01 fe ff ff e9 f1 fd ff ff e8 b4 9d 8d ff eb ac <0f> 0b eb a8 e8 39 c4 60 00 41 bd f4 ff ff ff eb 9b cc 90 90 90 90
 RSP: 0018:ffffc90000723cb8 EFLAGS: 00010297
 RAX: 0000000080000000 RBX: 0000000000000031 RCX: 0000000000000000
 RDX: 0000000000000001 RSI: 0000000000000030 RDI: 00000000ffffffff
 RBP: ffff88884b2204f0 R08: ffff88884b220bd8 R09: ffff8888c31f0000
 R10: ffff88884b220bd8 R11: 0000000000000000 R12: ffff8888c31f0000
 R13: 0000000000000000 R14: 0000000000000030 R15: 0000000000000000
 FS:  00007f5ff6be8b80(0000) GS:ffff888fff7c0000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 00007f5ff6706800 CR3: 0000000849554000 CR4: 0000000000350ee0
 DR0: ffffffff843793e0 DR1: ffffffff843793e1 DR2: ffffffff843793e2
 DR3: ffffffff843793e3 DR6: 00000000ffff0ff0 DR7: 0000000000000600
 Call Trace:
  <TASK>
  blk_mq_map_queues+0x16/0xc0
  null_map_queues+0xa5/0xe0 [null_blk]
  blk_mq_alloc_tag_set+0x14d/0x3f0
  ? __kmalloc+0xbc/0x130
  null_add_dev.part.0+0x601/0x700 [null_blk]
  null_init+0x109/0xff0 [null_blk]
  ? __pfx_init_module+0x10/0x10 [null_blk]
  do_one_initcall+0x44/0x220
  ? kmalloc_trace+0x25/0x90
  do_init_module+0x4c/0x210
  __do_sys_finit_module+0xb4/0x130
  do_syscall_64+0x3b/0x90
  entry_SYSCALL_64_after_hwframe+0x72/0xdc
 RIP: 0033:0x7f5ff672c15d
 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:00007ffd32ca3148 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
 RAX: ffffffffffffffda RBX: 000056096285db90 RCX: 00007f5ff672c15d
 RDX: 0000000000000000 RSI: 000056096285df00 RDI: 0000000000000003
 RBP: 0000000000040000 R08: 0000000000000000 R09: 0000000000000020
 R10: 0000000000000003 R11: 0000000000000246 R12: 000056096285df00
 R13: 000056096285dcc0 R14: 000056096285db90 R15: 000056096285df20
  </TASK>
 ---[ end trace 0000000000000000 ]---
 blk_queue_max_hw_sectors: set to minimum 8
 null_blk: disk nullb0 created
 null_blk: module loaded

Signed-off-by: Chaitanya Kulkarni <kch@xxxxxxxxxx>
---
 drivers/block/null_blk/main.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 9e3df92d0b98..29bc4b5720c1 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -114,8 +114,24 @@ static int g_submit_queues = 1;
 device_param_cb(submit_queues, &null_submit_queues_param_ops, &g_submit_queues, 0444);
 MODULE_PARM_DESC(submit_queues, "Number of submission queues");
 
+static int null_set_poll_queues(const char *s, const struct kernel_param *kp)
+{
+	int ret;
+
+	ret = null_param_store_int(s, kp->arg, 1, num_online_cpus());
+	if (ret)
+		pr_err("out of bound poll_queues [1 .. %u]\n",
+		       num_online_cpus());
+	return ret;
+}
+
+static const struct kernel_param_ops null_poll_queues_param_ops = {
+	.set	= null_set_poll_queues,
+	.get	= param_get_int,
+};
+
 static int g_poll_queues = 1;
-module_param_named(poll_queues, g_poll_queues, int, 0444);
+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;
-- 
2.29.0




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux