diff mbox series

[v2,blktests,4/5] tests/throtl: add a new test 004

Message ID 20240417022005.1410525-5-yukuai1@huaweicloud.com (mailing list archive)
State New
Headers show
Series add new tests for blk-throttle | expand

Commit Message

Yu Kuai April 17, 2024, 2:20 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

Test delete the disk while IO is throttled, regerssion test for:

commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/004     | 37 +++++++++++++++++++++++++++++++++++
 tests/throtl/004.out |  4 ++++
 tests/throtl/rc      | 46 +++++++++++++++++++++++++++++++++-----------
 3 files changed, 76 insertions(+), 11 deletions(-)
 create mode 100755 tests/throtl/004
 create mode 100644 tests/throtl/004.out

Comments

Shin'ichiro Kawasaki April 19, 2024, 4:45 a.m. UTC | #1
On Apr 17, 2024 / 10:20, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Test delete the disk while IO is throttled, regerssion test for:

Nit: s/regerssion/regression/

> 
> commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
> commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  tests/throtl/004     | 37 +++++++++++++++++++++++++++++++++++
>  tests/throtl/004.out |  4 ++++
>  tests/throtl/rc      | 46 +++++++++++++++++++++++++++++++++-----------
>  3 files changed, 76 insertions(+), 11 deletions(-)
>  create mode 100755 tests/throtl/004
>  create mode 100644 tests/throtl/004.out
> 
> diff --git a/tests/throtl/004 b/tests/throtl/004
> new file mode 100755
> index 0000000..f2567c0
> --- /dev/null
> +++ b/tests/throtl/004
> @@ -0,0 +1,37 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-3.0+
> +# Copyright (C) 2024 Yu Kuai
> +#
> +# Test delete the disk while IO is throttled, regerssion test for

Nit: s/regerssion/regression/

