Skip to contentSkip to conversation

null_blk: add modparam vefication

PATCH New Chaitanya Kulkarni 1 participant 7 messages Oct 7, 2022 Block layer

lore
Share & tools
lore
#0 lore raw

cover null_blk: add modparam vefication

Hi,

Add module parameter verification make sure we are not deling with the negative value that also fixes follwing Oops :-

linux-block (for-next) # modprobe null_blk poll_queues=-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>

-ck

Chaitanya Kulkarni (6):
null_blk: check for valid submit_queue value
null_blk: check for valid poll_queue value
null_blk: check for valid gb value
null_blk: check for valid block size value
null_blk: check for valid max_sectors value
null_blk: check for valid queue depth value

 drivers/block/null_blk/main.c | 107 +++++++++++++++++++++++++++-------
 1 file changed, 85 insertions(+), 22 deletions(-)

Test Report :-

ilinux-block (for-next) # sh ./test-mod-param.sh
###################################################
poll_queues:
------------------------------------
modprobe null_blk poll_queues=2

[ 1924.377679] null_blk: disk nullb0 created
[ 1924.377688] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=4
[ 1924.677126] null_blk: disk nullb0 created
[ 1924.677131] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=8
[ 1924.971561] null_blk: disk nullb0 created
[ 1924.971566] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=16
[ 1925.274443] null_blk: disk nullb0 created
[ 1925.274448] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=32
[ 1925.576851] null_blk: disk nullb0 created
[ 1925.576856] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=64
[ 1925.891751] null_blk: disk nullb0 created
[ 1925.891755] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=128
[ 1926.195455] null_blk: disk nullb0 created
[ 1926.195460] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=256
[ 1926.503886] null_blk: disk nullb0 created
[ 1926.503890] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=512
[ 1926.834959] null_blk: disk nullb0 created
[ 1926.834965] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=1024
[ 1927.201886] null_blk: disk nullb0 created
[ 1927.201891] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=2048
[ 1927.616806]  nullb0: AHDI p1 p3
[ 1927.616920] nullb0: p3 size 4294949121 extends beyond EOD, truncated
[ 1927.616978] null_blk: disk nullb0 created
[ 1927.616979] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=4096
[ 1928.117183] null_blk: disk nullb0 created
[ 1928.117188] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=8192
[ 1928.797501] null_blk: disk nullb0 created
[ 1928.797506] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=16384
[ 1929.849149] null_blk: disk nullb0 created
[ 1929.849154] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=32768
[ 1931.577964] null_blk: disk nullb0 created
[ 1931.577969] null_blk: module loaded

------------------------------------
modprobe null_blk poll_queues=65536
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=131072
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=262144
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=524288
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=1048576
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=2097152
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=4194304
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=8388608
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=16777216
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=33554432
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=67108864
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=134217728
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=268435456
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=536870912
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=1073741824
modprobe: ERROR: could not insert 'null_blk': Cannot allocate memory
------------------------------------
modprobe null_blk poll_queues=2147483648
modprobe: ERROR: could not insert 'null_blk': Invalid argument

[ 1937.008217] null_blk: `2147483648' invalid for parameter `poll_queues'
------------------------------------
modprobe null_blk poll_queues=4294967296
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1937.290366] null_blk: `4294967296' invalid for parameter `poll_queues'

###################################################
submit_queues:
------------------------------------
modprobe null_blk submit_queues=2

