* [Qemu-devel] [PULL for-2.3 0/4] Block patches
@ 2015-03-27 10:20 Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 1/4] nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN) Stefan Hajnoczi
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-03-27 10:20 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi
The following changes since commit 4ad9e2b36e1e00fe5b96c3448ecd673e11c4d6d8:
Merge remote-tracking branch 'remotes/kraxel/tags/pull-gtk-20150326-1' into staging (2015-03-26 18:35:09 +0000)
are available in the git repository at:
git://github.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to da2cf4e80355e42fbaeb8bcfa2b07f5bceddd323:
block: Document blockdev-add's immaturity (2015-03-27 10:01:12 +0000)
----------------------------------------------------------------
----------------------------------------------------------------
Fam Zheng (2):
block: Fix unaligned zero write
qemu-iotests: Test unaligned 4k zero write
Markus Armbruster (1):
block: Document blockdev-add's immaturity
Stefan Weil (1):
nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
block.c | 45 ++++++++++++++++++++++++++++++++++++++------
hw/block/nvme.c | 2 +-
qapi/block-core.json | 4 ++++
qmp-commands.hx | 4 ++++
tests/qemu-iotests/033 | 47 +++++++++++++++++++++++++++++-----------------
tests/qemu-iotests/033.out | 26 +++++++++++++++++++++++++
6 files changed, 104 insertions(+), 24 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PULL for-2.3 1/4] nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
2015-03-27 10:20 [Qemu-devel] [PULL for-2.3 0/4] Block patches Stefan Hajnoczi
@ 2015-03-27 10:20 ` Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 2/4] block: Fix unaligned zero write Stefan Hajnoczi
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-03-27 10:20 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi, Stefan Weil
From: Stefan Weil <sw@weilnetz.de>
The shift operation on nlb gives a 32 bit result if no type cast is
applied. This bug was reported by Coverity.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Message-id: 1426348844-8793-1-git-send-email-sw@weilnetz.de
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/block/nvme.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 0f3dfb9..1e07166 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -222,7 +222,7 @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
- uint64_t data_size = nlb << data_shift;
+ uint64_t data_size = (uint64_t)nlb << data_shift;
uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS);
int is_write = rw->opcode == NVME_CMD_WRITE ? 1 : 0;
--
2.1.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PULL for-2.3 2/4] block: Fix unaligned zero write
2015-03-27 10:20 [Qemu-devel] [PULL for-2.3 0/4] Block patches Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 1/4] nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN) Stefan Hajnoczi
@ 2015-03-27 10:20 ` Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 3/4] qemu-iotests: Test unaligned 4k " Stefan Hajnoczi
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-03-27 10:20 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Fam Zheng, Stefan Hajnoczi
From: Fam Zheng <famz@redhat.com>
If the zero write is not aligned, bdrv_co_do_pwritev will segfault
because of accessing to the NULL qiov passed in by bdrv_co_write_zeroes.
Fix this by allocating a local qiov in bdrv_co_do_pwritev if the request
is not aligned. (In this case the padding iovs are necessary anyway, so
it doesn't hurt.)
Also add a check at the end of bdrv_co_do_pwritev to clear the zero flag
if padding is involved.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-id: 1427160230-4489-2-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block.c | 45 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index 0fe97de..f2f8ae7 100644
--- a/block.c
+++ b/block.c
@@ -3118,6 +3118,19 @@ out:
return ret;
}
+static inline uint64_t bdrv_get_align(BlockDriverState *bs)
+{
+ /* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */
+ return MAX(BDRV_SECTOR_SIZE, bs->request_alignment);
+}
+
+static inline bool bdrv_req_is_aligned(BlockDriverState *bs,
+ int64_t offset, size_t bytes)
+{
+ int64_t align = bdrv_get_align(bs);
+ return !(offset & (align - 1) || (bytes & (align - 1)));
+}
+
/*
* Handle a read request in coroutine context
*/
@@ -3128,8 +3141,7 @@ static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs,
BlockDriver *drv = bs->drv;
BdrvTrackedRequest req;
- /* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */
- uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment);
+ uint64_t align = bdrv_get_align(bs);
uint8_t *head_buf = NULL;
uint8_t *tail_buf = NULL;
QEMUIOVector local_qiov;
@@ -3371,8 +3383,7 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
BdrvRequestFlags flags)
{
BdrvTrackedRequest req;
- /* TODO Lift BDRV_SECTOR_SIZE restriction in BlockDriver interface */
- uint64_t align = MAX(BDRV_SECTOR_SIZE, bs->request_alignment);
+ uint64_t align = bdrv_get_align(bs);
uint8_t *head_buf = NULL;
uint8_t *tail_buf = NULL;
QEMUIOVector local_qiov;
@@ -3471,6 +3482,10 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,
bytes = ROUND_UP(bytes, align);
}
+ if (use_local_qiov) {
+ /* Local buffer may have non-zero data. */
+ flags &= ~BDRV_REQ_ZERO_WRITE;
+ }
ret = bdrv_aligned_pwritev(bs, &req, offset, bytes,
use_local_qiov ? &local_qiov : qiov,
flags);
@@ -3511,14 +3526,32 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
int64_t sector_num, int nb_sectors,
BdrvRequestFlags flags)
{
+ int ret;
+
trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors, flags);
if (!(bs->open_flags & BDRV_O_UNMAP)) {
flags &= ~BDRV_REQ_MAY_UNMAP;
}
+ if (bdrv_req_is_aligned(bs, sector_num << BDRV_SECTOR_BITS,
+ nb_sectors << BDRV_SECTOR_BITS)) {
+ ret = bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
+ BDRV_REQ_ZERO_WRITE | flags);
+ } else {
+ uint8_t *buf;
+ QEMUIOVector local_qiov;
+ size_t bytes = nb_sectors << BDRV_SECTOR_BITS;
- return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
- BDRV_REQ_ZERO_WRITE | flags);
+ buf = qemu_memalign(bdrv_opt_mem_align(bs), bytes);
+ memset(buf, 0, bytes);
+ qemu_iovec_init(&local_qiov, 1);
+ qemu_iovec_add(&local_qiov, buf, bytes);
+
+ ret = bdrv_co_do_writev(bs, sector_num, nb_sectors, &local_qiov,
+ BDRV_REQ_ZERO_WRITE | flags);
+ qemu_vfree(buf);
+ }
+ return ret;
}
/**
--
2.1.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PULL for-2.3 3/4] qemu-iotests: Test unaligned 4k zero write
2015-03-27 10:20 [Qemu-devel] [PULL for-2.3 0/4] Block patches Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 1/4] nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN) Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 2/4] block: Fix unaligned zero write Stefan Hajnoczi
@ 2015-03-27 10:20 ` Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 4/4] block: Document blockdev-add's immaturity Stefan Hajnoczi
2015-03-27 12:12 ` [Qemu-devel] [PULL for-2.3 0/4] Block patches Peter Maydell
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-03-27 10:20 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Fam Zheng, Stefan Hajnoczi
From: Fam Zheng <famz@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-id: 1427160230-4489-3-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/qemu-iotests/033 | 47 +++++++++++++++++++++++++++++-----------------
tests/qemu-iotests/033.out | 26 +++++++++++++++++++++++++
2 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033
index ea3351c..4008f10 100755
--- a/tests/qemu-iotests/033
+++ b/tests/qemu-iotests/033
@@ -46,26 +46,39 @@ _supported_os Linux
size=128M
_make_test_img $size
-echo
-echo "== preparing image =="
-$QEMU_IO -c "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io
-$QEMU_IO -c "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io
-$QEMU_IO -c "write -z 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
+do_test()
+{
+ local align=$1
+ local iocmd=$2
+ local img=$3
+ {
+ echo "open -o driver=$IMGFMT,file.align=$align blkdebug::$img"
+ echo $iocmd
+ } | $QEMU_IO
+}
-echo
-echo "== verifying patterns (1) =="
-$QEMU_IO -c "read -P 0xa 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
-$QEMU_IO -c "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
-$QEMU_IO -c "read -P 0xa 0x20400 0x200" "$TEST_IMG" | _filter_qemu_io
+for align in 512 4k; do
+ echo
+ echo "== preparing image =="
+ do_test $align "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io
+ do_test $align "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io
+ do_test $align "write -z 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
-echo
-echo "== rewriting zeroes =="
-$QEMU_IO -c "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
-$QEMU_IO -c "write -z 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
+ echo
+ echo "== verifying patterns (1) =="
+ do_test $align "read -P 0xa 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
+ do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
+ do_test $align "read -P 0xa 0x20400 0x200" "$TEST_IMG" | _filter_qemu_io
-echo
-echo "== verifying patterns (2) =="
-$QEMU_IO -c "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
+ echo
+ echo "== rewriting zeroes =="
+ do_test $align "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
+ do_test $align "write -z 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
+
+ echo
+ echo "== verifying patterns (2) =="
+ do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
+done
# success, all done
echo "*** done"
diff --git a/tests/qemu-iotests/033.out b/tests/qemu-iotests/033.out
index 41475ee..305949f 100644
--- a/tests/qemu-iotests/033.out
+++ b/tests/qemu-iotests/033.out
@@ -26,4 +26,30 @@ wrote 65536/65536 bytes at offset 65536
== verifying patterns (2) ==
read 131072/131072 bytes at offset 1024
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+== preparing image ==
+wrote 1024/1024 bytes at offset 512
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+wrote 1536/1536 bytes at offset 131072
+1.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+wrote 131072/131072 bytes at offset 1024
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+== verifying patterns (1) ==
+read 512/512 bytes at offset 512
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 131072/131072 bytes at offset 1024
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 512/512 bytes at offset 132096
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+== rewriting zeroes ==
+wrote 65536/65536 bytes at offset 65536
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+wrote 65536/65536 bytes at offset 65536
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+== verifying patterns (2) ==
+read 131072/131072 bytes at offset 1024
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
*** done
--
2.1.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PULL for-2.3 4/4] block: Document blockdev-add's immaturity
2015-03-27 10:20 [Qemu-devel] [PULL for-2.3 0/4] Block patches Stefan Hajnoczi
` (2 preceding siblings ...)
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 3/4] qemu-iotests: Test unaligned 4k " Stefan Hajnoczi
@ 2015-03-27 10:20 ` Stefan Hajnoczi
2015-03-27 12:12 ` [Qemu-devel] [PULL for-2.3 0/4] Block patches Peter Maydell
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-03-27 10:20 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Markus Armbruster, Stefan Hajnoczi
From: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1426858337-21423-1-git-send-email-armbru@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
qapi/block-core.json | 4 ++++
qmp-commands.hx | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/qapi/block-core.json b/qapi/block-core.json
index f525b04..7873084 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1721,6 +1721,10 @@
#
# Creates a new block device.
#
+# This command is still a work in progress. It doesn't support all
+# block drivers, it lacks a matching blockdev-del, and more. Stay
+# away from it unless you want to help with its development.
+#
# @options: block device options for the new device
#
# Since: 1.7
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 7f68760..3a42ad0 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3636,6 +3636,10 @@ blockdev-add
Add a block device.
+This command is still a work in progress. It doesn't support all
+block drivers, it lacks a matching blockdev-del, and more. Stay away
+from it unless you want to help with its development.
+
Arguments:
- "options": block driver options
--
2.1.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PULL for-2.3 0/4] Block patches
2015-03-27 10:20 [Qemu-devel] [PULL for-2.3 0/4] Block patches Stefan Hajnoczi
` (3 preceding siblings ...)
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 4/4] block: Document blockdev-add's immaturity Stefan Hajnoczi
@ 2015-03-27 12:12 ` Peter Maydell
4 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2015-03-27 12:12 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: QEMU Developers
On 27 March 2015 at 10:20, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> The following changes since commit 4ad9e2b36e1e00fe5b96c3448ecd673e11c4d6d8:
>
> Merge remote-tracking branch 'remotes/kraxel/tags/pull-gtk-20150326-1' into staging (2015-03-26 18:35:09 +0000)
>
> are available in the git repository at:
>
> git://github.com/stefanha/qemu.git tags/block-pull-request
>
> for you to fetch changes up to da2cf4e80355e42fbaeb8bcfa2b07f5bceddd323:
>
> block: Document blockdev-add's immaturity (2015-03-27 10:01:12 +0000)
>
> ----------------------------------------------------------------
Applied, thanks.
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-03-27 12:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-27 10:20 [Qemu-devel] [PULL for-2.3 0/4] Block patches Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 1/4] nvme: Fix unintentional integer overflow (OVERFLOW_BEFORE_WIDEN) Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 2/4] block: Fix unaligned zero write Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 3/4] qemu-iotests: Test unaligned 4k " Stefan Hajnoczi
2015-03-27 10:20 ` [Qemu-devel] [PULL for-2.3 4/4] block: Document blockdev-add's immaturity Stefan Hajnoczi
2015-03-27 12:12 ` [Qemu-devel] [PULL for-2.3 0/4] Block patches Peter Maydell
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).