Block patches
Subsystems (2)
The following changes since commit b150cb8f67bf491a49a1cb1c7da151eeacbdbcc9:
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-09-29 13:18:54 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to bc47831ff28d6f5830c9c8d74220131dc54c5253:
util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved regions (2020-09-30 10:23:05 +0100)
----------------------------------------------------------------
Pull request
Note I have switched from GitHub to GitLab.
----------------------------------------------------------------
Eric Auger (2):
util/vfio-helpers: Collect IOVA reserved regions util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved
regions
Philippe Mathieu-Daudé (6):
util/vfio-helpers: Pass page protections to qemu_vfio_pci_map_bar() block/nvme: Map doorbells pages write-only
block/nvme: Reduce I/O registers scope
block/nvme: Drop NVMeRegs structure, directly use NvmeBar block/nvme: Use register definitions from 'block/nvme.h' block/nvme: Replace magic value by SCALE_MS definition
Stefano Garzarella (1):
docs: add 'io_uring' option to 'aio' param in qemu-options.hx
Vladimir Sementsov-Ogievskiy (8):
block: return error-code from bdrv_invalidate_cache block/io: refactor coroutine wrappers
block: declare some coroutine functions in block/coroutines.h
scripts: add block-coroutine-wrapper.py
block: generate coroutine-wrapper code
block: drop bdrv_prwv
block/io: refactor save/load vmstate include/block/block.h: drop non-ascii quotation mark
block/block-gen.h | 49 ++++ block/coroutines.h | 65 +++++ include/block/block.h | 36 ++- include/qemu/vfio-helpers.h | 2 +- block.c | 97 +------ block/io.c | 339 ++++--------------------- block/nvme.c | 73 +++--- tests/test-bdrv-drain.c | 2 +- util/vfio-helpers.c | 133 +++++++++- block/meson.build | 8 + docs/devel/block-coroutine-wrapper.rst | 54 ++++ docs/devel/index.rst | 1 + qemu-options.hx | 10 +- scripts/block-coroutine-wrapper.py | 188 ++++++++++++++ 14 files changed, 629 insertions(+), 428 deletions(-) create mode 100644 block/block-gen.h create mode 100644 block/coroutines.h create mode 100644 docs/devel/block-coroutine-wrapper.rst create mode 100644 scripts/block-coroutine-wrapper.py
Signature · 1 line
2.26.2
[PULL 01/17] util/vfio-helpers: Pass page protections to qemu_vfio_pci_map_bar()
From: Philippe Mathieu-Daudé <[email protected]>
Pages are currently mapped READ/WRITE. To be able to use different protections, add a new argument to qemu_vfio_pci_map_bar().
Message-Id: <[email protected]>
--- include/qemu/vfio-helpers.h | 2 +- block/nvme.c | 3 ++- util/vfio-helpers.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-)
include/qemu/vfio-helpers.h +1 -1
@@ -22,7 +22,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,int qemu_vfio_dma_reset_temporary (QEMUVFIOState *s);void qemu_vfio_dma_unmap (QEMUVFIOState *s,void *host);void *qemu_vfio_pci_map_bar (QEMUVFIOState *s,int index, -uint64_t offset,uint64_t size, +uint64_t offset,uint64_t size,int prot,Error **errp);void qemu_vfio_pci_unmap_bar (QEMUVFIOState *s,int index,void *bar,uint64_t offset,uint64_t size);
block/nvme.c +2 -1
@@ -712,7 +712,8 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, goto out; } - s->regs =qemu_vfio_pci_map_bar (s->vfio,0 ,0 ,NVME_BAR_SIZE , errp); + s->regs =qemu_vfio_pci_map_bar (s->vfio,0 ,0 ,NVME_BAR_SIZE , +PROT_READ |PROT_WRITE , errp);if (!s->regs) { ret = -EINVAL ; goto out;
util/vfio-helpers.c +2 -2
@@ -146,13 +146,13 @@ static int qemu_vfio_pci_init_bar(QEMUVFIOState *s, int index, Error **errp)* Map a PCI bar area. */ void *qemu_vfio_pci_map_bar (QEMUVFIOState *s,int index, -uint64_t offset,uint64_t size, +uint64_t offset,uint64_t size,int prot,Error **errp) {void *p;assert_bar_index_valid (s, index); p =mmap (NULL ,MIN (size, s->bar_region_info[index].size - offset), -PROT_READ |PROT_WRITE ,MAP_SHARED , + prot,MAP_SHARED , s->device, s->bar_region_info[index].offset + offset);if (p ==MAP_FAILED ) {error_setg_errno (errp, errno,"Failed to map BAR region" );
Signature · 1 line
2.26.2
[PULL 04/17] block/nvme: Drop NVMeRegs structure, directly use NvmeBar
In reply to Stefan HajnocziFrom: Philippe Mathieu-Daudé <[email protected]>
NVMeRegs only contains NvmeBar. Simplify the code by using NvmeBar directly.
This triggers a checkpatch.pl error:
ERROR: Use of volatile is usually wrong, please add a comment #30: FILE: block/nvme.c:691:
+ volatile NvmeBar *regs;
This is a false positive as in our case we are using I/O registers, so the 'volatile' use is justified.
Message-Id: <[email protected]>
--- block/nvme.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
block/nvme.c +9 -14
@@ -81,11 +81,6 @@ typedef struct {QEMUBH *completion_bh; } NVMeQueuePair; -/* Memory mapped registers */ -typedef volatile struct { -NvmeBar ctrl; -}NVMeRegs ; -#define INDEX_ADMIN 0#define INDEX_IO (n) (1 + n)
@@ -694,7 +689,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,uint64_t timeout_ms;uint64_t deadline, now;Error *local_err =NULL ; -NVMeRegs *regs; +volatile NvmeBar *regs =NULL ;qemu_co_mutex_init (&s->dma_map_lock);qemu_co_queue_init (&s->dma_flush_queue);
@@ -722,7 +717,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,/* Perform initialize sequence as described in NVMe spec "7.6.1 * Initialization". */ - cap =le64_to_cpu (regs->ctrl.cap); + cap =le64_to_cpu (regs->cap);if (!(cap & (1ULL <<37 ))) {error_setg (errp,"Device doesn't support NVMe command set" ); ret = -EINVAL ;
@@ -735,10 +730,10 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, timeout_ms =MIN (500 * ((cap >>24 ) &0xFF ),30000 );/* Reset device to get a clean state. */ - regs->ctrl.cc =cpu_to_le32 (le32_to_cpu (regs->ctrl.cc) &0xFE ); + regs->cc =cpu_to_le32 (le32_to_cpu (regs->cc) &0xFE );/* Wait for CSTS.RDY = 0. */ deadline =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) + timeout_ms *SCALE_MS ; -while (le32_to_cpu (regs->ctrl.csts) &0x1 ) { +while (le32_to_cpu (regs->csts) &0x1 ) {if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) > deadline) { error_setg(errp, "Timeout while waiting for device to reset (%" PRId64 " ms)",
@@ -766,18 +761,18 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, } s->nr_queues =1 ;QEMU_BUILD_BUG_ON (NVME_QUEUE_SIZE &0xF000 ); - regs->ctrl.aqa =cpu_to_le32 ((NVME_QUEUE_SIZE <<16 ) |NVME_QUEUE_SIZE ); - regs->ctrl.asq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->sq.iova); - regs->ctrl.acq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->cq.iova); + regs->aqa =cpu_to_le32 ((NVME_QUEUE_SIZE <<16 ) |NVME_QUEUE_SIZE ); + regs->asq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->sq.iova); + regs->acq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->cq.iova);/* After setting up all control registers we can enable device now. */ - regs->ctrl.cc =cpu_to_le32 ((ctz32 (NVME_CQ_ENTRY_BYTES ) <<20 ) | + regs->cc =cpu_to_le32 ((ctz32 (NVME_CQ_ENTRY_BYTES ) <<20 ) | (ctz32 (NVME_SQ_ENTRY_BYTES ) <<16 ) |0x1 );/* Wait for CSTS.RDY = 1. */ now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); deadline = now + timeout_ms *1000000 ; -while (!(le32_to_cpu (regs->ctrl.csts) &0x1 )) { +while (!(le32_to_cpu (regs->csts) &0x1 )) {if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%" PRId64 " ms)",
Signature · 1 line
2.26.2
[PULL 06/17] block/nvme: Replace magic value by SCALE_MS definition
In reply to Stefan HajnocziFrom: Philippe Mathieu-Daudé <[email protected]>
Use self-explicit SCALE_MS definition instead of magic value (missed in similar commit e4f310fe7f5).
Message-Id: <[email protected]>
--- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/nvme.c +1 -1
@@ -772,7 +772,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, CC_EN_MASK);/* Wait for CSTS.RDY = 1. */ now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); - deadline = now + timeout_ms *1000000 ; + deadline = now + timeout_ms *SCALE_MS ;while (!NVME_CSTS_RDY (le32_to_cpu (regs->csts))) {if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%"
Signature · 1 line
2.26.2
[PULL 02/17] block/nvme: Map doorbells pages write-only
In reply to Stefan HajnocziFrom: Philippe Mathieu-Daudé <[email protected]>
Per the datasheet sections 3.1.13/3.1.14:
"The host should not read the doorbell registers."
As we don't need read access, map the doorbells with write-only permission. We keep a reference to this mapped address in the BDRVNVMeState structure.
Message-Id: <[email protected]>
--- block/nvme.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
block/nvme.c +19 -10
@@ -31,7 +31,7 @@#define NVME_SQ_ENTRY_BYTES 64#define NVME_CQ_ENTRY_BYTES 16#define NVME_QUEUE_SIZE 128 -#define NVME_BAR_SIZE 8192 +#define NVME_DOORBELL_SIZE 4096/* * We have to leave one slot empty as that is the full queue case where
@@ -84,10 +84,6 @@ typedef struct {/* Memory mapped registers */ typedef volatile struct {NvmeBar ctrl; -struct { -uint32_t sq_tail; -uint32_t cq_head; - } doorbells[]; }NVMeRegs ;#define INDEX_ADMIN 0
@@ -103,6 +99,11 @@ struct BDRVNVMeState {AioContext *aio_context;QEMUVFIOState *vfio;NVMeRegs *regs; +/* Memory mapped registers */ +volatile struct { +uint32_t sq_tail; +uint32_t cq_head; + } *doorbells;/* The submission/completion queue pairs. * [0]: admin queue. * [1..]: io queues.
@@ -247,14 +248,14 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,error_propagate (errp, local_err); goto fail; } - q->sq.doorbell = &s->regs->doorbells[idx * s->doorbell_scale].sq_tail; + q->sq.doorbell = &s->doorbells[idx * s->doorbell_scale].sq_tail;nvme_init_queue (s, &q->cq, size,NVME_CQ_ENTRY_BYTES , &local_err);if (local_err) {error_propagate (errp, local_err); goto fail; } - q->cq.doorbell = &s->regs->doorbells[idx * s->doorbell_scale].cq_head; + q->cq.doorbell = &s->doorbells[idx * s->doorbell_scale].cq_head;return q; fail:
@@ -712,13 +713,12 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, goto out; } - s->regs =qemu_vfio_pci_map_bar (s->vfio,0 ,0 ,NVME_BAR_SIZE , + s->regs =qemu_vfio_pci_map_bar (s->vfio,0 ,0 ,sizeof (NvmeBar),PROT_READ |PROT_WRITE , errp);if (!s->regs) { ret = -EINVAL ; goto out; } -/* Perform initialize sequence as described in NVMe spec "7.6.1 * Initialization". */
@@ -748,6 +748,13 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, } } + s->doorbells =qemu_vfio_pci_map_bar (s->vfio,0 ,sizeof (NvmeBar), +NVME_DOORBELL_SIZE ,PROT_WRITE , errp); +if (!s->doorbells) { + ret = -EINVAL ; + goto out; + } +/* Set up admin queue. */ s->queues = g_new(NVMeQueuePair *, 1); s->queues[INDEX_ADMIN] = nvme_create_queue_pair(s, aio_context, 0,
@@ -873,7 +880,9 @@ static void nvme_close(BlockDriverState *bs) &s->irq_notifier[MSIX_SHARED_IRQ_IDX ], false, NULL, NULL);event_notifier_cleanup (&s->irq_notifier[MSIX_SHARED_IRQ_IDX ]); -qemu_vfio_pci_unmap_bar (s->vfio,0 , (void *)s->regs,0 ,NVME_BAR_SIZE ); +qemu_vfio_pci_unmap_bar (s->vfio,0 , (void *)s->doorbells, +sizeof (NvmeBar),NVME_DOORBELL_SIZE ); +qemu_vfio_pci_unmap_bar (s->vfio,0 , (void *)s->regs,0 ,sizeof (NvmeBar));qemu_vfio_close (s->vfio);g_free (s->device);
Signature · 1 line
2.26.2
[PULL 03/17] block/nvme: Reduce I/O registers scope
In reply to Stefan HajnocziFrom: Philippe Mathieu-Daudé <[email protected]>
We only access the I/O register in nvme_init(). Remove the reference in BDRVNVMeState and reduce its scope.
Message-Id: <[email protected]>
--- block/nvme.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
block/nvme.c +16 -13
@@ -98,7 +98,6 @@ enum {struct BDRVNVMeState {AioContext *aio_context;QEMUVFIOState *vfio; -NVMeRegs *regs;/* Memory mapped registers */ volatile struct {uint32_t sq_tail;
@@ -695,6 +694,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace,uint64_t timeout_ms;uint64_t deadline, now;Error *local_err =NULL ; +NVMeRegs *regs;qemu_co_mutex_init (&s->dma_map_lock);qemu_co_queue_init (&s->dma_flush_queue);
@@ -713,16 +713,16 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, goto out; } - s->regs =qemu_vfio_pci_map_bar (s->vfio,0 ,0 ,sizeof (NvmeBar), -PROT_READ |PROT_WRITE , errp); -if (!s->regs) { + regs =qemu_vfio_pci_map_bar (s->vfio,0 ,0 ,sizeof (NvmeBar), +PROT_READ |PROT_WRITE , errp); +if (!regs) { ret = -EINVAL ; goto out; }/* Perform initialize sequence as described in NVMe spec "7.6.1 * Initialization". */ - cap =le64_to_cpu (s->regs->ctrl.cap); + cap =le64_to_cpu (regs->ctrl.cap);if (!(cap & (1ULL <<37 ))) {error_setg (errp,"Device doesn't support NVMe command set" ); ret = -EINVAL ;
@@ -735,10 +735,10 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, timeout_ms =MIN (500 * ((cap >>24 ) &0xFF ),30000 );/* Reset device to get a clean state. */ - s->regs->ctrl.cc =cpu_to_le32 (le32_to_cpu (s->regs->ctrl.cc) &0xFE ); + regs->ctrl.cc =cpu_to_le32 (le32_to_cpu (regs->ctrl.cc) &0xFE );/* Wait for CSTS.RDY = 0. */ deadline =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) + timeout_ms *SCALE_MS ; -while (le32_to_cpu (s->regs->ctrl.csts) &0x1 ) { +while (le32_to_cpu (regs->ctrl.csts) &0x1 ) {if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) > deadline) { error_setg(errp, "Timeout while waiting for device to reset (%" PRId64 " ms)",
@@ -766,18 +766,18 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, } s->nr_queues =1 ;QEMU_BUILD_BUG_ON (NVME_QUEUE_SIZE &0xF000 ); - s->regs->ctrl.aqa =cpu_to_le32 ((NVME_QUEUE_SIZE <<16 ) |NVME_QUEUE_SIZE ); - s->regs->ctrl.asq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->sq.iova); - s->regs->ctrl.acq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->cq.iova); + regs->ctrl.aqa =cpu_to_le32 ((NVME_QUEUE_SIZE <<16 ) |NVME_QUEUE_SIZE ); + regs->ctrl.asq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->sq.iova); + regs->ctrl.acq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->cq.iova);/* After setting up all control registers we can enable device now. */ - s->regs->ctrl.cc =cpu_to_le32 ((ctz32 (NVME_CQ_ENTRY_BYTES ) <<20 ) | + regs->ctrl.cc =cpu_to_le32 ((ctz32 (NVME_CQ_ENTRY_BYTES ) <<20 ) | (ctz32 (NVME_SQ_ENTRY_BYTES ) <<16 ) |0x1 );/* Wait for CSTS.RDY = 1. */ now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); deadline = now + timeout_ms *1000000 ; -while (!(le32_to_cpu (s->regs->ctrl.csts) &0x1 )) { +while (!(le32_to_cpu (regs->ctrl.csts) &0x1 )) {if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%" PRId64 " ms)",
@@ -808,6 +808,10 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, ret = -EIO ; } out: +if (regs) { +qemu_vfio_pci_unmap_bar (s->vfio,0 , (void *)regs,0 ,sizeof (NvmeBar)); + } +/* Cleaning up is done in nvme_file_open() upon error. */ return ret; }
@@ -882,7 +886,6 @@ static void nvme_close(BlockDriverState *bs)event_notifier_cleanup (&s->irq_notifier[MSIX_SHARED_IRQ_IDX ]);qemu_vfio_pci_unmap_bar (s->vfio,0 , (void *)s->doorbells,sizeof (NvmeBar),NVME_DOORBELL_SIZE ); -qemu_vfio_pci_unmap_bar (s->vfio,0 , (void *)s->regs,0 ,sizeof (NvmeBar));qemu_vfio_close (s->vfio);g_free (s->device);
Signature · 1 line
2.26.2
[PULL 10/17] scripts: add block-coroutine-wrapper.py
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
We have a very frequent pattern of creating a coroutine from a function with several arguments:
- create a structure to pack parameters
- create _entry function to call original function taking parameters from struct
- do different magic to handle completion: set ret to NOT_DONE or EINPROGRESS or use separate bool field
- fill the struct and create coroutine from _entry function with this struct as a parameter
- do coroutine enter and BDRV_POLL_WHILE loop
Let's reduce code duplication by generating coroutine wrappers.
This patch adds scripts/block-coroutine-wrapper.py together with some friends, which will generate functions with declared prototypes marked by the 'generated_co_wrapper' specifier.
The usage of new code generation is as follows:
1. define the coroutine function somewhere
int coroutine_fn bdrv_co_NAME(...) {...}
2. declare in some header file
int generated_co_wrapper bdrv_NAME(...);
with same list of parameters (generated_co_wrapper is defined in "include/block/block.h").
3. Make sure the block_gen_c declaration in block/meson.build mentions the file with your marker function.
Still, no function is now marked, this work is for the following commit.
Message-Id: <[email protected]> [Added encoding='utf-8' to open() calls as requested by Vladimir. Fixed typo and grammar issues pointed out by Eric Blake.
--Stefan]
--- block/block-gen.h | 49 +++++++ include/block/block.h | 10 ++ block/meson.build | 8 ++ docs/devel/block-coroutine-wrapper.rst | 54 +++++++ docs/devel/index.rst | 1 + scripts/block-coroutine-wrapper.py | 188 +++++++++++++++++++++++++ 6 files changed, 310 insertions(+) create mode 100644 block/block-gen.h create mode 100644 docs/devel/block-coroutine-wrapper.rst create mode 100644 scripts/block-coroutine-wrapper.py
block/block-gen.h new file +49 -0
@@ -0,0 +1,49 @@ +/* +* Block coroutine wrapping core, used by auto-generated block/block-gen.c +* +* Copyright (c) 2003 Fabrice Bellard +* Copyright (c) 2020 Virtuozzo International GmbH +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef BLOCK_BLOCK_GEN_H +#define BLOCK_BLOCK_GEN_H + +#include "block/block_int.h" + +/* Base structure for argument packing structures */ +typedef struct BdrvPollCo { +BlockDriverState *bs; +bool in_progress; +int ret; +Coroutine *co;/* Keep pointer here for debugging */ +}BdrvPollCo ; + +static inline int bdrv_poll_co (BdrvPollCo *s) +{ +assert (!qemu_in_coroutine ()); + +bdrv_coroutine_enter (s->bs, s->co); +BDRV_POLL_WHILE (s->bs, s->in_progress); + +return s->ret; +} + +#endif /* BLOCK_BLOCK_GEN_H */
include/block/block.h +10 -0
@@ -10,6 +10,16 @@#include "block/blockjob.h" #include "qemu/hbitmap.h" +/* +* generated_co_wrapper +* +* Function specifier, which does nothing but mark functions to be +* generated by scripts/block-coroutine-wrapper.py +* +* Read more in docs/devel/block-coroutine-wrapper.rst +*/ +#define generated_co_wrapper +/* block.c */ typedef struct BlockDriver BlockDriver ;typedef struct BdrvChild BdrvChild ;
block/meson.build +8 -0
@@ -107,6 +107,14 @@ module_block_h = custom_target('module_block.h', command: [module_block_py, '@OUTPUT0@', modsrc]) block_ss.add(module_block_h) +wrapper_py = find_program('../scripts/block-coroutine-wrapper.py') +block_gen_c = custom_target('block-gen.c', + output: 'block-gen.c', + input: files('../include/block/block.h', + 'coroutines.h'), + command: [wrapper_py, '@OUTPUT@', '@INPUT@']) +block_ss.add(block_gen_c) + block_ss.add(files('stream.c')) softmmu_ss.add(files('qapi-sysemu.c'))
docs/devel/block-coroutine-wrapper.rst new file +54 -0
54 lines not on this page · raw message
docs/devel/index.rst +1 -0
@@ -31,3 +31,4 @@ Contents: reset s390-dasd-ipl clocks + block-coroutine-wrapper
scripts/block-coroutine-wrapper.py new file +188 -0
188 lines not on this page · raw message
Signature · 1 line
2.26.2
[PULL 05/17] block/nvme: Use register definitions from 'block/nvme.h'
In reply to Stefan HajnocziFrom: Philippe Mathieu-Daudé <[email protected]>
Use the NVMe register definitions from "block/nvme.h" which ease a bit reviewing the code while matching the datasheet.
Message-Id: <[email protected]>
--- block/nvme.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
block/nvme.c +11 -10
@@ -718,22 +718,22 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, * Initialization". */ cap =le64_to_cpu (regs->cap); -if (!(cap & (1ULL <<37 ))) { +if (!NVME_CAP_CSS (cap)) {error_setg (errp,"Device doesn't support NVMe command set" ); ret = -EINVAL ; goto out; } - s->page_size =MAX (4096 ,1 << (12 + ((cap >>48 ) &0xF ))); - s->doorbell_scale = (4 << (((cap >>32 ) &0xF ))) /sizeof (uint32_t ); + s->page_size =MAX (4096 ,1 <<NVME_CAP_MPSMIN (cap)); + s->doorbell_scale = (4 <<NVME_CAP_DSTRD (cap)) /sizeof (uint32_t ); bs->bl.opt_mem_alignment = s->page_size; - timeout_ms =MIN (500 * ((cap >>24 ) &0xFF ),30000 ); + timeout_ms =MIN (500 *NVME_CAP_TO (cap),30000 );/* Reset device to get a clean state. */ regs->cc =cpu_to_le32 (le32_to_cpu (regs->cc) &0xFE );/* Wait for CSTS.RDY = 0. */ deadline =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) + timeout_ms *SCALE_MS ; -while (le32_to_cpu (regs->csts) &0x1 ) { +while (NVME_CSTS_RDY (le32_to_cpu (regs->csts))) {if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) > deadline) { error_setg(errp, "Timeout while waiting for device to reset (%" PRId64 " ms)",
@@ -761,18 +761,19 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, } s->nr_queues =1 ;QEMU_BUILD_BUG_ON (NVME_QUEUE_SIZE &0xF000 ); - regs->aqa =cpu_to_le32 ((NVME_QUEUE_SIZE <<16 ) |NVME_QUEUE_SIZE ); + regs->aqa =cpu_to_le32 ((NVME_QUEUE_SIZE <<AQA_ACQS_SHIFT ) | + (NVME_QUEUE_SIZE <<AQA_ASQS_SHIFT )); regs->asq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->sq.iova); regs->acq =cpu_to_le64 (s->queues[INDEX_ADMIN ]->cq.iova);/* After setting up all control registers we can enable device now. */ - regs->cc =cpu_to_le32 ((ctz32 (NVME_CQ_ENTRY_BYTES ) <<20 ) | - (ctz32 (NVME_SQ_ENTRY_BYTES ) <<16 ) | -0x1 ); + regs->cc =cpu_to_le32 ((ctz32 (NVME_CQ_ENTRY_BYTES ) <<CC_IOCQES_SHIFT ) | + (ctz32 (NVME_SQ_ENTRY_BYTES ) <<CC_IOSQES_SHIFT ) | +CC_EN_MASK );/* Wait for CSTS.RDY = 1. */ now =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); deadline = now + timeout_ms *1000000 ; -while (!(le32_to_cpu (regs->csts) &0x1 )) { +while (!NVME_CSTS_RDY (le32_to_cpu (regs->csts))) {if (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%" PRId64 " ms)",
Signature · 1 line
2.26.2
[PULL 17/17] util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved regions
In reply to Stefan HajnocziFrom: Eric Auger <[email protected]>
Introduce the qemu_vfio_find_fixed/temp_iova helpers which respectively allocate IOVAs from the bottom/top parts of the usable IOVA range, without picking within host IOVA reserved windows. The allocation remains basic: if the size is too big for the remaining of the current usable IOVA range, we jump to the next one, leaving a hole in the address map.
Message-id: [email protected]
--- util/vfio-helpers.c | 57 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-)
util/vfio-helpers.c +53 -4
@@ -667,6 +667,50 @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *s)return true; } +static int +qemu_vfio_find_fixed_iova (QEMUVFIOState *s,size_t size,uint64_t *iova) +{ +int i; + +for (i =0 ; i < s->nb_iova_ranges; i++) { +if (s->usable_iova_ranges[i].end < s->low_water_mark) { +continue ; + } + s->low_water_mark = +MAX (s->low_water_mark, s->usable_iova_ranges[i].start); + +if (s->usable_iova_ranges[i].end - s->low_water_mark +1 >= size || + s->usable_iova_ranges[i].end - s->low_water_mark +1 ==0 ) { + *iova = s->low_water_mark; + s->low_water_mark += size; +return 0 ; + } + } +return -ENOMEM ; +} + +static int +qemu_vfio_find_temp_iova (QEMUVFIOState *s,size_t size,uint64_t *iova) +{ +int i; + +for (i = s->nb_iova_ranges -1 ; i >=0 ; i--) { +if (s->usable_iova_ranges[i].start > s->high_water_mark) { +continue ; + } + s->high_water_mark = +MIN (s->high_water_mark, s->usable_iova_ranges[i].end +1 ); + +if (s->high_water_mark - s->usable_iova_ranges[i].start +1 >= size || + s->high_water_mark - s->usable_iova_ranges[i].start +1 ==0 ) { + *iova = s->high_water_mark - size; + s->high_water_mark = *iova; +return 0 ; + } + } +return -ENOMEM ; +} +/* Map [host, host + size) area into a contiguous IOVA address space, and store * the result in @iova if not NULL. The caller need to make sure the area is * aligned to page size, and mustn't overlap with existing mapping areas (split
@@ -693,7 +737,11 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size, goto out; }if (!temporary) { - iova0 = s->low_water_mark; +if (qemu_vfio_find_fixed_iova (s, size, &iova0)) { + ret = -ENOMEM ; + goto out; + } + mapping =qemu_vfio_add_mapping (s, host, size, index +1 , iova0);if (!mapping) { ret = -ENOMEM ;
@@ -705,15 +753,16 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,qemu_vfio_undo_mapping (s, mapping,NULL ); goto out; } - s->low_water_mark += size;qemu_vfio_dump_mappings (s); }else { - iova0 = s->high_water_mark - size; +if (qemu_vfio_find_temp_iova (s, size, &iova0)) { + ret = -ENOMEM ; + goto out; + } ret =qemu_vfio_do_mapping (s, host, size, iova0);if (ret) { goto out; } - s->high_water_mark -= size; } }if (iova) {
Signature · 1 line
2.26.2
[PULL 15/17] docs: add 'io_uring' option to 'aio' param in qemu-options.hx
In reply to Stefan HajnocziFrom: Stefano Garzarella <[email protected]>
When we added io_uring AIO engine, we forgot to update qemu-options.hx, so qemu(1) man page and qemu help were outdated.
Message-Id: <[email protected]>
--- qemu-options.hx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
qemu-options.hx +6 -4
@@ -1053,7 +1053,8 @@ SRST The path to the image file in the local filesystem ``aio`` - Specifies the AIO backend (threads/native, default: threads) + Specifies the AIO backend (threads/native/io_uring, + default: threads) ``locking`` Specifies whether the image file is protected with Linux OFD
@@ -1175,7 +1176,8 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" " [,snapshot=on|off][,rerror=ignore|stop|report]\n" - " [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]\n" + " [,werror=ignore|stop|report|enospc][,id=name]\n" + " [,aio=threads|native|io_uring]\n" " [,readonly=on|off][,copy-on-read=on|off]\n" " [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n" " [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]]\n"
@@ -1247,8 +1249,8 @@ SRST The default mode is ``cache=writeback``. ``aio=aio`` - aio is "threads", or "native" and selects between pthread based - disk I/O and native Linux AIO. + aio is "threads", "native", or "io_uring" and selects between pthread + based disk I/O, native Linux AIO, or Linux io_uring API. ``format=format`` Specify which disk format will be used rather than detecting the
Signature · 1 line
2.26.2
[PULL 08/17] block/io: refactor coroutine wrappers
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Most of our coroutine wrappers already follow this convention:
We have 'coroutine_fn bdrv_co_<something>(<normal argument list>)' as the core function, and a wrapper 'bdrv_<something>(<same argument list>)' which does parameter packing and calls bdrv_run_co().
The only outsiders are the bdrv_prwv_co and bdrv_common_block_status_above wrappers. Let's refactor them to behave as the others, it simplifies further conversion of coroutine wrappers.
This patch adds an indirection layer, but it will be compensated by a further commit, which will drop bdrv_co_prwv together with the is_write logic, to keep the read and write paths separate.
Message-Id: <[email protected]>
--- block/io.c | 60 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-)
block/io.c +32 -28
@@ -933,27 +933,31 @@ typedef struct RwCo {BdrvRequestFlags flags; } RwCo; +static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, +QEMUIOVector *qiov,bool is_write, +BdrvRequestFlags flags) +{ +if (is_write) { +return bdrv_co_pwritev (child, offset, qiov->size, qiov, flags); + }else { +return bdrv_co_preadv (child, offset, qiov->size, qiov, flags); + } +} + static int coroutine_fn bdrv_rw_co_entry(void *opaque) {RwCo *rwco = opaque; -if (!rwco->is_write) { -return bdrv_co_preadv (rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - }else { -return bdrv_co_pwritev (rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - } +return bdrv_co_prwv (rwco->child, rwco->offset, rwco->qiov, + rwco->is_write, rwco->flags); }/* * Process a vectored synchronous request using coroutines */ -static int bdrv_prwv_co (BdrvChild *child,int64_t offset, -QEMUIOVector *qiov,bool is_write, -BdrvRequestFlags flags) +static int bdrv_prwv (BdrvChild *child,int64_t offset, +QEMUIOVector *qiov,bool is_write, +BdrvRequestFlags flags) {RwCo rwco = { .child = child,
@@ -971,8 +975,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, {QEMUIOVector qiov =QEMU_IOVEC_INIT_BUF (qiov,NULL , bytes); -return bdrv_prwv_co (child, offset, &qiov, true, -BDRV_REQ_ZERO_WRITE | flags); +return bdrv_prwv (child, offset, &qiov, true,BDRV_REQ_ZERO_WRITE | flags); }/*
@@ -1021,7 +1024,7 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) {int ret; - ret =bdrv_prwv_co (child, offset, qiov, false,0 ); + ret =bdrv_prwv (child, offset, qiov, false,0 );if (ret <0 ) {return ret; }
@@ -1045,7 +1048,7 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) {int ret; - ret =bdrv_prwv_co (child, offset, qiov, true,0 ); + ret =bdrv_prwv (child, offset, qiov, true,0 );if (ret <0 ) {return ret; }
@@ -2449,14 +2452,15 @@ early_out:return ret; } -static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, -BlockDriverState *base, -bool want_zero, -int64_t offset, -int64_t bytes, -int64_t *pnum, -int64_t *map, -BlockDriverState **file) +static int coroutine_fn +bdrv_co_common_block_status_above (BlockDriverState *bs, +BlockDriverState *base, +bool want_zero, +int64_t offset, +int64_t bytes, +int64_t *pnum, +int64_t *map, +BlockDriverState **file) {BlockDriverState *p;int ret =0 ;
@@ -2494,10 +2498,10 @@ static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque) {BdrvCoBlockStatusData *data = opaque; -return bdrv_co_block_status_above (data->bs, data->base, - data->want_zero, - data->offset, data->bytes, - data->pnum, data->map, data->file); +return bdrv_co_common_block_status_above (data->bs, data->base, + data->want_zero, + data->offset, data->bytes, + data->pnum, data->map, data->file); }/*
Signature · 1 line
2.26.2
[PULL 09/17] block: declare some coroutine functions in block/coroutines.h
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
We are going to keep coroutine-wrappers code (structure-packing parameters, BDRV_POLL wrapper functions) in separate auto-generated files. So, we'll need a header with declaration of original _co_ functions, for those which are static now. As well, we'll need declarations for wrapper functions. Do these declarations now, as a preparation step.
Message-Id: <[email protected]>
--- block/coroutines.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++ block.c | 8 +++--- block/io.c | 34 +++++++++++------------ 3 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 block/coroutines.h
block/coroutines.h new file +67 -0
@@ -0,0 +1,67 @@ +/* +* Block layer I/O functions +* +* Copyright (c) 2003 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef BLOCK_COROUTINES_INT_H +#define BLOCK_COROUTINES_INT_H + +#include "block/block_int.h" + +int coroutine_fn bdrv_co_check(BlockDriverState *bs, +BdrvCheckResult *res,BdrvCheckMode fix); +int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp); + +int coroutine_fn +bdrv_co_prwv (BdrvChild *child,int64_t offset,QEMUIOVector *qiov, +bool is_write,BdrvRequestFlags flags); +int +bdrv_prwv (BdrvChild *child,int64_t offset,QEMUIOVector *qiov, +bool is_write,BdrvRequestFlags flags); + +int coroutine_fn +bdrv_co_common_block_status_above (BlockDriverState *bs, +BlockDriverState *base, +bool want_zero, +int64_t offset, +int64_t bytes, +int64_t *pnum, +int64_t *map, +BlockDriverState **file); +int +bdrv_common_block_status_above (BlockDriverState *bs, +BlockDriverState *base, +bool want_zero, +int64_t offset, +int64_t bytes, +int64_t *pnum, +int64_t *map, +BlockDriverState **file); + +int coroutine_fn +bdrv_co_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos, +bool is_read); +int +bdrv_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos, +bool is_read); + +#endif /* BLOCK_COROUTINES_INT_H */
block.c +4 -4
@@ -48,6 +48,7 @@#include "qemu/timer.h" #include "qemu/cutils.h" #include "qemu/id.h" +#include "block/coroutines.h" #ifdef CONFIG_BSD #include <sys/ioctl.h>
@@ -4676,8 +4677,8 @@ static void bdrv_delete(BlockDriverState *bs)* free of errors) or -errno when an internal error occurred. The results of the * check are stored in res. */ -static int coroutine_fn bdrv_co_check(BlockDriverState *bs, -BdrvCheckResult *res,BdrvCheckMode fix) +int coroutine_fn bdrv_co_check(BlockDriverState *bs, +BdrvCheckResult *res,BdrvCheckMode fix) {if (bs->drv ==NULL ) {return -ENOMEDIUM ;
@@ -5781,8 +5782,7 @@ void bdrv_init_with_whitelist(void)bdrv_init (); } -static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, -Error **errp) +int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp) {BdrvChild *child, *parent;uint64_t perm, shared_perm;
block/io.c +17 -17
@@ -29,6 +29,7 @@#include "block/blockjob.h" #include "block/blockjob_int.h" #include "block/block_int.h" +#include "block/coroutines.h" #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/error-report.h"
@@ -933,9 +934,9 @@ typedef struct RwCo {BdrvRequestFlags flags; } RwCo; -static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, -QEMUIOVector *qiov,bool is_write, -BdrvRequestFlags flags) +int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, +QEMUIOVector *qiov,bool is_write, +BdrvRequestFlags flags) {if (is_write) {return bdrv_co_pwritev (child, offset, qiov->size, qiov, flags);
@@ -955,9 +956,9 @@ static int coroutine_fn bdrv_rw_co_entry(void *opaque)/* * Process a vectored synchronous request using coroutines */ -static int bdrv_prwv (BdrvChild *child,int64_t offset, -QEMUIOVector *qiov,bool is_write, -BdrvRequestFlags flags) +int bdrv_prwv (BdrvChild *child,int64_t offset, +QEMUIOVector *qiov,bool is_write, +BdrvRequestFlags flags) {RwCo rwco = { .child = child,
@@ -2452,7 +2453,7 @@ early_out:return ret; } -static int coroutine_fn +int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero,
@@ -2509,12 +2510,12 @@ static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque)* * See bdrv_co_block_status_above() for details. */ -static int bdrv_common_block_status_above (BlockDriverState *bs, -BlockDriverState *base, -bool want_zero,int64_t offset, -int64_t bytes,int64_t *pnum, -int64_t *map, -BlockDriverState **file) +int bdrv_common_block_status_above (BlockDriverState *bs, +BlockDriverState *base, +bool want_zero,int64_t offset, +int64_t bytes,int64_t *pnum, +int64_t *map, +BlockDriverState **file) {BdrvCoBlockStatusData data = { .bs = bs,
@@ -2630,7 +2631,7 @@ typedef struct BdrvVmstateCo {bool is_read; } BdrvVmstateCo; -static int coroutine_fn +int coroutine_fnbdrv_co_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos,bool is_read) {
@@ -2663,9 +2664,8 @@ static int coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque)return bdrv_co_rw_vmstate (co->bs, co->qiov, co->pos, co->is_read); } -static inline int -bdrv_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos, -bool is_read) +int bdrv_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos, +bool is_read) {BdrvVmstateCo data = { .bs = bs,
Signature · 1 line
2.26.2
[PULL 07/17] block: return error-code from bdrv_invalidate_cache
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
This is the only coroutine wrapper from block.c and block/io.c which doesn't return a value, so let's convert it to the common behavior, to simplify moving to generated coroutine wrappers in a further commit.
Also, bdrv_invalidate_cache is a void function, returning error only through **errp parameter, which is considered to be bad practice, as it forces callers to define and propagate local_err variable, so conversion is good anyway.
This patch leaves the conversion of .bdrv_co_invalidate_cache() driver callbacks and bdrv_invalidate_cache_all() for another day.
Message-Id: <[email protected]>
--- include/block/block.h | 2 +- block.c | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-)
include/block/block.h +1 -1
@@ -460,7 +460,7 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb);int bdrv_co_ioctl (BlockDriverState *bs,int req,void *buf);/* Invalidate any cached metadata used by image formats */ -void bdrv_invalidate_cache (BlockDriverState *bs,Error **errp); +int bdrv_invalidate_cache (BlockDriverState *bs,Error **errp);void bdrv_invalidate_cache_all (Error **errp);int bdrv_inactivate_all (void );
block.c +18 -14
@@ -5781,8 +5781,8 @@ void bdrv_init_with_whitelist(void)bdrv_init (); } -static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, -Error **errp) +static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, +Error **errp) {BdrvChild *child, *parent;uint64_t perm, shared_perm;
@@ -5791,14 +5791,14 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,BdrvDirtyBitmap *bm;if (!bs->drv) { -return ; +return -ENOMEDIUM ; } QLIST_FOREACH(child, &bs->children, next) {bdrv_co_invalidate_cache (child->bs, &local_err);if (local_err) {error_propagate (errp, local_err); -return ; +return -EINVAL ; } }
@@ -5821,7 +5821,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, ret =bdrv_check_perm (bs,NULL , perm, shared_perm,NULL ,NULL , errp);if (ret <0 ) { bs->open_flags |=BDRV_O_INACTIVE ; -return ; +return ret; }bdrv_set_perm (bs, perm, shared_perm);
@@ -5830,7 +5830,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,if (local_err) { bs->open_flags |=BDRV_O_INACTIVE ;error_propagate (errp, local_err); -return ; +return -EINVAL ; } }
@@ -5842,7 +5842,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,if (ret <0 ) { bs->open_flags |=BDRV_O_INACTIVE ;error_setg_errno (errp, -ret,"Could not refresh total sector count" ); -return ; +return ret; } }
@@ -5852,27 +5852,30 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,if (local_err) { bs->open_flags |=BDRV_O_INACTIVE ;error_propagate (errp, local_err); -return ; +return -EINVAL ; } } } + +return 0 ; }typedef struct InvalidateCacheCo {BlockDriverState *bs;Error **errp;bool done; +int ret; }InvalidateCacheCo ; static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque) {InvalidateCacheCo *ico = opaque; -bdrv_co_invalidate_cache (ico->bs, ico->errp); + ico->ret =bdrv_co_invalidate_cache (ico->bs, ico->errp); ico->done = true;aio_wait_kick (); } -void bdrv_invalidate_cache (BlockDriverState *bs,Error **errp) +int bdrv_invalidate_cache (BlockDriverState *bs,Error **errp) {Coroutine *co;InvalidateCacheCo ico = {
@@ -5889,22 +5892,23 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)bdrv_coroutine_enter (bs, co);BDRV_POLL_WHILE (bs, !ico.done); } + +return ico.ret; }void bdrv_invalidate_cache_all (Error **errp) {BlockDriverState *bs; -Error *local_err =NULL ;BdrvNextIterator it;for (bs =bdrv_first (&it); bs; bs =bdrv_next (&it)) {AioContext *aio_context =bdrv_get_aio_context (bs); +int ret;aio_context_acquire (aio_context); -bdrv_invalidate_cache (bs, &local_err); + ret =bdrv_invalidate_cache (bs, errp);aio_context_release (aio_context); -if (local_err) { -error_propagate (errp, local_err); +if (ret <0 ) {bdrv_next_cleanup (&it);return ; }
Signature · 1 line
2.26.2
[PULL 13/17] block/io: refactor save/load vmstate
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Like for read/write in a previous commit, drop extra indirection layer, generate directly bdrv_readv_vmstate() and bdrv_writev_vmstate().
Message-Id: <[email protected]>
--- block/coroutines.h | 10 +++---- include/block/block.h | 6 ++-- block/io.c | 70 ++++++++++++++++++++++--------------------- 3 files changed, 44 insertions(+), 42 deletions(-)
block/coroutines.h +4 -6
@@ -57,11 +57,9 @@ bdrv_common_block_status_above(BlockDriverState *bs,int64_t *map, BlockDriverState **file); -int coroutine_fn -bdrv_co_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos, -bool is_read); -int generated_co_wrapper -bdrv_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos, -bool is_read); +int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs, +QEMUIOVector *qiov,int64_t pos); +int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs, +QEMUIOVector *qiov,int64_t pos);#endif /* BLOCK_COROUTINES_INT_H */
include/block/block.h +4 -2
@@ -572,8 +572,10 @@ int path_has_protocol(const char *path);int path_is_absolute (const char *path);char *path_combine (const char *base_path,const char *filename); -int bdrv_readv_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos); -int bdrv_writev_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos); +int generated_co_wrapper +bdrv_readv_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos); +int generated_co_wrapper +bdrv_writev_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos);int bdrv_save_vmstate (BlockDriverState *bs,const uint8_t *buf,int64_t pos,int size);
block/io.c +36 -34
102 lines not on this page · raw message
Signature · 1 line
2.26.2
[PULL 11/17] block: generate coroutine-wrapper code
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Use code generation implemented in previous commit to generated coroutine wrappers in block.c and block/io.c
Message-Id: <[email protected]>
--- block/coroutines.h | 6 +- include/block/block.h | 16 ++-- block.c | 73 --------------- block/io.c | 212 ------------------------------------------ 4 files changed, 13 insertions(+), 294 deletions(-)
block/coroutines.h +3 -3
@@ -34,7 +34,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp); int coroutine_fnbdrv_co_prwv (BdrvChild *child,int64_t offset,QEMUIOVector *qiov,bool is_write,BdrvRequestFlags flags); -int +int generated_co_wrapperbdrv_prwv (BdrvChild *child,int64_t offset,QEMUIOVector *qiov,bool is_write,BdrvRequestFlags flags);
@@ -47,7 +47,7 @@ bdrv_co_common_block_status_above(BlockDriverState *bs,int64_t *pnum, int64_t *map, BlockDriverState **file); -int +int generated_co_wrapper bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero,
@@ -60,7 +60,7 @@ bdrv_common_block_status_above(BlockDriverState *bs, int coroutine_fnbdrv_co_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos,bool is_read); -int +int generated_co_wrapperbdrv_rw_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos,bool is_read);
include/block/block.h +10 -6
@@ -403,8 +403,9 @@ void bdrv_refresh_filename(BlockDriverState *bs); int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,PreallocMode prealloc,BdrvRequestFlags flags,Error **errp); -int bdrv_truncate (BdrvChild *child,int64_t offset,bool exact, -PreallocMode prealloc,BdrvRequestFlags flags,Error **errp); +int generated_co_wrapper +bdrv_truncate (BdrvChild *child,int64_t offset,bool exact, +PreallocMode prealloc,BdrvRequestFlags flags,Error **errp);int64_t bdrv_nb_sectors (BlockDriverState *bs);int64_t bdrv_getlength (BlockDriverState *bs);
@@ -446,7 +447,8 @@ typedef enum {BDRV_FIX_ERRORS =2 , } BdrvCheckMode; -int bdrv_check (BlockDriverState *bs,BdrvCheckResult *res,BdrvCheckMode fix); +int generated_co_wrapper bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, +BdrvCheckMode fix);/* The units of offset and total_work_size may be chosen arbitrarily by the * block driver; total_work_size may change during the course of the amendment
@@ -470,12 +472,13 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb);int bdrv_co_ioctl (BlockDriverState *bs,int req,void *buf);/* Invalidate any cached metadata used by image formats */ -int bdrv_invalidate_cache (BlockDriverState *bs,Error **errp); +int generated_co_wrapper bdrv_invalidate_cache(BlockDriverState *bs, + Error **errp);void bdrv_invalidate_cache_all (Error **errp);int bdrv_inactivate_all (void );/* Ensure contents are flushed to disk. */ -int bdrv_flush (BlockDriverState *bs); +int generated_co_wrapper bdrv_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs);int bdrv_flush_all (void );void bdrv_close_all (void );
@@ -490,7 +493,8 @@ void bdrv_drain_all(void);AIO_WAIT_WHILE (bdrv_get_aio_context (bs_), \ cond); }) -int bdrv_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes); +int generated_co_wrapper bdrv_pdiscard(BdrvChild *child, int64_t offset, +int64_t bytes);int bdrv_co_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes);int bdrv_has_zero_init_1 (BlockDriverState *bs);int bdrv_has_zero_init (BlockDriverState *bs);
block.c +0 -73
85 lines not on this page · raw message
block/io.c +0 -212
269 lines not on this page · raw message
Signature · 1 line
2.26.2
[PULL 12/17] block: drop bdrv_prwv
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Now that we are not maintaining boilerplate code for coroutine wrappers, there is no more sense in keeping the extra indirection layer of bdrv_prwv(). Let's drop it and instead generate pure bdrv_preadv() and bdrv_pwritev().
Currently, bdrv_pwritev() and bdrv_preadv() are returning bytes on success, auto generated functions will instead return zero, as their _co_ prototype. Still, it's simple to make the conversion safe: the only external user of bdrv_pwritev() is test-bdrv-drain, and it is comfortable enough with bdrv_co_pwritev() instead. So prototypes are moved to local block/coroutines.h. Next, the only internal use is bdrv_pread() and bdrv_pwrite(), which are modified to return bytes on success.
Of course, it would be great to convert bdrv_pread() and bdrv_pwrite() to return 0 on success. But this requires audit (and probably conversion) of all their users, let's leave it for another day refactoring.
Message-Id: <[email protected]>
--- block/coroutines.h | 10 ++++----- include/block/block.h | 2 -- block/io.c | 49 ++++++++--------------------------------- tests/test-bdrv-drain.c | 2 +- 4 files changed, 15 insertions(+), 48 deletions(-)
block/coroutines.h +5 -5
@@ -31,12 +31,12 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp); -int coroutine_fn -bdrv_co_prwv (BdrvChild *child,int64_t offset,QEMUIOVector *qiov, -bool is_write,BdrvRequestFlags flags); int generated_co_wrapper -bdrv_prwv (BdrvChild *child,int64_t offset,QEMUIOVector *qiov, -bool is_write,BdrvRequestFlags flags); +bdrv_preadv (BdrvChild *child,int64_t offset,unsigned int bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags); +int generated_co_wrapper +bdrv_pwritev (BdrvChild *child,int64_t offset,unsigned int bytes, +QEMUIOVector *qiov,BdrvRequestFlags flags); int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs,
include/block/block.h +0 -2
@@ -383,9 +383,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags);int bdrv_make_zero (BdrvChild *child,BdrvRequestFlags flags);int bdrv_pread (BdrvChild *child,int64_t offset,void *buf,int bytes); -int bdrv_preadv (BdrvChild *child,int64_t offset,QEMUIOVector *qiov);int bdrv_pwrite (BdrvChild *child,int64_t offset,const void *buf,int bytes); -int bdrv_pwritev (BdrvChild *child,int64_t offset,QEMUIOVector *qiov);int bdrv_pwrite_sync (BdrvChild *child,int64_t offset,const void *buf,int count);/*
block/io.c +9 -40
86 lines not on this page · raw message
tests/test-bdrv-drain.c +1 -1
@@ -1872,7 +1872,7 @@ static int coroutine_fn bdrv_replace_test_co_preadv(BlockDriverState *bs, } s->io_co =NULL ; - ret =bdrv_preadv (bs->backing, offset, qiov); + ret =bdrv_co_preadv (bs->backing, offset, bytes, qiov,0 ); s->has_read = true;/* Wake up drain_co if it runs */
Signature · 1 line
2.26.2
[PULL 16/17] util/vfio-helpers: Collect IOVA reserved regions
In reply to Stefan HajnocziFrom: Eric Auger <[email protected]>
The IOVA allocator currently ignores host reserved regions. As a result some chosen IOVAs may collide with some of them, resulting in VFIO MAP_DMA errors later on. This happens on ARM where the MSI reserved window quickly is encountered:
[0x8000000, 0x8100000]. since 5.4 kernel, VFIO returns the usable IOVA regions. So let's enumerate them in the prospect to avoid them, later on.
Message-id: [email protected]
--- util/vfio-helpers.c | 72 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-)
util/vfio-helpers.c +70 -2
@@ -40,6 +40,11 @@ typedef struct {uint64_t iova; } IOVAMapping; +struct IOVARange { +uint64_t start; +uint64_t end; +}; +struct QEMUVFIOState {QemuMutex lock;
@@ -49,6 +54,8 @@ struct QEMUVFIOState {int device;RAMBlockNotifier ram_notifier;struct vfio_region_info config_region_info, bar_region_info[6 ]; +struct IOVARange *usable_iova_ranges; +uint8_t nb_iova_ranges;/* These fields are protected by @lock */ /* VFIO's IO virtual address space is managed by splitting into a few
@@ -236,6 +243,35 @@ static int qemu_vfio_pci_write_config(QEMUVFIOState *s, void *buf, int size, intreturn ret == size ?0 : -errno; } +static void collect_usable_iova_ranges (QEMUVFIOState *s,void *buf) +{ +struct vfio_iommu_type1_info *info = (struct vfio_iommu_type1_info *)buf; +struct vfio_info_cap_header *cap = (void *)buf + info->cap_offset; +struct vfio_iommu_type1_info_cap_iova_range *cap_iova_range; +int i; + +while (cap->id !=VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE ) { +if (!cap->next) { +return ; + } + cap = (struct vfio_info_cap_header *)(buf + cap->next); + } + + cap_iova_range = (struct vfio_iommu_type1_info_cap_iova_range *)cap; + + s->nb_iova_ranges = cap_iova_range->nr_iovas; +if (s->nb_iova_ranges >1 ) { + s->usable_iova_ranges = +g_realloc (s->usable_iova_ranges, + s->nb_iova_ranges *sizeof (struct IOVARange )); + } + +for (i =0 ; i < s->nb_iova_ranges; i++) { + s->usable_iova_ranges[i].start = cap_iova_range->iova_ranges[i].start; + s->usable_iova_ranges[i].end = cap_iova_range->iova_ranges[i].end; + } +} +static int qemu_vfio_init_pci (QEMUVFIOState *s,const char *device,Error **errp) {
@@ -243,10 +279,13 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,int i;uint16_t pci_cmd;struct vfio_group_status group_status = { .argsz =sizeof (group_status) }; -struct vfio_iommu_type1_info iommu_info = { .argsz =sizeof (iommu_info) }; +struct vfio_iommu_type1_info *iommu_info =NULL ; +size_t iommu_info_size =sizeof (*iommu_info);struct vfio_device_info device_info = { .argsz =sizeof (device_info) };char *group_file =NULL ; + s->usable_iova_ranges =NULL ; +/* Create a new container */ s->container =open ("/dev/vfio/vfio" ,O_RDWR );
@@ -310,13 +349,35 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device, goto fail; } + iommu_info =g_malloc0 (iommu_info_size); + iommu_info->argsz = iommu_info_size; +/* Get additional IOMMU info */ -if (ioctl (s->container,VFIO_IOMMU_GET_INFO , &iommu_info)) { +if (ioctl (s->container,VFIO_IOMMU_GET_INFO , iommu_info)) {error_setg_errno (errp, errno,"Failed to get IOMMU info" ); ret = -errno; goto fail; } +/* +* if the kernel does not report usable IOVA regions, choose +* the legacy [QEMU_VFIO_IOVA_MIN, QEMU_VFIO_IOVA_MAX -1] region +*/ + s->nb_iova_ranges =1 ; + s->usable_iova_ranges = g_new0(struct IOVARange, 1); + s->usable_iova_ranges[0 ].start =QEMU_VFIO_IOVA_MIN ; + s->usable_iova_ranges[0 ].end =QEMU_VFIO_IOVA_MAX -1 ; + +if (iommu_info->argsz > iommu_info_size) { + iommu_info_size = iommu_info->argsz; + iommu_info =g_realloc (iommu_info, iommu_info_size); +if (ioctl (s->container,VFIO_IOMMU_GET_INFO , iommu_info)) { + ret = -errno; + goto fail; + } +collect_usable_iova_ranges (s, iommu_info); + } + s->device =ioctl (s->group,VFIO_GROUP_GET_DEVICE_FD , device);if (s->device <0 ) {
@@ -365,8 +426,13 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device,if (ret) { goto fail; } +g_free (iommu_info);return 0 ; fail: +g_free (s->usable_iova_ranges); + s->usable_iova_ranges =NULL ; + s->nb_iova_ranges =0 ; +g_free (iommu_info);close (s->group); fail_container:close (s->container);
@@ -716,6 +782,8 @@ void qemu_vfio_close(QEMUVFIOState *s)qemu_vfio_undo_mapping (s, &s->mappings[i],NULL ); }ram_block_notifier_remove (&s->ram_notifier); +g_free (s->usable_iova_ranges); + s->nb_iova_ranges =0 ;qemu_vfio_reset (s);close (s->device);close (s->group);
Signature · 1 line
2.26.2
[PULL 14/17] include/block/block.h: drop non-ascii quotation mark
In reply to Stefan HajnocziFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
This is the only non-ascii character in the file and it doesn't really needed here. Let's use normal "'" symbol for consistency with the rest 11 occurrences of "'" in the file.
--- include/block/block.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/block/block.h +1 -1
@@ -304,7 +304,7 @@ enum BdrvChildRoleBits { BDRV_CHILD_FILTERED = (1 << 2),/* -* Child from which to read all data that isn’t allocated in the +* Child from which to read all data that isn't allocated in the * parent (i.e., the backing child); such data is copied to the * parent through COW (and optionally COR). * This field is mutually exclusive with DATA, METADATA, and
Signature · 1 line
2.26.2
Quoted 11 lines · Stefan Hajnoczi
The following changes since commit
b150cb8f67bf491a49a1cb1c7da151eeacbdbcc9:Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-09-29 13:18:54 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to
bc47831ff28d6f5830c9c8d74220131dc54c5253:
Quoted 8 lines
util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved regions (2020-09-30 10:23:05 +0100)
----------------------------------------------------------------
Pull requestNote I have switched from GitHub to GitLab.
----------------------------------------------------------------
This produces this error message on ppc64be Linux:
make: Entering directory /home/pm215/qemu/build/all' make[1]: Entering directory /home/pm215/qemu/slirp' make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/pm215/qemu/slirp' Generating qemu-version.h with a meson_exe.py custom command Generating qemu-options.def with a meson_exe.py custom command Generating block-gen.c with a custom command YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~
Error parsing -style: Invalid argument, using LLVM style YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~
Error parsing -style: Invalid argument, using LLVM style Compiling C object libqemuutil.a.p/util_qemu-error.c.o Compiling C object libqemuutil.a.p/util_qemu-sockets.c.o Compiling C object libqemuutil.a.p/util_aio-posix.c.o Compiling C object libqemuutil.a.p/util_osdep.c.o
The error does not cause the build to fail, which seems like it's also a bug...
(My guess is this is due to some script implicitly wanting a newer version of something or other than the PPC box happens to have installed, rather than being an endianness issue.)
thanks
-- PMM
Quoted 43 lines · Peter Maydell
Quoted 11 lines · Stefan Hajnoczi
The following changes since commit
b150cb8f67bf491a49a1cb1c7da151eeacbdbcc9:Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-09-29 13:18:54 +0100)are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to
bc47831ff28d6f5830c9c8d74220131dc54c5253:Quoted 8 lines
util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved regions (2020-09-30 10:23:05 +0100)
----------------------------------------------------------------
Pull requestNote I have switched from GitHub to GitLab.
----------------------------------------------------------------
This produces this error message on ppc64be Linux:
make: Entering directory
/home/pm215/qemu/build/all' make[1]: Entering directory/home/pm215/qemu/slirp' make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/pm215/qemu/slirp' Generatingqemu-version.hwith ameson_exe.pycustom command Generating qemu-options.def with ameson_exe.pycustom command Generatingblock-gen.cwith a custom command YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}^~~~~~~~Error parsing -style: Invalid argument, using LLVM style YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~
Quoted 8 lines
Error parsing -style: Invalid argument, using LLVM style Compiling C object
libqemuutil.a.p/util_qemu-error.c.oCompiling C objectlibqemuutil.a.p/util_qemu-sockets.c.oCompiling C objectlibqemuutil.a.p/util_aio-posix.c.oCompiling C objectlibqemuutil.a.p/util_osdep.c.oThe error does not cause the build to fail, which seems like it's also a bug...
YAML:1:83 is most probably "Custom" value for "BeakBeforeBraces" key, which is needed to enable custom brace wrapping, set with separate BraceWrapping key.
Not simple to find the version of clang which is first to support "Custom' here, but at least clang 3.6.1 doesn't support it.
Hm, I can "reproduce" like this:
[root@kvm work]# clang-format -style='{"BreakBeforeBraces": "Mega"}' int c() {}
YAML:1:23: error: unknown enumerated scalar {"BreakBeforeBraces": "Mega"}
^~~~~~
Error parsing -style: Invalid argument
[root@kvm work]# echo $?
1
.
Build doesn't fail because clang-formatting of generated code is optional, and error is ignored. But stderr output of clang-format is still printed and this is wrong.
To fix we need:
scripts/block-coroutine-wrapper.py +1 -1
@@ -43,7 +43,7 @@ def prettify(code: str) -> str: }) p = subprocess.run(['clang-format', f'-style={style}'], check=True, encoding='utf-8', input=code, - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE) return p.stdout except FileNotFoundError: return code
I can send a separate patch if it is convenient.
Quoted 9 lines
(My guess is this is due to some script implicitly wanting a newer version of something or other than the PPC box happens to have installed, rather than being an endianness issue.)
thanks
-- PMM
Signature · 2 lines
Best regards, Vladimir
Quoted 49 lines · Peter Maydell
Quoted 11 lines · Stefan Hajnoczi
The following changes since commit
b150cb8f67bf491a49a1cb1c7da151eeacbdbcc9:Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-09-29 13:18:54 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to
bc47831ff28d6f5830c9c8d74220131dc54c5253:Quoted 8 lines
util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved regions (2020-09-30 10:23:05 +0100)
----------------------------------------------------------------
Pull requestNote I have switched from GitHub to GitLab.
----------------------------------------------------------------
This produces this error message on ppc64be Linux:
make: Entering directory
/home/pm215/qemu/build/all' make[1]: Entering directory/home/pm215/qemu/slirp' make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/pm215/qemu/slirp' Generatingqemu-version.hwith ameson_exe.pycustom command Generating qemu-options.def with ameson_exe.pycustom command Generatingblock-gen.cwith a custom command YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}^~~~~~~~Error parsing -style: Invalid argument, using LLVM style YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~Error parsing -style: Invalid argument, using LLVM style Compiling C object
libqemuutil.a.p/util_qemu-error.c.oCompiling C objectlibqemuutil.a.p/util_qemu-sockets.c.oCompiling C objectlibqemuutil.a.p/util_aio-posix.c.oCompiling C objectlibqemuutil.a.p/util_osdep.c.o
Quoted 7 lines
The error does not cause the build to fail, which seems like it's also a bug...
(My guess is this is due to some script implicitly wanting a newer version of something or other than the PPC box happens to have installed, rather than being an endianness issue.)
Please rerun with make -j1 V=1 so the full command is printed. I'm not sure what is emitting these errors.
Thanks,
Stefan
Quoted 33 lines · Stefan Hajnoczi
Quoted 31 lines · Peter Maydell
This produces this error message on ppc64be Linux:
make: Entering directory
/home/pm215/qemu/build/all' make[1]: Entering directory/home/pm215/qemu/slirp' make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/pm215/qemu/slirp' Generatingqemu-version.hwith ameson_exe.pycustom command Generating qemu-options.def with ameson_exe.pycustom command Generatingblock-gen.cwith a custom command YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}^~~~~~~~Error parsing -style: Invalid argument, using LLVM style YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~Error parsing -style: Invalid argument, using LLVM style Compiling C object
libqemuutil.a.p/util_qemu-error.c.oCompiling C objectlibqemuutil.a.p/util_qemu-sockets.c.oCompiling C objectlibqemuutil.a.p/util_aio-posix.c.oCompiling C objectlibqemuutil.a.p/util_osdep.c.oThe error does not cause the build to fail, which seems like it's also a bug...
Quoted 7 lines
Quoted 4 lines
(My guess is this is due to some script implicitly wanting a newer version of something or other than the PPC box happens to have installed, rather than being an endianness issue.)
Please rerun with make -j1 V=1 so the full command is printed. I'm not sure what is emitting these errors.
Build tree already overwritten to handle a different pullreq, I'm afraid. I can come back and retry later...
thanks
-- PMM
Quoted 39 lines · Peter Maydell
Quoted 38 lines · Stefan Hajnoczi
Quoted 35 lines · Peter Maydell
This produces this error message on ppc64be Linux:
make: Entering directory
/home/pm215/qemu/build/all' make[1]: Entering directory/home/pm215/qemu/slirp' make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/pm215/qemu/slirp' Generatingqemu-version.hwith ameson_exe.pycustom command Generating qemu-options.def with ameson_exe.pycustom command Generatingblock-gen.cwith a custom command YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}^~~~~~~~Error parsing -style: Invalid argument, using LLVM style YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~Error parsing -style: Invalid argument, using LLVM style Compiling C object
libqemuutil.a.p/util_qemu-error.c.oCompiling C objectlibqemuutil.a.p/util_qemu-sockets.c.oCompiling C objectlibqemuutil.a.p/util_aio-posix.c.oCompiling C objectlibqemuutil.a.p/util_osdep.c.oThe error does not cause the build to fail, which seems like it's also a bug...
(My guess is this is due to some script implicitly wanting a newer version of something or other than the PPC box happens to have installed, rather than being an endianness issue.)
Quoted 5 lines
Quoted 2 lines
Please rerun with make -j1 V=1 so the full command is printed. I'm not sure what is emitting these errors.
Build tree already overwritten to handle a different pullreq, I'm afraid. I can come back and retry later...
No problem. Thanks for pointing out the issue, Vladimir and Peter.
I will send a v2.
Stefan
Quoted 53 lines · Stefan Hajnoczi
Quoted 52 lines · Peter Maydell
Quoted 11 lines · Stefan Hajnoczi
The following changes since commit
b150cb8f67bf491a49a1cb1c7da151eeacbdbcc9:Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-09-29 13:18:54 +0100)are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to
bc47831ff28d6f5830c9c8d74220131dc54c5253:Quoted 8 lines
util/vfio-helpers: Rework the IOVA allocator to avoid IOVA reserved regions (2020-09-30 10:23:05 +0100)
----------------------------------------------------------------
Pull requestNote I have switched from GitHub to GitLab.
----------------------------------------------------------------
This produces this error message on ppc64be Linux:
make: Entering directory
/home/pm215/qemu/build/all' make[1]: Entering directory/home/pm215/qemu/slirp' make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/pm215/qemu/slirp' Generatingqemu-version.hwith ameson_exe.pycustom command Generating qemu-options.def with ameson_exe.pycustom command Generatingblock-gen.cwith a custom command YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}^~~~~~~~Error parsing -style: Invalid argument, using LLVM style YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~Error parsing -style: Invalid argument, using LLVM style Compiling C object
libqemuutil.a.p/util_qemu-error.c.oCompiling C objectlibqemuutil.a.p/util_qemu-sockets.c.oCompiling C objectlibqemuutil.a.p/util_aio-posix.c.oCompiling C objectlibqemuutil.a.p/util_osdep.c.oThe error does not cause the build to fail, which seems like it's also a bug...
Quoted 8 lines
Quoted 4 lines
(My guess is this is due to some script implicitly wanting a newer version of something or other than the PPC box happens to have installed, rather than being an endianness issue.)
Please rerun with make -j1 V=1 so the full command is printed. I'm not sure what is emitting these errors.
For sure it's block-coroutine-wrapper.py. I've send a letter with some investigation and solution, did you get it?
Signature · 2 lines
Best regards, Vladimir
Quoted 2 lines · Stefan Hajnoczi
Please rerun with make -j1 V=1 so the full command is printed. I'm not sure what is emitting these errors.
Vladimir's guess was correct:
/usr/bin/python3 /home/pm215/qemu/block/../scripts/block-coroutine-wrapper.py block/block-gen.c ../../block/../include/block/block.h ../../block/coroutines.h && if test -e block/block-gen.c; then printf '%s\n' block/block-gen.c > block/block-gen.c.stamp; fi YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~
Error parsing -style: Invalid argument, using LLVM style YAML:1:83: error: unknown enumerated scalar {"IndentWidth": 4, "BraceWrapping": {"AfterFunction": true}, "BreakBeforeBraces": "Custom", "SortIncludes": false, "MaxEmptyLinesToKeep": 2}
^~~~~~~~
Error parsing -style: Invalid argument, using LLVM style
thanks
-- PMM