[PATCH] block/elevator: Avoid a NULL pointer dereference in kobject_uevent()
Since commit a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller"), q->elevator will be set to NULL in blk_cleanup_queue() so that calling blk_cleanup_queue() and del_gendisk() in the order may trigger a NULL pointer dereference in kobject_uevent() because del_gendisk() will call the released q->elevator again by elv_unregister_queue() in some cases. See the following Call Trace: [ 423.693305] Call Trace: ... [ 423.693317] [] kobject_uevent+0xb/0x10 [ 423.693321] [] elv_unregister_queue+0x26/0x40 [ 423.693324] [] blk_unregister_queue+0xd8/0x130 [ 423.693327] [] del_gendisk+0x139/0x2a0 Signed-off-by: Xiao Yang --- block/elevator.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index 6a06b5d..2c88076 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -863,11 +863,13 @@ void elv_unregister_queue(struct request_queue *q) lockdep_assert_held(>sysfs_lock); if (q) { - struct elevator_queue *e = q->elevator; + if (q->elevator) { + struct elevator_queue *e = q->elevator; - kobject_uevent(>kobj, KOBJ_REMOVE); - kobject_del(>kobj); - e->registered = 0; + kobject_uevent(>kobj, KOBJ_REMOVE); + kobject_del(>kobj); + e->registered = 0; + } /* Re-enable throttling in case elevator disabled it */ wbt_enable_default(q); } -- 1.8.3.1
[PATCH blktests] Fix syntax error with bash v4.1.2(e.g RHEL6)
-v option is not supported by conditional expressions on bash v4.1.2, so we use -n instead of -v to fix this issue. Signed-off-by: xiao yang <yangx...@cn.fujitsu.com> --- check| 12 ++-- common/fio | 2 +- common/rc| 2 +- tests/meta/group | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/check b/check index 95d269a..7fbdc70 100755 --- a/check +++ b/check @@ -178,7 +178,7 @@ _output_status() { local test="$1" local status="$2" - if [[ -v DESCRIPTION ]]; then + if [[ -n $DESCRIPTION ]]; then printf '%-60s' "$test ($DESCRIPTION)" else printf '%-60s' "$test" @@ -215,7 +215,7 @@ _output_notrun() { } _output_last_test_run() { - if [[ -v TEST_DEV ]]; then + if [[ -n $TEST_DEV ]]; then _output_status "$TEST_NAME => $(basename "$TEST_DEV")" "" else _output_status "$TEST_NAME" "" @@ -240,7 +240,7 @@ _output_test_run() { tput cuu $((${#LAST_TEST_RUN[@]} - 3)) fi - if [[ -v TEST_DEV ]]; then + if [[ -n $TEST_DEV ]]; then _output_status "$TEST_NAME => $(basename "$TEST_DEV")" "${TEST_RUN[status]}ed" else _output_status "$TEST_NAME" "${TEST_RUN[status]}ed" @@ -270,7 +270,7 @@ _output_test_run() { } _cleanup() { - if [[ -v TMPDIR ]]; then + if [[ -n $TMPDIR ]]; then rm -rf "$TMPDIR" unset TMPDIR fi @@ -282,7 +282,7 @@ _cleanup() { unset TEST_DEV_QUEUE_SAVED["$key"] done - if [[ -v RESTORE_CPUS_ONLINE ]]; then + if [[ -n $RESTORE_CPUS_ONLINE ]]; then local cpu for cpu in "${!CPUS_ONLINE_SAVED[@]}"; do echo "${CPUS_ONLINE_SAVED["$cpu"]}" >"/sys/devices/system/cpu/cpu$cpu/online" @@ -599,7 +599,7 @@ while true; do esac done -if [[ QUICK_RUN -ne 0 && ! -v TIMEOUT ]]; then +if [[ QUICK_RUN -ne 0 && ! -n $TIMEOUT ]]; then _error "QUICK_RUN specified without TIMEOUT" fi diff --git a/common/fio b/common/fio index f5787b4..eb21038 100644 --- a/common/fio +++ b/common/fio @@ -160,7 +160,7 @@ _fio_perf() { # You should usually use this instead of calling fio directly. _run_fio() { local args=("--output=$TMPDIR/fio_perf" "--output-format=terse" "--terse-version=4" "--group_reporting=1") - if [[ -v TIMEOUT ]]; then + if [[ -n $TIMEOUT ]]; then args+=("--runtime=$TIMEOUT") fi fio "${args[@]}" "$@" diff --git a/common/rc b/common/rc index 09ce4ef..0fdab99 100644 --- a/common/rc +++ b/common/rc @@ -35,7 +35,7 @@ _error() { # for TIMEOUT / number of subtests. _divide_timeout() { local num_tests="$1" - if [[ -v TIMEOUT ]]; then + if [[ -n $TIMEOUT ]]; then ((TIMEOUT = (TIMEOUT + num_tests - 1) / num_tests)) fi } diff --git a/tests/meta/group b/tests/meta/group index 4281ea1..012a700 100644 --- a/tests/meta/group +++ b/tests/meta/group @@ -18,7 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. group_requires() { - if [[ -v META_REQUIRES_SKIP ]]; then + if [[ -n $META_REQUIRES_SKIP ]]; then SKIP_REASON="META_REQUIRES_SKIP was set" return 1 fi @@ -26,7 +26,7 @@ group_requires() { } group_device_requires() { - if [[ -v META_DEVICE_REQUIRES_SKIP ]]; then + if [[ -n $META_DEVICE_REQUIRES_SKIP ]]; then SKIP_REASON="META_DEVICE_REQUIRES_SKIP was set" return 1 fi -- 1.8.3.1
Re: [PATCH] generic/473: test return EBUSY from BLKRRPART for mounted whole-dev
On 2017/12/19 18:53, Johannes Thumshirn wrote: Xiao Yang<yangx...@cn.fujitsu.com> writes: [root@RHEL6U9GA_Intel64 blktests]# make make -C src all make[1]: Entering directory `/root/blktests/src' cc -Wall -o sg/syzkaller1 -O2 sg/syzkaller1.c sg/syzkaller1.c: In function ‘segv_handler’: sg/syzkaller1.c:118: warning: implicit declaration of function ‘__atomic_load_n’ sg/syzkaller1.c:118: error: ‘__ATOMIC_RELAXED’ undeclared (first use in this function) sg/syzkaller1.c:118: error: (Each undeclared identifier is reported only once sg/syzkaller1.c:118: error: for each function it appears in.) sg/syzkaller1.c: In function ‘syz_open_dev’: sg/syzkaller1.c:204: warning: implicit declaration of function ‘__atomic_fetch_add’ sg/syzkaller1.c:204: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function) sg/syzkaller1.c:204: warning: implicit declaration of function ‘__atomic_fetch_sub’ sg/syzkaller1.c: In function ‘test’: sg/syzkaller1.c:406: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function) make[1]: *** [sg/syzkaller1] Error 1 make[1]: Leaving directory `/root/blktests/src' make: *** [all] Error 2 --- It seems that __atomic_* functions are not available, and could you tell me how to fix the compiler error? It seems like gcc 4.4 is too old to handle __ATOMIC_*. The oldest version of gcc I tried was 4.8 which could handle this code perfectly fine. I think we need hacks in the makefile to see which compiler version we have and conditionally compile the code. Hi Johannes, Thanks for your quick reply. i will try to fix it as you suggested. Thanks, Xiao Yang Byte, Johannes
Re: [PATCH] generic/473: test return EBUSY from BLKRRPART for mounted whole-dev
On 2017/12/05 2:29, Omar Sandoval wrote: On Mon, Dec 04, 2017 at 05:48:36PM +0800, Xiao Yang wrote: On 2017/12/04 17:25, Eryu Guan wrote: On Mon, Dec 04, 2017 at 05:15:17PM +0800, Xiao Yang wrote: On 2017/12/04 16:29, Eryu Guan wrote: On Wed, Nov 29, 2017 at 08:02:26PM +0800, Xiao Yang wrote: If the entire block device is formatted with a filesystem and mounted, running "blockdev --rereadpt" should fail and return EBUSY instead of pass. Signed-off-by: Xiao Yang<yangx...@cn.fujitsu.com> As we have blktests[1] now, I think this may fit in blktests better? Hi Eryu, Do you think test cases which use scsi_debug module should be moved into blktests? (e.g. generic/108, generic/349, generic/350, generic/351) I don't think they need to be moved to blktests. Most other tests that take use of scsi_debug are for filesystem testing, e.g. generic/108. generic/349 generic/35[01] are a bit special, they were there before blktests was announced available, so they're in a special blockdev group and not in the auto group. If Omar agrees, I think they can be ported to blktests. Hi Eryu, Thanks for your explanation, and i will try to send it to blktests. Thanks, Xiao Yang I agree, the three tests Eryu mentioned and this new test would be a good fit for blktests. Let me know if you need any help porting, things are a little different from xfstests. Hi Omar, With gcc v4.4.7 on RHEL6, i got the following compiler error: -- [root@RHEL6U9GA_Intel64 blktests]# make make -C src all make[1]: Entering directory `/root/blktests/src' cc -Wall -o sg/syzkaller1 -O2 sg/syzkaller1.c sg/syzkaller1.c: In function ‘segv_handler’: sg/syzkaller1.c:118: warning: implicit declaration of function ‘__atomic_load_n’ sg/syzkaller1.c:118: error: ‘__ATOMIC_RELAXED’ undeclared (first use in this function) sg/syzkaller1.c:118: error: (Each undeclared identifier is reported only once sg/syzkaller1.c:118: error: for each function it appears in.) sg/syzkaller1.c: In function ‘syz_open_dev’: sg/syzkaller1.c:204: warning: implicit declaration of function ‘__atomic_fetch_add’ sg/syzkaller1.c:204: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function) sg/syzkaller1.c:204: warning: implicit declaration of function ‘__atomic_fetch_sub’ sg/syzkaller1.c: In function ‘test’: sg/syzkaller1.c:406: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function) make[1]: *** [sg/syzkaller1] Error 1 make[1]: Leaving directory `/root/blktests/src' make: *** [all] Error 2 --- It seems that __atomic_* functions are not available, and could you tell me how to fix the compiler error? Thanks, Xiao Yang
[PATCH blktests] block/013: Add test for BLKRRPART ioctl
If the entire block device is formatted with a filesystem and mounted, running "blockdev --rereadpt" should fail and return EBUSY instead of pass. Signed-off-by: xiao yang <yangx...@cn.fujitsu.com> --- tests/block/013 | 62 + tests/block/013.out | 3 +++ 2 files changed, 65 insertions(+) create mode 100755 tests/block/013 create mode 100644 tests/block/013.out diff --git a/tests/block/013 b/tests/block/013 new file mode 100755 index 000..77ae55c --- /dev/null +++ b/tests/block/013 @@ -0,0 +1,62 @@ +#!/bin/bash +# +# If the entire block device is formatted with a filesystem and +# mounted, running "blockdev --rereadpt" should fail and return +# EBUSY. On buggy kernel, it passes unexpectedly. +# +# Regression test for commit 77032ca66f86 ("Return EBUSY from +# BLKRRPART for mounted whole-dev fs"). +# +# Copyright (c) 2017 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang <yangx...@cn.fujitsu.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +DESCRIPTION="test return EBUSY from BLKRRPART for mounted whole-dev" +QUICK=1 + +requires() { + _have_program mkfs.ext3 +} + +test_device() { + echo "Running ${TEST_NAME}" + + rm -f "$FULL" + mkdir "$TMPDIR/mntpoint" + + # Format + mkfs.ext3 -F "$TEST_DEV" >> "$FULL" 2>&1 + + # Mount + mount "$TEST_DEV" "$TMPDIR/mntpoint" + + # Check mounted whole-dev + local out=$(blockdev --rereadpt "$TEST_DEV" 2>&1) + echo $out | grep -q "Device or resource busy" + if [ $? -eq 0 ]; then + echo "Return EBUSY for mounted whole-dev" + else + echo "Don't return EBUSY for mounted whole-dev" + fi + + echo $out >> "$FULL" + + # Umount + umount "$TMPDIR/mntpoint" + + rm -rf "$TMPDIR/mntpoint" + + echo "Test complete" +} diff --git a/tests/block/013.out b/tests/block/013.out new file mode 100644 index 000..74d1d08 --- /dev/null +++ b/tests/block/013.out @@ -0,0 +1,3 @@ +Running block/013 +Return EBUSY for mounted whole-dev +Test complete -- 1.8.3.1
Re: [PATCH] generic/473: test return EBUSY from BLKRRPART for mounted whole-dev
On 2017/12/04 17:25, Eryu Guan wrote: On Mon, Dec 04, 2017 at 05:15:17PM +0800, Xiao Yang wrote: On 2017/12/04 16:29, Eryu Guan wrote: On Wed, Nov 29, 2017 at 08:02:26PM +0800, Xiao Yang wrote: If the entire block device is formatted with a filesystem and mounted, running "blockdev --rereadpt" should fail and return EBUSY instead of pass. Signed-off-by: Xiao Yang<yangx...@cn.fujitsu.com> As we have blktests[1] now, I think this may fit in blktests better? Hi Eryu, Do you think test cases which use scsi_debug module should be moved into blktests? (e.g. generic/108, generic/349, generic/350, generic/351) I don't think they need to be moved to blktests. Most other tests that take use of scsi_debug are for filesystem testing, e.g. generic/108. generic/349 generic/35[01] are a bit special, they were there before blktests was announced available, so they're in a special blockdev group and not in the auto group. If Omar agrees, I think they can be ported to blktests. Hi Eryu, Thanks for your explanation, and i will try to send it to blktests. Thanks, Xiao Yang Thanks, Eryu
Re: [PATCH] generic/473: test return EBUSY from BLKRRPART for mounted whole-dev
On 2017/12/04 16:29, Eryu Guan wrote: On Wed, Nov 29, 2017 at 08:02:26PM +0800, Xiao Yang wrote: If the entire block device is formatted with a filesystem and mounted, running "blockdev --rereadpt" should fail and return EBUSY instead of pass. Signed-off-by: Xiao Yang<yangx...@cn.fujitsu.com> As we have blktests[1] now, I think this may fit in blktests better? Hi Eryu, Do you think test cases which use scsi_debug module should be moved into blktests? (e.g. generic/108, generic/349, generic/350, generic/351) Thanks, Xiao Yang Thanks, Eryu [1] https://github.com/osandov/blktests --- tests/generic/473 | 83 +++ tests/generic/473.out | 2 ++ tests/generic/group | 1 + 3 files changed, 86 insertions(+) create mode 100755 tests/generic/473 create mode 100644 tests/generic/473.out diff --git a/tests/generic/473 b/tests/generic/473 new file mode 100755 index 000..d7998cd --- /dev/null +++ b/tests/generic/473 @@ -0,0 +1,83 @@ +#! /bin/bash +# FS QA Test No. 473 +# +# Regression test for commit: +# 77032ca ("Return EBUSY from BLKRRPART for mounted whole-dev fs") +# +# If the entire block device is formatted with a filesystem and +# mounted, running "blockdev --rereadpt" should fail and return +# EBUSY. On buggy kernel, it passes unexpectedly. +# +#--- +# Copyright (c) 2017 FUJITSU LIMITED. All rights reserved. +# Author: Xiao Yang<yangx...@cn.fujitsu.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#--- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmpdir=`mktemp -d` +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 7 15 + +_cleanup() +{ + # Umount + $UMOUNT_PROG $tmpdir>>$seqres.full 2>&1 + # Destroy device +_put_scsi_debug_dev + rm -rf $tmpdir +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/scsi_debug + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_os Linux +_require_scsi_debug + +# Create and format +test_dev=`_get_scsi_debug_dev` +_mkfs_dev $test_dev>>$seqres.full 2>&1 + +# Mount and check mounted whole-dev +_mount $test_dev $tmpdir + +out=$(blockdev --rereadpt $test_dev 2>&1) +res=$? + +echo $out | grep -q "Unknown command"&& \ + _notrun "blockdev --rereadpt was not supported" + +[ $res -eq 0 ]&& _fail "blockdev --rereadpt passed when checking mounted whole-dev" + +echo $out | grep -q "Device or resource busy" || \ + _fail "blockdev --rereadpt returned unexpected error when checking mounted whole-dev" + +echo $out>> $seqres.full + +echo "Silence is golden" + +# success, all done +status=0 +exit diff --git a/tests/generic/473.out b/tests/generic/473.out new file mode 100644 index 000..854fbcd --- /dev/null +++ b/tests/generic/473.out @@ -0,0 +1,2 @@ +QA output created by 473 +Silence is golden diff --git a/tests/generic/group b/tests/generic/group index 6c3bb03..54b9404 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -472,3 +472,4 @@ 467 auto quick exportfs 468 shutdown auto quick metadata 469 auto quick +473 auto quick blockdev -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html .