[ 1937.585539] null_blk: disk nullb0 created
[ 1937.585544] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=4
[ 1937.880302] null_blk: disk nullb0 created
[ 1937.880306] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=8
[ 1938.174551] null_blk: disk nullb0 created
[ 1938.174555] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=16
[ 1938.477783] null_blk: disk nullb0 created
[ 1938.477787] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=32
[ 1938.770354] null_blk: disk nullb0 created
[ 1938.770359] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=64
[ 1939.074975] null_blk: disk nullb0 created
[ 1939.074979] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=128
[ 1939.370133] null_blk: disk nullb0 created
[ 1939.370138] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=256
[ 1939.663309] null_blk: disk nullb0 created
[ 1939.663313] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=512
[ 1939.970666] null_blk: disk nullb0 created
[ 1939.970671] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=1024
[ 1940.267200] null_blk: disk nullb0 created
[ 1940.267203] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=2048
[ 1940.569051] null_blk: disk nullb0 created
[ 1940.569055] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=4096
[ 1940.869073] null_blk: disk nullb0 created
[ 1940.869076] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=8192
[ 1941.170419] null_blk: disk nullb0 created
[ 1941.170423] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=16384
[ 1941.473582] null_blk: disk nullb0 created
[ 1941.473586] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=32768
[ 1941.766981] null_blk: disk nullb0 created
[ 1941.766985] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=65536
[ 1942.069883] null_blk: disk nullb0 created
[ 1942.069887] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=131072
[ 1942.362132] null_blk: disk nullb0 created
[ 1942.362137] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=262144
[ 1942.661742] null_blk: disk nullb0 created
[ 1942.661747] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=524288
[ 1942.955668] null_blk: disk nullb0 created
[ 1942.955673] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=1048576
[ 1943.249454] null_blk: disk nullb0 created
[ 1943.249459] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=2097152
[ 1943.550678] null_blk: disk nullb0 created
[ 1943.550683] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=4194304
[ 1943.856922] null_blk: disk nullb0 created
[ 1943.856927] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=8388608
[ 1944.173595] null_blk: disk nullb0 created
[ 1944.173600] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=16777216
[ 1944.472637] null_blk: disk nullb0 created
[ 1944.472641] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=33554432
[ 1944.767623] null_blk: disk nullb0 created
[ 1944.767627] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=67108864
[ 1945.073317] null_blk: disk nullb0 created
[ 1945.073321] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=134217728
[ 1945.380609] null_blk: disk nullb0 created
[ 1945.380613] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=268435456
[ 1945.677736] null_blk: disk nullb0 created
[ 1945.677740] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=536870912
[ 1945.975502] null_blk: disk nullb0 created
[ 1945.975506] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=1073741824
[ 1946.272191] null_blk: disk nullb0 created
[ 1946.272195] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=2147483648
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1946.566080] null_blk: `2147483648' invalid for parameter `submit_queues'
------------------------------------
modprobe null_blk submit_queues=4294967296
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1946.847997] null_blk: `4294967296' invalid for parameter `submit_queues'

###################################################
hw_queue_depth:
------------------------------------
modprobe null_blk hw_queue_depth=-2
modprobe: ERROR: could not insert 'null_blk': Invalid argument

[ 1947.127929] null_blk: `-2' invalid for parameter `hw_queue_depth'
------------------------------------
modprobe null_blk hw_queue_depth=-1
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1947.161958] null_blk: `-1' invalid for parameter `hw_queue_depth'
------------------------------------
modprobe null_blk hw_queue_depth=0
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1947.192521] null_blk: `0' invalid for parameter `hw_queue_depth'
------------------------------------
modprobe null_blk hw_queue_depth=1
[ 1947.222359] null_blk: disk nullb0 created
[ 1947.222363] null_blk: module loaded
------------------------------------
modprobe null_blk hw_queue_depth=2
[ 1947.270471] null_blk: disk nullb0 created
[ 1947.270476] null_blk: module loaded
------------------------------------
modprobe null_blk hw_queue_depth=4
[ 1947.318861] null_blk: disk nullb0 created
[ 1947.318865] null_blk: module loaded
------------------------------------
modprobe null_blk hw_queue_depth=8
[ 1947.368261] null_blk: disk nullb0 created
[ 1947.368265] null_blk: module loaded
------------------------------------
modprobe null_blk hw_queue_depth=32
[ 1947.422207] null_blk: disk nullb0 created
[ 1947.422210] null_blk: module loaded
------------------------------------
modprobe null_blk hw_queue_depth=64
[ 1947.469696] null_blk: disk nullb0 created
[ 1947.469699] null_blk: module loaded

###################################################
max_sectors:
------------------------------------
modprobe null_blk max_sectors=-2
modprobe: ERROR: could not insert 'null_blk': Invalid argument

