All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: linux-block@vger.kernel.org, saranyamohan@google.com,
	axboe@kernel.dk, tj@kernel.org
Cc: yukuai3@huawei.com, yukuai1@huaweicloud.com, yangerkun@huawei.com
Subject: [PATCH blktests 4/5] tests/throtl: add a new test 004
Date: Tue, 16 Apr 2024 10:00:41 +0800	[thread overview]
Message-ID: <20240416020042.509291-5-yukuai1@huaweicloud.com> (raw)
In-Reply-To: <20240416020042.509291-1-yukuai1@huaweicloud.com>

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     | 79 ++++++++++++++++++++++++++++++++++++++++++++
 tests/throtl/004.out |  4 +++
 2 files changed, 83 insertions(+)
 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..d07f9d5
--- /dev/null
+++ b/tests/throtl/004
@@ -0,0 +1,79 @@
+#!/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
+
+CG=/sys/fs/cgroup
+TEST_DIR=$CG/blktests_throtl
+devname=nullb0
+dev=""
+
+set_up_test() {
+	if ! _init_null_blk nr_devices=0; then
+		return 1;
+	fi
+
+	if ! _configure_null_blk $devname power=1; then
+		return 1;
+	fi
+
+	dev=$(cat /sys/block/$devname/dev)
+	echo +io > $CG/cgroup.subtree_control
+	mkdir $TEST_DIR
+
+	return 0;
+}
+
+clean_up_test() {
+	rmdir $TEST_DIR
+	echo -io > $CG/cgroup.subtree_control
+	_exit_null_blk
+}
+
+config_throtl() {
+	limit=$((1024 * 1024))
+	echo "$dev wbps=$limit" > $TEST_DIR/io.max
+}
+
+test_io() {
+	config_throtl
+
+	{
+		sleep 0.1
+		start_time=$(date +%s.%N)
+
+		dd of=/dev/$devname if=/dev/zero bs=10M count=1 oflag=direct status=none
+
+		end_time=$(date +%s.%N)
+		elapsed=$(echo "$end_time - $start_time" | bc)
+		printf "%.0f\n" "$elapsed"
+	} &
+
+	pid=$!
+	echo $! > $TEST_DIR/cgroup.procs
+
+	sleep 1
+	echo 0 > /sys/kernel/config/nullb/$devname/power
+	wait $pid
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! set_up_test; then
+		return 1;
+	fi
+
+	test_io
+
+	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
-- 
2.39.2


  parent reply	other threads:[~2024-04-16  2:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16  2:00 [PATCH blktests 0/5] add new tests for blk-throttle Yu Kuai
2024-04-16  2:00 ` [PATCH blktests 1/5] tests/throtl: add first test " Yu Kuai
2024-04-16  3:02   ` Chaitanya Kulkarni
2024-04-16  3:17     ` Yu Kuai
2024-04-16  3:37       ` Chaitanya Kulkarni
2024-04-16  2:00 ` [PATCH blktests 2/5] tests/throtl: add a new test 002 Yu Kuai
2024-04-16  2:00 ` [PATCH blktests 3/5] tests/throtl: add a new test 003 Yu Kuai
2024-04-16  2:00 ` Yu Kuai [this message]
2024-04-16  2:00 ` [PATCH blktests 5/5] tests/throtl: add a new test 005 Yu Kuai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240416020042.509291-5-yukuai1@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=saranyamohan@google.com \
    --cc=tj@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.