* [PATCH 0/5] file-posix: Clean up and fix zoned checks
@ 2023-08-24 15:53 Hanna Czenczek
2023-08-24 15:53 ` [PATCH 1/5] file-posix: Clear bs->bl.zoned on error Hanna Czenczek
` (6 more replies)
0 siblings, 7 replies; 13+ messages in thread
From: Hanna Czenczek @ 2023-08-24 15:53 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Hanna Czenczek, Kevin Wolf, Stefan Hajnoczi, Sam Li
Hi,
As presented in [1] there is a bug in the zone code in raw_co_prw(),
specifically we don’t check whether there actually is zone information
before running code that assumes there is (and thus we run into a
division by zero). This has now also been reported in [2].
I believe the solution [1] is incomplete, though, which is why I’m
sending this separate series: I don’t think checking bs->wps and/or
bs->bl.zone_size to determine whether there is zone information is
right; for example, we do not have raw_refresh_zoned_limits() clear
those values if on a refresh, zone information were to disappear.
It is also weird that we separate checking bs->wps and bs->bl.zone_size
at all; raw_refresh_zoned_limits() seems to intend to ensure that either
we have information with non-NULL bs->wps and non-zero bs->bl.zone_size,
or we don’t.
I think we should have a single flag that tells whether we have valid
information or not, and it looks to me like bs->bl.zoned != BLK_Z_NONE
is the condition that fits best.
Patch 1 ensures that raw_refresh_zoned_limits() will set bs->bl.zoned to
BLK_Z_NONE on error, so that we can actually be sure that this condition
tells us whether we have valid information or not.
Patch 2 unifies all conditional checks for zone information to use
bs->bl.zoned != BLK_Z_NONE.
Patch 3 is the I/O error path fix, which is not really different from
[1].
Patch 4 does a bit of clean-up.
Patch 5 adds a regression test.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2023-06/msg01742.html
[2] https://bugzilla.redhat.com/show_bug.cgi?id=2234374
Hanna Czenczek (5):
file-posix: Clear bs->bl.zoned on error
file-posix: Check bs->bl.zoned for zone info
file-posix: Fix zone update in I/O error path
file-posix: Simplify raw_co_prw's 'out' zone code
tests/file-io-error: New test
block/file-posix.c | 42 +++++----
tests/qemu-iotests/tests/file-io-error | 99 ++++++++++++++++++++++
tests/qemu-iotests/tests/file-io-error.out | 31 +++++++
3 files changed, 150 insertions(+), 22 deletions(-)
create mode 100755 tests/qemu-iotests/tests/file-io-error
create mode 100644 tests/qemu-iotests/tests/file-io-error.out
--
2.41.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/5] file-posix: Clear bs->bl.zoned on error
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
@ 2023-08-24 15:53 ` Hanna Czenczek
2023-08-24 16:57 ` Sam Li
2023-08-24 15:53 ` [PATCH 2/5] file-posix: Check bs->bl.zoned for zone info Hanna Czenczek
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hanna Czenczek @ 2023-08-24 15:53 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Hanna Czenczek, Kevin Wolf, Stefan Hajnoczi, Sam Li
bs->bl.zoned is what indicates whether the zone information is present
and valid; it is the only thing that raw_refresh_zoned_limits() sets if
CONFIG_BLKZONED is not defined, and it is also the only thing that it
sets if CONFIG_BLKZONED is defined, but there are no zones.
Make sure that it is always set to BLK_Z_NONE if there is an error
anywhere in raw_refresh_zoned_limits() so that we do not accidentally
announce zones while our information is incomplete or invalid.
This also fixes a memory leak in the last error path in
raw_refresh_zoned_limits().
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
---
block/file-posix.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index b16e9c21a1..2b88b9eefa 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1412,11 +1412,9 @@ static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st,
BlockZoneModel zoned;
int ret;
- bs->bl.zoned = BLK_Z_NONE;
-
ret = get_sysfs_zoned_model(st, &zoned);
if (ret < 0 || zoned == BLK_Z_NONE) {
- return;
+ goto no_zoned;
}
bs->bl.zoned = zoned;
@@ -1437,10 +1435,10 @@ static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st,
if (ret < 0) {
error_setg_errno(errp, -ret, "Unable to read chunk_sectors "
"sysfs attribute");
- return;
+ goto no_zoned;
} else if (!ret) {
error_setg(errp, "Read 0 from chunk_sectors sysfs attribute");
- return;
+ goto no_zoned;
}
bs->bl.zone_size = ret << BDRV_SECTOR_BITS;
@@ -1448,10 +1446,10 @@ static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st,
if (ret < 0) {
error_setg_errno(errp, -ret, "Unable to read nr_zones "
"sysfs attribute");
- return;
+ goto no_zoned;
} else if (!ret) {
error_setg(errp, "Read 0 from nr_zones sysfs attribute");
- return;
+ goto no_zoned;
}
bs->bl.nr_zones = ret;
@@ -1472,10 +1470,15 @@ static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st,
ret = get_zones_wp(bs, s->fd, 0, bs->bl.nr_zones, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "report wps failed");
- bs->wps = NULL;
- return;
+ goto no_zoned;
}
qemu_co_mutex_init(&bs->wps->colock);
+ return;
+
+no_zoned:
+ bs->bl.zoned = BLK_Z_NONE;
+ g_free(bs->wps);
+ bs->wps = NULL;
}
#else /* !defined(CONFIG_BLKZONED) */
static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st,
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/5] file-posix: Check bs->bl.zoned for zone info
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
2023-08-24 15:53 ` [PATCH 1/5] file-posix: Clear bs->bl.zoned on error Hanna Czenczek
@ 2023-08-24 15:53 ` Hanna Czenczek
2023-08-24 16:58 ` Sam Li
2023-08-24 15:53 ` [PATCH 3/5] file-posix: Fix zone update in I/O error path Hanna Czenczek
` (4 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hanna Czenczek @ 2023-08-24 15:53 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Hanna Czenczek, Kevin Wolf, Stefan Hajnoczi, Sam Li
Instead of checking bs->wps or bs->bl.zone_size for whether zone
information is present, check bs->bl.zoned. That is the flag that
raw_refresh_zoned_limits() reliably sets to indicate zone support. If
it is set to something other than BLK_Z_NONE, other values and objects
like bs->wps and bs->bl.zone_size must be non-null/zero and valid; if it
is not, we cannot rely on their validity.
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
---
block/file-posix.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 2b88b9eefa..46e22403fe 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2455,9 +2455,10 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,
if (fd_open(bs) < 0)
return -EIO;
#if defined(CONFIG_BLKZONED)
- if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) && bs->wps) {
+ if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
+ bs->bl.zoned != BLK_Z_NONE) {
qemu_co_mutex_lock(&bs->wps->colock);
- if (type & QEMU_AIO_ZONE_APPEND && bs->bl.zone_size) {
+ if (type & QEMU_AIO_ZONE_APPEND) {
int index = offset / bs->bl.zone_size;
offset = bs->wps->wp[index];
}
@@ -2508,8 +2509,8 @@ out:
{
BlockZoneWps *wps = bs->wps;
if (ret == 0) {
- if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND))
- && wps && bs->bl.zone_size) {
+ if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
+ bs->bl.zoned != BLK_Z_NONE) {
uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];
if (!BDRV_ZT_IS_CONV(*wp)) {
if (type & QEMU_AIO_ZONE_APPEND) {
@@ -2529,7 +2530,8 @@ out:
}
}
- if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) && wps) {
+ if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
+ bs->blk.zoned != BLK_Z_NONE) {
qemu_co_mutex_unlock(&wps->colock);
}
}
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/5] file-posix: Fix zone update in I/O error path
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
2023-08-24 15:53 ` [PATCH 1/5] file-posix: Clear bs->bl.zoned on error Hanna Czenczek
2023-08-24 15:53 ` [PATCH 2/5] file-posix: Check bs->bl.zoned for zone info Hanna Czenczek
@ 2023-08-24 15:53 ` Hanna Czenczek
2023-08-24 17:17 ` Sam Li
2023-08-24 15:53 ` [PATCH 4/5] file-posix: Simplify raw_co_prw's 'out' zone code Hanna Czenczek
` (3 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hanna Czenczek @ 2023-08-24 15:53 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Hanna Czenczek, Kevin Wolf, Stefan Hajnoczi, Sam Li
We must check that zone information is present before running
update_zones_wp().
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2234374
Fixes: Coverity CID 1512459
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
---
block/file-posix.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 46e22403fe..a050682e97 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2525,7 +2525,8 @@ out:
}
}
} else {
- if (type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) {
+ if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
+ bs->bl.zoned != BLK_Z_NONE) {
update_zones_wp(bs, s->fd, 0, 1);
}
}
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/5] file-posix: Simplify raw_co_prw's 'out' zone code
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
` (2 preceding siblings ...)
2023-08-24 15:53 ` [PATCH 3/5] file-posix: Fix zone update in I/O error path Hanna Czenczek
@ 2023-08-24 15:53 ` Hanna Czenczek
2023-08-24 17:18 ` Sam Li
2023-08-24 15:53 ` [PATCH 5/5] tests/file-io-error: New test Hanna Czenczek
` (2 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Hanna Czenczek @ 2023-08-24 15:53 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Hanna Czenczek, Kevin Wolf, Stefan Hajnoczi, Sam Li
We duplicate the same condition three times here, pull it out to the top
level.
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
---
block/file-posix.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index a050682e97..aa89789737 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2506,11 +2506,10 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,
out:
#if defined(CONFIG_BLKZONED)
-{
- BlockZoneWps *wps = bs->wps;
- if (ret == 0) {
- if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
- bs->bl.zoned != BLK_Z_NONE) {
+ if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
+ bs->bl.zoned != BLK_Z_NONE) {
+ BlockZoneWps *wps = bs->wps;
+ if (ret == 0) {
uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];
if (!BDRV_ZT_IS_CONV(*wp)) {
if (type & QEMU_AIO_ZONE_APPEND) {
@@ -2523,19 +2522,12 @@ out:
*wp = offset + bytes;
}
}
- }
- } else {
- if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
- bs->bl.zoned != BLK_Z_NONE) {
+ } else {
update_zones_wp(bs, s->fd, 0, 1);
}
- }
- if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) &&
- bs->blk.zoned != BLK_Z_NONE) {
qemu_co_mutex_unlock(&wps->colock);
}
-}
#endif
return ret;
}
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/5] tests/file-io-error: New test
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
` (3 preceding siblings ...)
2023-08-24 15:53 ` [PATCH 4/5] file-posix: Simplify raw_co_prw's 'out' zone code Hanna Czenczek
@ 2023-08-24 15:53 ` Hanna Czenczek
2023-08-24 16:53 ` [PATCH 0/5] file-posix: Clean up and fix zoned checks Sam Li
2023-09-21 18:21 ` Michael Tokarev
6 siblings, 0 replies; 13+ messages in thread
From: Hanna Czenczek @ 2023-08-24 15:53 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Hanna Czenczek, Kevin Wolf, Stefan Hajnoczi, Sam Li
This is a regression test for
https://bugzilla.redhat.com/show_bug.cgi?id=2234374.
All this test needs to do is trigger an I/O error inside of file-posix
(specifically raw_co_prw()). One reliable way to do this without
requiring special privileges is to use a FUSE export, which allows us to
inject any error that we want, e.g. via blkdebug.
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
---
tests/qemu-iotests/tests/file-io-error | 99 ++++++++++++++++++++++
tests/qemu-iotests/tests/file-io-error.out | 31 +++++++
2 files changed, 130 insertions(+)
create mode 100755 tests/qemu-iotests/tests/file-io-error
create mode 100644 tests/qemu-iotests/tests/file-io-error.out
diff --git a/tests/qemu-iotests/tests/file-io-error b/tests/qemu-iotests/tests/file-io-error
new file mode 100755
index 0000000000..a47ad0a678
--- /dev/null
+++ b/tests/qemu-iotests/tests/file-io-error
@@ -0,0 +1,99 @@
+#!/usr/bin/env bash
+# group: rw
+#
+# Produce an I/O error in file-posix, and hope that it is not catastrophic.
+# Regression test for: https://bugzilla.redhat.com/show_bug.cgi?id=2234374
+#
+# Copyright (C) 2023 Red Hat, Inc.
+#
+# 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 2 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/>.
+#
+
+seq=$(basename "$0")
+echo "QA output created by $seq"
+
+status=1 # failure is the default!
+
+_cleanup()
+{
+ _cleanup_qemu
+ rm -f "$TEST_DIR/fuse-export"
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ../common.rc
+. ../common.filter
+. ../common.qemu
+
+# Format-agnostic (we do not use any), but we do test the file protocol
+_supported_proto file
+_require_drivers blkdebug null-co
+
+# This is a regression test of a bug in which flie-posix would access zone
+# information in case of an I/O error even when there is no zone information,
+# resulting in a division by zero.
+# To reproduce the problem, we need to trigger an I/O error inside of
+# file-posix, which can be done (rootless) by providing a FUSE export that
+# presents only errors when accessed.
+
+_launch_qemu
+_send_qemu_cmd $QEMU_HANDLE \
+ "{'execute': 'qmp_capabilities'}" \
+
+_send_qemu_cmd $QEMU_HANDLE \
+ "{'execute': 'blockdev-add',
+ 'arguments': {
+ 'driver': 'blkdebug',
+ 'node-name': 'node0',
+ 'inject-error': [{'event': 'none'}],
+ 'image': {
+ 'driver': 'null-co'
+ }
+ }}" \
+ 'return'
+
+# FUSE mountpoint must exist and be a regular file
+touch "$TEST_DIR/fuse-export"
+
+_send_qemu_cmd $QEMU_HANDLE \
+ "{'execute': 'block-export-add',
+ 'arguments': {
+ 'id': 'exp0',
+ 'type': 'fuse',
+ 'node-name': 'node0',
+ 'mountpoint': '$TEST_DIR/fuse-export',
+ 'writable': true
+ }}" \
+ 'return'
+
+echo
+# This should fail, but gracefully, i.e. just print an I/O error, not crash.
+$QEMU_IO -f file -c 'write 0 64M' "$TEST_DIR/fuse-export" | _filter_qemu_io
+echo
+
+_send_qemu_cmd $QEMU_HANDLE \
+ "{'execute': 'block-export-del',
+ 'arguments': {'id': 'exp0'}}" \
+ 'return'
+
+_send_qemu_cmd $QEMU_HANDLE \
+ "{'execute': 'blockdev-del',
+ 'arguments': {'node-name': 'node0'}}" \
+ 'return'
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/tests/file-io-error.out b/tests/qemu-iotests/tests/file-io-error.out
new file mode 100644
index 0000000000..4e6758c62c
--- /dev/null
+++ b/tests/qemu-iotests/tests/file-io-error.out
@@ -0,0 +1,31 @@
+QA output created by file-io-error
+{'execute': 'qmp_capabilities'}
+{'execute': 'blockdev-add',
+ 'arguments': {
+ 'driver': 'blkdebug',
+ 'node-name': 'node0',
+ 'inject-error': [{'event': 'none'}],
+ 'image': {
+ 'driver': 'null-co'
+ }
+ }}
+{"return": {}}
+{'execute': 'block-export-add',
+ 'arguments': {
+ 'id': 'exp0',
+ 'type': 'fuse',
+ 'node-name': 'node0',
+ 'mountpoint': 'TEST_DIR/fuse-export',
+ 'writable': true
+ }}
+{"return": {}}
+
+write failed: Input/output error
+
+{'execute': 'block-export-del',
+ 'arguments': {'id': 'exp0'}}
+{"return": {}}
+{'execute': 'blockdev-del',
+ 'arguments': {'node-name': 'node0'}}
+{"return": {}}
+*** done
--
2.41.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 0/5] file-posix: Clean up and fix zoned checks
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
` (4 preceding siblings ...)
2023-08-24 15:53 ` [PATCH 5/5] tests/file-io-error: New test Hanna Czenczek
@ 2023-08-24 16:53 ` Sam Li
2023-09-21 18:21 ` Michael Tokarev
6 siblings, 0 replies; 13+ messages in thread
From: Sam Li @ 2023-08-24 16:53 UTC (permalink / raw)
To: Hanna Czenczek; +Cc: qemu-block, qemu-devel, Kevin Wolf, Stefan Hajnoczi
Hi Hanna,
Hanna Czenczek <hreitz@redhat.com> 于2023年8月24日周四 23:53写道:
>
> Hi,
>
> As presented in [1] there is a bug in the zone code in raw_co_prw(),
> specifically we don’t check whether there actually is zone information
> before running code that assumes there is (and thus we run into a
> division by zero). This has now also been reported in [2].
Thanks for catching the bugs and your work.
>
> I believe the solution [1] is incomplete, though, which is why I’m
> sending this separate series: I don’t think checking bs->wps and/or
> bs->bl.zone_size to determine whether there is zone information is
> right; for example, we do not have raw_refresh_zoned_limits() clear
> those values if on a refresh, zone information were to disappear.
>
> It is also weird that we separate checking bs->wps and bs->bl.zone_size
> at all; raw_refresh_zoned_limits() seems to intend to ensure that either
> we have information with non-NULL bs->wps and non-zero bs->bl.zone_size,
> or we don’t.
>
> I think we should have a single flag that tells whether we have valid
> information or not, and it looks to me like bs->bl.zoned != BLK_Z_NONE
> is the condition that fits best.
The former way only checks zone information when it is being used to
avoid divide-by-zero or nullptr errors. Putting the error path with
non-zoned model implies a zoned device must have non-zero zone size
and allocated write pointers. Given that no other parts are changing
the zone_size to 0 and free wps, It does simplify the code path.
Thanks,
Sam
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/5] file-posix: Clear bs->bl.zoned on error
2023-08-24 15:53 ` [PATCH 1/5] file-posix: Clear bs->bl.zoned on error Hanna Czenczek
@ 2023-08-24 16:57 ` Sam Li
0 siblings, 0 replies; 13+ messages in thread
From: Sam Li @ 2023-08-24 16:57 UTC (permalink / raw)
To: Hanna Czenczek; +Cc: qemu-block, qemu-devel, Kevin Wolf, Stefan Hajnoczi
Hanna Czenczek <hreitz@redhat.com> 于2023年8月24日周四 23:53写道:
>
> bs->bl.zoned is what indicates whether the zone information is present
> and valid; it is the only thing that raw_refresh_zoned_limits() sets if
> CONFIG_BLKZONED is not defined, and it is also the only thing that it
> sets if CONFIG_BLKZONED is defined, but there are no zones.
>
> Make sure that it is always set to BLK_Z_NONE if there is an error
> anywhere in raw_refresh_zoned_limits() so that we do not accidentally
> announce zones while our information is incomplete or invalid.
>
> This also fixes a memory leak in the last error path in
> raw_refresh_zoned_limits().
>
> Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
> ---
> block/file-posix.c | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
Reviewed-by: Sam Li <faithilikerun@gmail.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/5] file-posix: Check bs->bl.zoned for zone info
2023-08-24 15:53 ` [PATCH 2/5] file-posix: Check bs->bl.zoned for zone info Hanna Czenczek
@ 2023-08-24 16:58 ` Sam Li
0 siblings, 0 replies; 13+ messages in thread
From: Sam Li @ 2023-08-24 16:58 UTC (permalink / raw)
To: Hanna Czenczek; +Cc: qemu-block, qemu-devel, Kevin Wolf, Stefan Hajnoczi
Hanna Czenczek <hreitz@redhat.com> 于2023年8月24日周四 23:53写道:
>
> Instead of checking bs->wps or bs->bl.zone_size for whether zone
> information is present, check bs->bl.zoned. That is the flag that
> raw_refresh_zoned_limits() reliably sets to indicate zone support. If
> it is set to something other than BLK_Z_NONE, other values and objects
> like bs->wps and bs->bl.zone_size must be non-null/zero and valid; if it
> is not, we cannot rely on their validity.
>
> Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
> ---
> block/file-posix.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
Reviewed-by: Sam Li <faithilikerun@gmail.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/5] file-posix: Fix zone update in I/O error path
2023-08-24 15:53 ` [PATCH 3/5] file-posix: Fix zone update in I/O error path Hanna Czenczek
@ 2023-08-24 17:17 ` Sam Li
0 siblings, 0 replies; 13+ messages in thread
From: Sam Li @ 2023-08-24 17:17 UTC (permalink / raw)
To: Hanna Czenczek; +Cc: qemu-block, qemu-devel, Kevin Wolf, Stefan Hajnoczi
Hanna Czenczek <hreitz@redhat.com> 于2023年8月24日周四 23:53写道:
>
> We must check that zone information is present before running
> update_zones_wp().
>
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2234374
> Fixes: Coverity CID 1512459
> Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
> ---
> block/file-posix.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Sam Li <faithilikerun@gmail.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 4/5] file-posix: Simplify raw_co_prw's 'out' zone code
2023-08-24 15:53 ` [PATCH 4/5] file-posix: Simplify raw_co_prw's 'out' zone code Hanna Czenczek
@ 2023-08-24 17:18 ` Sam Li
0 siblings, 0 replies; 13+ messages in thread
From: Sam Li @ 2023-08-24 17:18 UTC (permalink / raw)
To: Hanna Czenczek; +Cc: qemu-block, qemu-devel, Kevin Wolf, Stefan Hajnoczi
Hanna Czenczek <hreitz@redhat.com> 于2023年8月24日周四 23:53写道:
>
> We duplicate the same condition three times here, pull it out to the top
> level.
>
> Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
> ---
> block/file-posix.c | 18 +++++-------------
> 1 file changed, 5 insertions(+), 13 deletions(-)
Reviewed-by: Sam Li <faithilikerun@gmail.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/5] file-posix: Clean up and fix zoned checks
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
` (5 preceding siblings ...)
2023-08-24 16:53 ` [PATCH 0/5] file-posix: Clean up and fix zoned checks Sam Li
@ 2023-09-21 18:21 ` Michael Tokarev
2023-09-21 18:52 ` Michael Tokarev
6 siblings, 1 reply; 13+ messages in thread
From: Michael Tokarev @ 2023-09-21 18:21 UTC (permalink / raw)
To: Hanna Czenczek, qemu-block
Cc: qemu-devel, Kevin Wolf, Stefan Hajnoczi, Sam Li
24.08.2023 18:53, Hanna Czenczek wrote:
> Hi,
>
> As presented in [1] there is a bug in the zone code in raw_co_prw(),
> specifically we don’t check whether there actually is zone information
> before running code that assumes there is (and thus we run into a
> division by zero). This has now also been reported in [2].
>
> I believe the solution [1] is incomplete, though, which is why I’m
> sending this separate series: I don’t think checking bs->wps and/or
> bs->bl.zone_size to determine whether there is zone information is
> right; for example, we do not have raw_refresh_zoned_limits() clear
> those values if on a refresh, zone information were to disappear.
>
> It is also weird that we separate checking bs->wps and bs->bl.zone_size
> at all; raw_refresh_zoned_limits() seems to intend to ensure that either
> we have information with non-NULL bs->wps and non-zero bs->bl.zone_size,
> or we don’t.
>
> I think we should have a single flag that tells whether we have valid
> information or not, and it looks to me like bs->bl.zoned != BLK_Z_NONE
> is the condition that fits best.
>
> Patch 1 ensures that raw_refresh_zoned_limits() will set bs->bl.zoned to
> BLK_Z_NONE on error, so that we can actually be sure that this condition
> tells us whether we have valid information or not.
>
> Patch 2 unifies all conditional checks for zone information to use
> bs->bl.zoned != BLK_Z_NONE.
>
> Patch 3 is the I/O error path fix, which is not really different from
> [1].
>
> Patch 4 does a bit of clean-up.
>
> Patch 5 adds a regression test.
>
>
> [1] https://lists.nongnu.org/archive/html/qemu-devel/2023-06/msg01742.html
> [2] https://bugzilla.redhat.com/show_bug.cgi?id=2234374
Is this stable-worthy (at least 1-3)? From the bug description it smells
like it should be in 8.1.x, or maybe whole series.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/5] file-posix: Clean up and fix zoned checks
2023-09-21 18:21 ` Michael Tokarev
@ 2023-09-21 18:52 ` Michael Tokarev
0 siblings, 0 replies; 13+ messages in thread
From: Michael Tokarev @ 2023-09-21 18:52 UTC (permalink / raw)
To: Hanna Czenczek, qemu-block
Cc: qemu-devel, Kevin Wolf, Stefan Hajnoczi, Sam Li
21.09.2023 21:21, Michael Tokarev wrote:
..
> Is this stable-worthy (at least 1-3)? From the bug description it smells
> like it should be in 8.1.x, or maybe whole series.
N/M, this whole patchset has been Cc'd qemu-stable already.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-09-21 18:53 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24 15:53 [PATCH 0/5] file-posix: Clean up and fix zoned checks Hanna Czenczek
2023-08-24 15:53 ` [PATCH 1/5] file-posix: Clear bs->bl.zoned on error Hanna Czenczek
2023-08-24 16:57 ` Sam Li
2023-08-24 15:53 ` [PATCH 2/5] file-posix: Check bs->bl.zoned for zone info Hanna Czenczek
2023-08-24 16:58 ` Sam Li
2023-08-24 15:53 ` [PATCH 3/5] file-posix: Fix zone update in I/O error path Hanna Czenczek
2023-08-24 17:17 ` Sam Li
2023-08-24 15:53 ` [PATCH 4/5] file-posix: Simplify raw_co_prw's 'out' zone code Hanna Czenczek
2023-08-24 17:18 ` Sam Li
2023-08-24 15:53 ` [PATCH 5/5] tests/file-io-error: New test Hanna Czenczek
2023-08-24 16:53 ` [PATCH 0/5] file-posix: Clean up and fix zoned checks Sam Li
2023-09-21 18:21 ` Michael Tokarev
2023-09-21 18:52 ` Michael Tokarev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).