[ 1947.518538] null_blk: `-2' invalid for parameter `max_sectors'
------------------------------------
modprobe null_blk max_sectors=-1
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1947.548179] null_blk: `-1' invalid for parameter `max_sectors'
------------------------------------
modprobe null_blk max_sectors=0
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1947.584591] null_blk: `0' invalid for parameter `max_sectors'
------------------------------------
modprobe null_blk max_sectors=1
[ 1947.621178] blk_queue_max_hw_sectors: set to minimum 8
[ 1947.622980] null_blk: disk nullb0 created
[ 1947.622983] null_blk: module loaded
------------------------------------
modprobe null_blk max_sectors=2
[ 1947.673349] blk_queue_max_hw_sectors: set to minimum 8
[ 1947.675181] null_blk: disk nullb0 created
[ 1947.675184] null_blk: module loaded
------------------------------------
modprobe null_blk max_sectors=4
[ 1947.742695] blk_queue_max_hw_sectors: set to minimum 8
[ 1947.744392] null_blk: disk nullb0 created
[ 1947.744395] null_blk: module loaded
------------------------------------
modprobe null_blk max_sectors=8
[ 1947.790072] null_blk: disk nullb0 created
[ 1947.790076] null_blk: module loaded
------------------------------------
modprobe null_blk max_sectors=32
[ 1947.833683] null_blk: disk nullb0 created
[ 1947.833686] null_blk: module loaded
------------------------------------
modprobe null_blk max_sectors=64
[ 1947.879298] null_blk: disk nullb0 created
[ 1947.879302] null_blk: module loaded

###################################################
gb:
------------------------------------
modprobe null_blk gb=-2
modprobe: ERROR: could not insert 'null_blk': Invalid argument

[ 1947.936630] null_blk: `-2' invalid for parameter `gb'
------------------------------------
modprobe null_blk gb=-1
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1947.965811] null_blk: `-1' invalid for parameter `gb'
------------------------------------
modprobe null_blk gb=0
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1948.000246] null_blk: `0' invalid for parameter `gb'
------------------------------------
modprobe null_blk gb=1
[ 1948.031978] null_blk: disk nullb0 created
[ 1948.031981] null_blk: module loaded
------------------------------------
modprobe null_blk gb=2
[ 1948.076624] null_blk: disk nullb0 created
[ 1948.076628] null_blk: module loaded
------------------------------------
modprobe null_blk gb=4
[ 1948.128380] null_blk: disk nullb0 created
[ 1948.128385] null_blk: module loaded
------------------------------------
modprobe null_blk gb=8
[ 1948.189039] null_blk: disk nullb0 created
[ 1948.189043] null_blk: module loaded
------------------------------------
modprobe null_blk gb=32
[ 1948.242571] null_blk: disk nullb0 created
[ 1948.242576] null_blk: module loaded
------------------------------------
modprobe null_blk gb=64
[ 1948.288508] null_blk: disk nullb0 created
[ 1948.288512] null_blk: module loaded

###################################################
poll_queues:
------------------------------------
modprobe null_blk poll_queues=-2
modprobe: ERROR: could not insert 'null_blk': Invalid argument

[ 1948.338489] null_blk: `-2' invalid for parameter `poll_queues'
------------------------------------
modprobe null_blk poll_queues=-1
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1948.366555] null_blk: `-1' invalid for parameter `poll_queues'
------------------------------------
modprobe null_blk poll_queues=0
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1948.396045] null_blk: `0' invalid for parameter `poll_queues'
------------------------------------
modprobe null_blk poll_queues=1
[ 1948.431236] null_blk: disk nullb0 created
[ 1948.431240] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=2
[ 1948.483416] null_blk: disk nullb0 created
[ 1948.483420] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=4
[ 1948.531614] null_blk: disk nullb0 created
[ 1948.531617] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=8
[ 1948.579633] null_blk: disk nullb0 created
[ 1948.579638] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=32
[ 1948.628638] null_blk: disk nullb0 created
[ 1948.628643] null_blk: module loaded
------------------------------------
modprobe null_blk poll_queues=64
[ 1948.686840] null_blk: disk nullb0 created
[ 1948.686845] null_blk: module loaded

###################################################
submit_queues:
------------------------------------
modprobe null_blk submit_queues=-2
modprobe: ERROR: could not insert 'null_blk': Invalid argument

[ 1948.735486] null_blk: `-2' invalid for parameter `submit_queues'
------------------------------------
modprobe null_blk submit_queues=-1
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1948.764503] null_blk: `-1' invalid for parameter `submit_queues'
------------------------------------
modprobe null_blk submit_queues=0
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1948.794944] null_blk: `0' invalid for parameter `submit_queues'
------------------------------------
modprobe null_blk submit_queues=1
[ 1948.826061] null_blk: disk nullb0 created
[ 1948.826065] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=2
[ 1948.872684] null_blk: disk nullb0 created
[ 1948.872688] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=4
[ 1948.928300] null_blk: disk nullb0 created
[ 1948.928303] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=8
[ 1948.984935] null_blk: disk nullb0 created
[ 1948.984939] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=32
[ 1949.034590] null_blk: disk nullb0 created
[ 1949.034595] null_blk: module loaded
------------------------------------
modprobe null_blk submit_queues=64
[ 1949.085751] null_blk: disk nullb0 created
[ 1949.085756] null_blk: module loaded