> +# commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
> +# commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")
> +
> +. tests/throtl/rc
> +
> +DESCRIPTION="delete disk while IO is throttled"
> +QUICK=1
> +
> +test() {
> +	echo "Running ${TEST_NAME}"
> +
> +	if ! _set_up_test_by_configfs power=1; then
> +		return 1;
> +	fi
> +
> +	_set_limits wbps=$((1024 * 1024))
> +
> +	{
> +		sleep 0.1
> +		_issue_io write 10M 1
> +	} &
> +
> +	pid=$!
> +	echo "$pid" > $TEST_DIR/cgroup.procs
> +
> +	sleep 1

When I ran this test case on my QEMU test machine, it failed with the message
below. When I repeat the test case, it sometimes passes but fails in most
cases. I guess this is because my machine is slow and takes some time from
the disk deletion to write process exit.

throtl/004 (delete disk while IO is throttled)               [failed]
    runtime  1.085s  ...  1.997s
    --- tests/throtl/004.out    2024-04-19 11:26:56.507007360 +0900
    +++ /home/shin/Blktests/blktests/results/nodev/throtl/004.out.bad   2024-04-19 13:34:03.766045990 +0900
    @@ -1,4 +1,4 @@
     Running throtl/004
     dd: error writing '/dev/thr_nullb': Input/output error
    -1
    +2
     Test complete

When I change the "sleep 1" in line above to "sleep .6", then the test case
passed even when I repeat the test case run several times. This changes adds
some margin and will make the result elapsed time to be round up to "1" not to
"2". Still 0.6 second delay on the wait process and 0.1 second delay on the
write process has the gap 0.5 second, then it is ensured to be rounded to "1".
So I guess the sleep time 0.6 is the valid number, probably.

> +	echo 0 > /sys/kernel/config/nullb/$devname/power
> +	wait "$pid"
> +
> +	_clean_up_test
> +	echo "Test complete"
> +}
> diff --git a/tests/throtl/004.out b/tests/throtl/004.out
> new file mode 100644
> index 0000000..03331fe
> --- /dev/null
> +++ b/tests/throtl/004.out
> @@ -0,0 +1,4 @@
> +Running throtl/004
> +dd: error writing '/dev/nullb0': Input/output error
> +1
> +Test complete
> diff --git a/tests/throtl/rc b/tests/throtl/rc
> index 871102c..f70e250 100644
> --- a/tests/throtl/rc
> +++ b/tests/throtl/rc
> @@ -30,6 +30,21 @@ _set_up_test() {
>  	return 0;
>  }
>  
> +_set_up_test_by_configfs() {
> +	if ! _init_null_blk nr_devices=0; then
> +		return 1;
> +	fi
> +
> +	if ! _configure_null_blk $devname "$*"; then
> +		return 1;
> +	fi
> +
> +	echo +io > $CG/cgroup.subtree_control
> +	mkdir $TEST_DIR
> +
> +	return 0;
> +}
> +
>  _clean_up_test() {
>  	rmdir $TEST_DIR
>  	echo -io > $CG/cgroup.subtree_control
> @@ -46,23 +61,32 @@ _remove_limits() {
>  	echo "$dev rbps=max wbps=max riops=max wiops=max" > $TEST_DIR/io.max
>  }
>  
> +_issue_io()
> +{
> +	start_time=$(date +%s.%N)
> +
> +	if [ "$1" == "read" ]; then
> +		dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none
> +	elif [ "$1" == "write" ]; then
> +		dd of=/dev/$devname if=/dev/zero bs="$2" count="$3" oflag=direct status=none
> +	fi
> +
> +	end_time=$(date +%s.%N)
> +	elapsed=$(echo "$end_time - $start_time" | bc)
> +	printf "%.0f\n" "$elapsed"
> +}
> +
>  # Create an asynchronous thread and bind it to the specified blk-cgroup, issue
>  # IO and then print time elapsed to the second, blk-throttle limits should be
>  # set before this function.
>  _test_io() {
>  	{
> -		sleep 0.1
> -		start_time=$(date +%s.%N)
> +		rw=$1
> +		bs=$2
> +		count=$3
>  
> -		if [ "$1" == "read" ]; then
> -			dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none
> -		elif [ "$1" == "write" ]; then
> -			dd of=/dev/$devname if=/dev/zero bs="$2" count="$3" oflag=direct status=none
> -		fi
> -
> -		end_time=$(date +%s.%N)
> -		elapsed=$(echo "$end_time - $start_time" | bc)
> -		printf "%.0f\n" "$elapsed"
> +		sleep 0.1
> +		_issue_io "$rw" "$bs" "$count"
>  	} &
>  
>  	pid=$!
> -- 
> 2.39.2
>
Yu Kuai April 19, 2024, 8:05 a.m. UTC | #2
Hi,

在 2024/04/19 12:45, Shinichiro Kawasaki 写道:
> On Apr 17, 2024 / 10:20, Yu Kuai wrote:
>> From: Yu Kuai <yukuai3@huawei.com>
>>
>> Test delete the disk while IO is throttled, regerssion test for:
> 
> Nit: s/regerssion/regression/
> 
>>
>> commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
>> commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")
>>
>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>> ---
>>   tests/throtl/004     | 37 +++++++++++++++++++++++++++++++++++
>>   tests/throtl/004.out |  4 ++++
>>   tests/throtl/rc      | 46 +++++++++++++++++++++++++++++++++-----------
>>   3 files changed, 76 insertions(+), 11 deletions(-)
>>   create mode 100755 tests/throtl/004
>>   create mode 100644 tests/throtl/004.out
>>
>> diff --git a/tests/throtl/004 b/tests/throtl/004
>> new file mode 100755
>> index 0000000..f2567c0
>> --- /dev/null
>> +++ b/tests/throtl/004
>> @@ -0,0 +1,37 @@
>> +#!/bin/bash
>> +# SPDX-License-Identifier: GPL-3.0+
>> +# Copyright (C) 2024 Yu Kuai
>> +#
>> +# Test delete the disk while IO is throttled, regerssion test for
> 
> Nit: s/regerssion/regression/
> 
>> +# commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
>> +# commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")
>> +
>> +. tests/throtl/rc
>> +
>> +DESCRIPTION="delete disk while IO is throttled"
>> +QUICK=1
>> +
>> +test() {
>> +	echo "Running ${TEST_NAME}"
>> +
>> +	if ! _set_up_test_by_configfs power=1; then
>> +		return 1;
>> +	fi
>> +
>> +	_set_limits wbps=$((1024 * 1024))
>> +
>> +	{
>> +		sleep 0.1
>> +		_issue_io write 10M 1
>> +	} &
>> +
>> +	pid=$!
>> +	echo "$pid" > $TEST_DIR/cgroup.procs
>> +
>> +	sleep 1
> 
> When I ran this test case on my QEMU test machine, it failed with the message
> below. When I repeat the test case, it sometimes passes but fails in most
> cases. I guess this is because my machine is slow and takes some time from
> the disk deletion to write process exit.
> 
> throtl/004 (delete disk while IO is throttled)               [failed]
>      runtime  1.085s  ...  1.997s
>      --- tests/throtl/004.out    2024-04-19 11:26:56.507007360 +0900
>      +++ /home/shin/Blktests/blktests/results/nodev/throtl/004.out.bad   2024-04-19 13:34:03.766045990 +0900
>      @@ -1,4 +1,4 @@
>       Running throtl/004
>       dd: error writing '/dev/thr_nullb': Input/output error
>      -1
>      +2
>       Test complete
> 
> When I change the "sleep 1" in line above to "sleep .6", then the test case
> passed even when I repeat the test case run several times. This changes adds
> some margin and will make the result elapsed time to be round up to "1" not to
> "2". Still 0.6 second delay on the wait process and 0.1 second delay on the
> write process has the gap 0.5 second, then it is ensured to be rounded to "1".
> So I guess the sleep time 0.6 is the valid number, probably.

Yes, I was worried about slow machine, that's why I creat the null_blk
with 1s IO latency. use 0.6 sounds good to me, time precision is still
one second.

Thanks,
Kuai
> 
>> +	echo 0 > /sys/kernel/config/nullb/$devname/power
>> +	wait "$pid"
>> +
>> +	_clean_up_test
>> +	echo "Test complete"
>> +}
>> diff --git a/tests/throtl/004.out b/tests/throtl/004.out
>> new file mode 100644
>> index 0000000..03331fe
>> --- /dev/null
>> +++ b/tests/throtl/004.out
>> @@ -0,0 +1,4 @@
>> +Running throtl/004
>> +dd: error writing '/dev/nullb0': Input/output error
>> +1
>> +Test complete
>> diff --git a/tests/throtl/rc b/tests/throtl/rc
>> index 871102c..f70e250 100644
>> --- a/tests/throtl/rc
>> +++ b/tests/throtl/rc
>> @@ -30,6 +30,21 @@ _set_up_test() {
>>   	return 0;
>>   }
>>   
>> +_set_up_test_by_configfs() {
>> +	if ! _init_null_blk nr_devices=0; then
>> +		return 1;
>> +	fi
>> +
>> +	if ! _configure_null_blk $devname "$*"; then
>> +		return 1;
>> +	fi
>> +
>> +	echo +io > $CG/cgroup.subtree_control
>> +	mkdir $TEST_DIR
>> +
>> +	return 0;
>> +}
>> +
>>   _clean_up_test() {
>>   	rmdir $TEST_DIR
>>   	echo -io > $CG/cgroup.subtree_control
>> @@ -46,23 +61,32 @@ _remove_limits() {
>>   	echo "$dev rbps=max wbps=max riops=max wiops=max" > $TEST_DIR/io.max
>>   }
>>   
>> +_issue_io()
>> +{
>> +	start_time=$(date +%s.%N)
>> +
>> +	if [ "$1" == "read" ]; then
>> +		dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none
>> +	elif [ "$1" == "write" ]; then
>> +		dd of=/dev/$devname if=/dev/zero bs="$2" count="$3" oflag=direct status=none
>> +	fi
>> +
>> +	end_time=$(date +%s.%N)
>> +	elapsed=$(echo "$end_time - $start_time" | bc)
>> +	printf "%.0f\n" "$elapsed"
>> +}
>> +
>>   # Create an asynchronous thread and bind it to the specified blk-cgroup, issue
>>   # IO and then print time elapsed to the second, blk-throttle limits should be
>>   # set before this function.
>>   _test_io() {
>>   	{
>> -		sleep 0.1
>> -		start_time=$(date +%s.%N)
>> +		rw=$1
>> +		bs=$2
>> +		count=$3
>>   
>> -		if [ "$1" == "read" ]; then
>> -			dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none
>> -		elif [ "$1" == "write" ]; then
>> -			dd of=/dev/$devname if=/dev/zero bs="$2" count="$3" oflag=direct status=none
>> -		fi
>> -
>> -		end_time=$(date +%s.%N)
>> -		elapsed=$(echo "$end_time - $start_time" | bc)
>> -		printf "%.0f\n" "$elapsed"
>> +		sleep 0.1
>> +		_issue_io "$rw" "$bs" "$count"
>>   	} &
>>   
>>   	pid=$!
>> -- 
>> 2.39.2
>> .
>
diff mbox series

Patch

diff --git a/tests/throtl/004 b/tests/throtl/004
new file mode 100755
index 0000000..f2567c0
--- /dev/null
+++ b/tests/throtl/004
@@ -0,0 +1,37 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test delete the disk while IO is throttled, regerssion test for
+# commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
+# commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")
+
+. tests/throtl/rc
+
+DESCRIPTION="delete disk while IO is throttled"
+QUICK=1
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! _set_up_test_by_configfs power=1; then
+		return 1;
+	fi
+
+	_set_limits wbps=$((1024 * 1024))
+
+	{
+		sleep 0.1
+		_issue_io write 10M 1
+	} &
+
+	pid=$!
+	echo "$pid" > $TEST_DIR/cgroup.procs
+
+	sleep 1
+	echo 0 > /sys/kernel/config/nullb/$devname/power
+	wait "$pid"
+
+	_clean_up_test
+	echo "Test complete"
+}
diff --git a/tests/throtl/004.out b/tests/throtl/004.out
new file mode 100644
index 0000000..03331fe
--- /dev/null
+++ b/tests/throtl/004.out
@@ -0,0 +1,4 @@ 
+Running throtl/004
+dd: error writing '/dev/nullb0': Input/output error
+1
+Test complete
diff --git a/tests/throtl/rc b/tests/throtl/rc
index 871102c..f70e250 100644
--- a/tests/throtl/rc
+++ b/tests/throtl/rc
@@ -30,6 +30,21 @@  _set_up_test() {
 	return 0;
 }
 
+_set_up_test_by_configfs() {
+	if ! _init_null_blk nr_devices=0; then
+		return 1;
+	fi
+
+	if ! _configure_null_blk $devname "$*"; then
+		return 1;
+	fi
+
+	echo +io > $CG/cgroup.subtree_control
+	mkdir $TEST_DIR
+
+	return 0;
+}
+
 _clean_up_test() {
 	rmdir $TEST_DIR
 	echo -io > $CG/cgroup.subtree_control
@@ -46,23 +61,32 @@  _remove_limits() {
 	echo "$dev rbps=max wbps=max riops=max wiops=max" > $TEST_DIR/io.max
 }
 
+_issue_io()
+{
+	start_time=$(date +%s.%N)
+
+	if [ "$1" == "read" ]; then
+		dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none
+	elif [ "$1" == "write" ]; then
+		dd of=/dev/$devname if=/dev/zero bs="$2" count="$3" oflag=direct status=none
+	fi
+
+	end_time=$(date +%s.%N)
+	elapsed=$(echo "$end_time - $start_time" | bc)
+	printf "%.0f\n" "$elapsed"
+}
+
 # Create an asynchronous thread and bind it to the specified blk-cgroup, issue
 # IO and then print time elapsed to the second, blk-throttle limits should be
 # set before this function.
 _test_io() {
 	{
-		sleep 0.1
-		start_time=$(date +%s.%N)
+		rw=$1
+		bs=$2
+		count=$3
 
-		if [ "$1" == "read" ]; then
-			dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none
-		elif [ "$1" == "write" ]; then
-			dd of=/dev/$devname if=/dev/zero bs="$2" count="$3" oflag=direct status=none
-		fi
-
-		end_time=$(date +%s.%N)
-		elapsed=$(echo "$end_time - $start_time" | bc)
-		printf "%.0f\n" "$elapsed"
+		sleep 0.1
+		_issue_io "$rw" "$bs" "$count"
 	} &
 
 	pid=$!