dma-helpers: Fix too long qiov
PATCH 1/1 dma-helpers: Fix too long qiov
If the size of the scatter/gather list isn't a multiple of 512, the number of sectors for the block layer request is rounded down, resulting in a qiov that doesn't match the request length. Truncate the qiov to the new length of the request.
This fixes the IDE qtest case /x86_64/ide/bmdma/short_prdt.
--- dma-helpers.c | 4 ++++ include/qemu-common.h | 1 + util/iov.c | 13 +++++++++++++ 3 files changed, 18 insertions(+)
dma-helpers.c +4 -0
@@ -170,6 +170,10 @@ static void dma_bdrv_cb(void *opaque, int ret)return ; } +if (dbs->iov.size & ~BDRV_SECTOR_MASK ) { +qemu_iovec_discard_back (&dbs->iov, dbs->iov.size & ~BDRV_SECTOR_MASK ); + } + dbs->acb = dbs->io_func (dbs->bs, dbs->sector_num, &dbs->iov, dbs->iov.size /512 , dma_bdrv_cb, dbs);assert (dbs->acb);
include/qemu-common.h +1 -0
@@ -329,6 +329,7 @@ size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset, int fillc, size_t bytes);ssize_t qemu_iovec_compare (QEMUIOVector *a,QEMUIOVector *b);void qemu_iovec_clone (QEMUIOVector *dest,const QEMUIOVector *src,void *buf); +void qemu_iovec_discard_back (QEMUIOVector *qiov,size_t bytes);bool buffer_is_zero (const void *buf,size_t len);
util/iov.c +13 -0
@@ -550,3 +550,16 @@ size_t iov_discard_back(struct iovec *iov, unsigned int *iov_cnt,return total; } + +void qemu_iovec_discard_back (QEMUIOVector *qiov,size_t bytes) +{ +size_t total; +unsigned int niov = qiov->niov; + +assert (qiov->size >= bytes); + total =iov_discard_back (qiov->iov, &niov, bytes); +assert (total == bytes); + + qiov->niov = niov; + qiov->size -= bytes; +}
Signature · 1 line
1.8.3.1
Quoted 5 lines · Kevin Wolf
If the size of the scatter/gather list isn't a multiple of 512, the number of sectors for the block layer request is rounded down, resulting in a qiov that doesn't match the request length. Truncate the qiov to the new length of the request.
Quoted 9 lines
This fixes the IDE qtest case /x86_64/ide/bmdma/short_prdt.
Signed-off-by Kevin Wolf <[email protected]>--- dma-helpers.c | 4 ++++ include/qemu-common.h | 1 + util/iov.c | 13 +++++++++++++ 3 files changed, 18 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Il 09/07/2014 19:23, Kevin Wolf ha scritto:
Quoted 19 lines
If the size of the scatter/gather list isn't a multiple of 512, the number of sectors for the block layer request is rounded down, resulting in a qiov that doesn't match the request length. Truncate the qiov to the new length of the request.
This fixes the IDE qtest case /x86_64/ide/bmdma/short_prdt.
Signed-off-by Kevin Wolf <[email protected]>--- dma-helpers.c | 4 ++++ include/qemu-common.h | 1 + util/iov.c | 13 +++++++++++++ 3 files changed, 18 insertions(+)dma-helpers.c +0
-0
dma-helpers.c static void dma_bdrv_cb(void *opaque, int ret) · line 175
Quoted 6 lines
dma-helpers.c +3
-0@@ -170,6 +170,10 @@ static void dma_bdrv_cb(void *opaque, int ret)return ; } +if (dbs->iov.size & ~BDRV_SECTOR_MASK ) { +qemu_iovec_discard_back (&dbs->iov, dbs->iov.size & ~BDRV_SECTOR_MASK ); + }
This is right for read/write, but not for discard.
Also, it is wrong if you got a misaligned request that straddles a page boundary, and the second half is from a MMIO device.
Do you think this works:
- add an alignment argument to dma_bdrv_io, and use it instead of 0 in the "if (dbs->iov.size == 0)" conditional
- only do the qemu_iovec_discard_back if the SG list has been processed entirely.
Paolo
Quoted 37 lines
dma-helpers.c +0
-0dbs->acb = dbs->io_func (dbs->bs, dbs->sector_num, &dbs->iov, dbs->iov.size /512 , dma_bdrv_cb, dbs);assert (dbs->acb);include/qemu-common.h +1
-0@@ -329,6 +329,7 @@ size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset, int fillc, size_t bytes);ssize_t qemu_iovec_compare (QEMUIOVector *a,QEMUIOVector *b);void qemu_iovec_clone (QEMUIOVector *dest,const QEMUIOVector *src,void *buf); +void qemu_iovec_discard_back (QEMUIOVector *qiov,size_t bytes);bool buffer_is_zero (const void *buf,size_t len);util/iov.c +13
-0@@ -550,3 +550,16 @@ size_t iov_discard_back(struct iovec *iov, unsigned int *iov_cnt,return total; } + +void qemu_iovec_discard_back (QEMUIOVector *qiov,size_t bytes) +{ +size_t total; +unsigned int niov = qiov->niov; + +assert (qiov->size >= bytes); + total =iov_discard_back (qiov->iov, &niov, bytes); +assert (total == bytes); + + qiov->niov = niov; + qiov->size -= bytes; +}