###################################################
bs:
------------------------------------
modprobe null_blk bs=-2
modprobe: ERROR: could not insert 'null_blk': Invalid argument

[ 1949.130053] null_blk: `-2' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=-1
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.161179] null_blk: `-1' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=0
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.199904] null_blk: `0' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=1
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.229583] null_blk: `1' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=2
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.261719] null_blk: `2' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=4
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.292527] null_blk: `4' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=8
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.327845] null_blk: `8' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=32
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.358911] null_blk: `32' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=64
modprobe: ERROR: could not insert 'null_blk': Invalid argument
[ 1949.387419] null_blk: `64' invalid for parameter `bs'
------------------------------------
modprobe null_blk bs=512
[ 1949.417564] null_blk: disk nullb0 created
[ 1949.417567] null_blk: module loaded
------------------------------------
modprobe null_blk bs=1024
[ 1949.462782] null_blk: disk nullb0 created
[ 1949.462786] null_blk: module loaded
------------------------------------
modprobe null_blk bs=2048
[ 1949.518958] null_blk: disk nullb0 created
[ 1949.518961] null_blk: module loaded
------------------------------------
modprobe null_blk bs=4096
[ 1949.565926] null_blk: disk nullb0 created
[ 1949.565931] null_blk: module loaded

linux-block (for-next) #

Signature · 1 line
2.29.0
#1 lore raw

PATCH 1/6 null_blk: check for valid submit_queue value

Right now we don't check for valid module parameter value for submit_queue, that allows user to set negative values.

Move null_param_store_val() at the top so we can reuse that code in module param ops.

Add a callback null_set_submit_queues() to error out when submit_queue value is < 1 before module is loaded.

---
 drivers/block/null_blk/main.c | 42 +++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 17 deletions(-)
drivers/block/null_blk/main.c +25 -17
index 1f154f92f4c2..c8dbff120c65 100644
@@ -77,6 +77,21 @@ enum {
 	NULL_IRQ_TIMER		= 2,
 };
 
+static int null_param_store_val(const char *str, int *val, int min, int max)
+{
+	int ret, new_val;
+
+	ret = kstrtoint(str, 10, &new_val);
+	if (ret)
+		return -EINVAL;
+
+	if (new_val < min || new_val > max)
+		return -EINVAL;
+
+	*val = new_val;
+	return 0;
+}
+
 static bool g_virt_boundary = false;
 module_param_named(virt_boundary, g_virt_boundary, bool, 0444);
 MODULE_PARM_DESC(virt_boundary, "Require a virtual boundary for the device. Default: False");
@@ -86,7 +101,16 @@ module_param_named(no_sched, g_no_sched, int, 0444);
 MODULE_PARM_DESC(no_sched, "No io scheduler");
 
 static int g_submit_queues = 1;
