block: add regression test for null-blk concurrently power/submit_queues test
PATCH v2 1/1 block: add regression test for null-blk concurrently power/submit_queues test
null-blk currently power/submit_queues operations which will lead kernel null-ptr-dereference[1], add one regression test for it and the fix has
been merged to v6.10-rc1 by [2].
[1]
https://lore.kernel.org/linux-block/CAHj4cs9LgsHLnjg8z06LQ3Pr5cax-+Ps+xT7AP7TPnEjStuwZA@mail.gmail.com/
https://lore.kernel.org/linux-block/[email protected]/
[2]
commit a2db328b0839 ("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")
--- tests/block/038 | 61 +++++++++++++++++++++++++++++++++++++++++++++ tests/block/038.out | 2 ++ 2 files changed, 63 insertions(+) create mode 100755 tests/block/038 create mode 100644 tests/block/038.out
tests/block/038 new file +61 -0
@@ -0,0 +1,61 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2024 Yi Zhang <[email protected]> +# +# Regression test for commit a2db328b0839 ("null_blk: fix null-ptr-dereference +# while configuring 'power' and 'submit_queues'"). + +. tests/block/rc +. common/null_blk + +DESCRIPTION="Test null-blk concurrent power/submit_queues operations" +QUICK=1 + +requires() { + _have_module null_blk + _have_module_param null_blk nr_devices + _have_module_param null_blk submit_queues +} + +null_blk_power_loop() { + local nullb="$1" + for ((i = 1; i <= 200; i++)); do + echo 1 > "/sys/kernel/config/nullb/${nullb}/power" + echo 0 > "/sys/kernel/config/nullb/${nullb}/power" + done +} + +null_blk_submit_queues_loop() { + local nullb="$1" + for ((i = 1; i <= 200; i++)); do + echo 1 > "/sys/kernel/config/nullb/${nullb}/submit_queues" + echo 4 > "/sys/kernel/config/nullb/${nullb}/submit_queues" + done +} + +test() { + echo "Running ${TEST_NAME}" + + local nullb_params=( + nr_devices=0 + ) + if ! _init_null_blk "${nullb_params[@]}"; then + echo "Loading null_blk failed" + return 1 + fi + + if ! _configure_null_blk nullb0; then + echo "Configuring null_blk nullb0 failed" + return 1 + fi + + # fire off two null-blk power/submit_queues concurrently and wait + # for them to complete... + null_blk_power_loop nullb0 & + null_blk_submit_queues_loop nullb0 & + wait + + _exit_null_blk + + echo "Test complete" +}
tests/block/038.out new file +2 -0
@@ -0,0 +1,2 @@ +Running block/038 +Test complete
Signature · 1 line
2.45.1
Quoted 10 lines · Yi Zhang
null-blk currently power/submit_queues operations which will lead kernel null-ptr-dereference[1], add one regression test for it and the fix has
been merged to v6.10-rc1 by [2].
[1]
https://lore.kernel.org/linux-block/CAHj4cs9LgsHLnjg8z06LQ3Pr5cax-+Ps+xT7AP7TPnEjStuwZA@mail.gmail.com/
https://lore.kernel.org/linux-block/[email protected]/
[2]
commita2db328b0839("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")Signed-off-by Yi Zhang<[email protected]>
Thanks for the test, looks good, I wonder what other drivers might need such test ...
-ck
Quoted 8 lines · Yi Zhang
null-blk currently power/submit_queues operations which will lead kernel null-ptr-dereference[1], add one regression test for it and the fix has
been merged to v6.10-rc1 by [2].
[1]
https://lore.kernel.org/linux-block/CAHj4cs9LgsHLnjg8z06LQ3Pr5cax-+Ps+xT7AP7TPnEjStuwZA@mail.gmail.com/
https://lore.kernel.org/linux-block/[email protected]/
[2]
commita2db328b0839("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")
Thank you Yi. I ran the test case and it looks working good. It passes with the kernel v6.10-rc2. It causes the hang with the kernel v6.9. To not confuse blktests users with the hang, I will wait for the commit a2db328b0839 to land on the stable kernels before I apply this patch.
One more thing I noticed is that your current patch requires loadable null_blk. To allow it run with built-in null_blk, I would like to suggest additional change below on top of your patch. It,
- calls _have_null_blk instead of _have_module null_blk,
- checks submit_queues parameter with _have_null_blk_feature instead of _have_module_param,
- does not call _init_null_blk, and
- uses nullb1 instead for nullb0.
Please let me know your thought about these changes. If you are ok with them, I can fold them in the commit.
tests/block/038 +8 -15
@@ -12,9 +12,10 @@ DESCRIPTION="Test null-blk concurrent power/submit_queues operations" QUICK=1 requires() { - _have_module null_blk - _have_module_param null_blk nr_devices - _have_module_param null_blk submit_queues + _have_null_blk + if ! _have_null_blk_feature submit_queues; then + SKIP_REASONS+=("null_blk does not support submit_queues") + fi } null_blk_power_loop() {
@@ -36,23 +37,15 @@ null_blk_submit_queues_loop() { test() { echo "Running ${TEST_NAME}" - local nullb_params=( - nr_devices=0 - ) - if ! _init_null_blk "${nullb_params[@]}"; then - echo "Loading null_blk failed" - return 1 - fi - - if ! _configure_null_blk nullb0; then - echo "Configuring null_blk nullb0 failed" + if ! _configure_null_blk nullb1; then + echo "Configuring null_blk nullb1 failed" return 1 fi # fire off two null-blk power/submit_queues concurrently and wait # for them to complete... - null_blk_power_loop nullb0 & - null_blk_submit_queues_loop nullb0 & + null_blk_power_loop nullb1 & + null_blk_submit_queues_loop nullb1 & wait _exit_null_blk
Quoted 20 lines · Shinichiro Kawasaki
Quoted 8 lines · Yi Zhang
null-blk currently power/submit_queues operations which will lead kernel null-ptr-dereference[1], add one regression test for it and the fix has
been merged to v6.10-rc1 by [2].
[1]
https://lore.kernel.org/linux-block/CAHj4cs9LgsHLnjg8z06LQ3Pr5cax-+Ps+xT7AP7TPnEjStuwZA@mail.gmail.com/
https://lore.kernel.org/linux-block/[email protected]/
[2]
commita2db328b0839("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")Thank you Yi. I ran the test case and it looks working good. It passes with the kernel v6.10-rc2. It causes the hang with the kernel v6.9. To not confuse blktests users with the hang, I will wait for the commit
a2db328b0839to land on the stable kernels before I apply this patch.One more thing I noticed is that your current patch requires loadable
null_blk. To allow it run with built-innull_blk, I would like to suggest additional change below on top of your patch. It,
Quoted 8 lines
- calls
_have_null_blkinstead of_have_modulenull_blk,
- checkssubmit_queuesparameter with_have_null_blk_featureinstead of_have_module_param,
- does not call_init_null_blk, and
- uses nullb1 instead for nullb0.Please let me know your thought about these changes. If you are ok with them, I can fold them in the commit.
Sure, I'm OK with the change, thanks. :)
Quoted 48 lines
tests/block/038 +8
-15@@ -12,9 +12,10 @@ DESCRIPTION="Test null-blk concurrent power/submit_queues operations" QUICK=1 requires() { - _have_module null_blk - _have_module_param null_blk nr_devices - _have_module_param null_blk submit_queues + _have_null_blk + if ! _have_null_blk_feature submit_queues; then + SKIP_REASONS+=("null_blk does not support submit_queues") + fi } null_blk_power_loop() {@@ -36,23 +37,15 @@ null_blk_submit_queues_loop() { test() { echo "Running ${TEST_NAME}" - local nullb_params=( - nr_devices=0 - ) - if ! _init_null_blk "${nullb_params[@]}"; then - echo "Loading null_blk failed" - return 1 - fi - - if ! _configure_null_blk nullb0; then - echo "Configuring null_blk nullb0 failed" + if ! _configure_null_blk nullb1; then + echo "Configuring null_blk nullb1 failed" return 1 fi # fire off two null-blk power/submit_queues concurrently and wait # for them to complete... - null_blk_power_loop nullb0 & - null_blk_submit_queues_loop nullb0 & + null_blk_power_loop nullb1 & + null_blk_submit_queues_loop nullb1 & wait _exit_null_blk
Signature · 2 lines
Best Regards, Yi Zhang
Quoted 28 lines · Yi Zhang
Quoted 26 lines · Shinichiro Kawasaki
Quoted 8 lines · Yi Zhang
null-blk currently power/submit_queues operations which will lead kernel null-ptr-dereference[1], add one regression test for it and the fix has
been merged to v6.10-rc1 by [2].
[1]
https://lore.kernel.org/linux-block/CAHj4cs9LgsHLnjg8z06LQ3Pr5cax-+Ps+xT7AP7TPnEjStuwZA@mail.gmail.com/
https://lore.kernel.org/linux-block/[email protected]/
[2]
commita2db328b0839("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")Thank you Yi. I ran the test case and it looks working good. It passes with the kernel v6.10-rc2. It causes the hang with the kernel v6.9. To not confuse blktests users with the hang, I will wait for the commit
a2db328b0839to land on the stable kernels before I apply this patch.One more thing I noticed is that your current patch requires loadable
null_blk. To allow it run with built-innull_blk, I would like to suggest additional change below on top of your patch. It,- calls
_have_null_blkinstead of_have_modulenull_blk,
- checkssubmit_queuesparameter with_have_null_blk_featureinstead of_have_module_param,
- does not call_init_null_blk, and
- uses nullb1 instead for nullb0.
Quoted 4 lines
Quoted 2 lines
Please let me know your thought about these changes. If you are ok with them, I can fold them in the commit.
Sure, I'm OK with the change, thanks. :)
Now the kernel side fix is in v6.9.4 kernel. I've applied this blktests patch. Thanks! FYI, I added my modification as a following commit [*].
[*] https://github.com/osandov/blktests/commit/eba35aaf32ceb9516a7dbc856c9db4d0ae3268d0