-module_param_named(submit_queues, g_submit_queues, int, 0444);
+static int null_set_submit_queues(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_submit_queues, 1, INT_MAX);
+}
+
+static const struct kernel_param_ops null_submit_queues_param_ops = {
+	.set	= null_set_submit_queues,
+	.get	= param_get_int,
+};
+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 g_poll_queues = 1;
@@ -116,22 +140,6 @@ MODULE_PARM_DESC(init_hctx, "Fault injection to fail hctx init. init_hctx=<inter
 #endif
 
 static int g_queue_mode = NULL_Q_MQ;
-
-static int null_param_store_val(const char *str, int *val, int min, int max)
-{
-	int ret, new_val;
-
-	ret = kstrtoint(str, 10, &new_val);
-	if (ret)
-		return -EINVAL;
-
-	if (new_val < min || new_val > max)
-		return -EINVAL;
-
-	*val = new_val;
-	return 0;
-}
-
 static int null_set_queue_mode(const char *str, const struct kernel_param *kp)
 {
 	return null_param_store_val(str, &g_queue_mode, NULL_Q_BIO, NULL_Q_MQ);
Signature · 1 line
2.29.0
#2 lore raw

PATCH 2/6 null_blk: check for valid poll_queue value

In reply to Chaitanya Kulkarni

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>

---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +12 -1
index c8dbff120c65..29e43444cf66 100644
@@ -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;
Signature · 1 line
2.29.0
#3 lore raw

PATCH 3/6 null_blk: check for valid gb value

In reply to Chaitanya Kulkarni

Right now we don't check for valid module parameter value for gb, that allows user to set negative values.

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

---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +12 -1
index 29e43444cf66..83bf9065831a 100644
@@ -165,7 +165,18 @@ device_param_cb(queue_mode, &null_queue_mode_param_ops, &g_queue_mode, 0444);
 MODULE_PARM_DESC(queue_mode, "Block interface to use (0=bio,1=rq,2=multiqueue)");
 
 static int g_gb = 250;
-module_param_named(gb, g_gb, int, 0444);
+
+static int null_set_gb(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_gb, 1, INT_MAX);
+}
+
+static const struct kernel_param_ops null_gb_param_ops = {
+	.set	= null_set_gb,
+	.get	= param_get_int,
+};
+
+device_param_cb(gb, &null_gb_param_ops, &g_gb, 0444);
 MODULE_PARM_DESC(gb, "Size in GB");
 
 static int g_bs = 512;
Signature · 1 line
2.29.0
#4 lore raw

PATCH 4/6 null_blk: check for valid block size value

In reply to Chaitanya Kulkarni

Right now we don't check for valid module parameter value for block size, that allows user to set negative values.

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

---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +12 -1
index 83bf9065831a..7cfc1eaa5e3c 100644
@@ -180,7 +180,18 @@ device_param_cb(gb, &null_gb_param_ops, &g_gb, 0444);
 MODULE_PARM_DESC(gb, "Size in GB");
 
 static int g_bs = 512;
-module_param_named(bs, g_bs, int, 0444);
+
+static int null_set_bs(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_bs, 512, INT_MAX);
+}
+
+static const struct kernel_param_ops null_bs_param_ops = {
+	.set	= null_set_bs,
+	.get	= param_get_int,
+};
+
+device_param_cb(bs, &null_bs_param_ops, &g_bs, 0444);
 MODULE_PARM_DESC(bs, "Block size (in bytes)");
 
 static int g_max_sectors;
Signature · 1 line
2.29.0
#5 lore raw

PATCH 5/6 null_blk: check for valid max_sectors value

In reply to Chaitanya Kulkarni

Right now we don't check for valid module parameter value for max_sectors, that allows user to set negative values.

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

---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +12 -1
index 7cfc1eaa5e3c..1b9fa5af02d5 100644
@@ -195,7 +195,18 @@ device_param_cb(bs, &null_bs_param_ops, &g_bs, 0444);
 MODULE_PARM_DESC(bs, "Block size (in bytes)");
 
 static int g_max_sectors;
-module_param_named(max_sectors, g_max_sectors, int, 0444);
+
+static int null_set_max_sects(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_max_sectors, 1, INT_MAX);
+}
+
+static const struct kernel_param_ops null_max_sects_param_ops = {
+	.set	= null_set_max_sects,
+	.get	= param_get_int,
+};
+
+device_param_cb(max_sectors, &null_max_sects_param_ops, &g_max_sectors, 0444);
 MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)");
 
 static unsigned int nr_devices = 1;
Signature · 1 line
2.29.0
#6 lore raw

PATCH 6/6 null_blk: check for valid queue depth value

In reply to Chaitanya Kulkarni

Right now we don't check for valid module parameter value for queue depth, that allows user to set negative values.

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

---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +12 -1
index 1b9fa5af02d5..ae339376f112 100644
@@ -246,7 +246,18 @@ module_param_named(completion_nsec, g_completion_nsec, ulong, 0444);
 MODULE_PARM_DESC(completion_nsec, "Time in ns to complete a request in hardware. Default: 10,000ns");
 
 static int g_hw_queue_depth = 64;
-module_param_named(hw_queue_depth, g_hw_queue_depth, int, 0444);
+
+static int null_set_hw_queue_depth(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_hw_queue_depth, 1, INT_MAX);
+}
+
+static const struct kernel_param_ops null_hw_qdepth_param_ops = {
+	.set	= null_set_hw_queue_depth,
+	.get	= param_get_int,
+};
+
+device_param_cb(hw_queue_depth, &null_hw_qdepth_param_ops, &g_hw_queue_depth, 0444);
 MODULE_PARM_DESC(hw_queue_depth, "Queue depth for each hardware queue. Default: 64");
 
 static bool g_use_per_node_hctx;
Signature · 1 line
2.29.0