Skip to content
Snippets Groups Projects
  1. Sep 23, 2020
    • Stefan Hajnoczi's avatar
      qemu/atomic.h: rename atomic_ to qatomic_ · d73415a3
      Stefan Hajnoczi authored
      
      clang's C11 atomic_fetch_*() functions only take a C11 atomic type
      pointer argument. QEMU uses direct types (int, etc) and this causes a
      compiler error when a QEMU code calls these functions in a source file
      that also included <stdatomic.h> via a system header file:
      
        $ CC=clang CXX=clang++ ./configure ... && make
        ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)
      
      Avoid using atomic_*() names in QEMU's atomic.h since that namespace is
      used by <stdatomic.h>. Prefix QEMU's APIs with 'q' so that atomic.h
      and <stdatomic.h> can co-exist. I checked /usr/include on my machine and
      searched GitHub for existing "qatomic_" users but there seem to be none.
      
      This patch was generated using:
      
        $ git grep -h -o '\<atomic\(64\)\?_[a-z0-9_]\+' include/qemu/atomic.h | \
          sort -u >/tmp/changed_identifiers
        $ for identifier in $(</tmp/changed_identifiers); do
              sed -i "s%\<$identifier\>%q$identifier%g" \
                  $(git grep -I -l "\<$identifier\>")
          done
      
      I manually fixed line-wrap issues and misaligned rST tables.
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200923105646.47864-1-stefanha@redhat.com>
      d73415a3
  2. May 18, 2020
  3. May 05, 2020
  4. Mar 11, 2020
  5. Dec 18, 2019
  6. Sep 16, 2019
  7. Sep 10, 2019
  8. Aug 16, 2019
    • Markus Armbruster's avatar
      Include qemu/main-loop.h less · db725815
      Markus Armbruster authored
      
      In my "build everything" tree, changing qemu/main-loop.h triggers a
      recompile of some 5600 out of 6600 objects (not counting tests and
      objects that don't depend on qemu/osdep.h).  It includes block/aio.h,
      which in turn includes qemu/event_notifier.h, qemu/notify.h,
      qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
      qemu/thread.h, qemu/timer.h, and a few more.
      
      Include qemu/main-loop.h only where it's needed.  Touching it now
      recompiles only some 1700 objects.  For block/aio.h and
      qemu/event_notifier.h, these numbers drop from 5600 to 2800.  For the
      others, they shrink only slightly.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190812052359.30071-21-armbru@redhat.com>
      Reviewed-by: default avatarAlex Bennée <alex.bennee@linaro.org>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      db725815
    • Kevin Wolf's avatar
      block-backend: Queue requests while drained · cf312932
      Kevin Wolf authored
      
      This fixes devices like IDE that can still start new requests from I/O
      handlers in the CPU thread while the block backend is drained.
      
      The basic assumption is that in a drain section, no new requests should
      be allowed through a BlockBackend (blk_drained_begin/end don't exist,
      we get drain sections only on the node level). However, there are two
      special cases where requests should not be queued:
      
      1. Block jobs: We already make sure that block jobs are paused in a
         drain section, so they won't start new requests. However, if the
         drain_begin is called on the job's BlockBackend first, it can happen
         that we deadlock because the job stays busy until it reaches a pause
         point - which it can't if its requests aren't processed any more.
      
         The proper solution here would be to make all requests through the
         job's filter node instead of using a BlockBackend. For now, just
         disabling request queuing on the job BlockBackend is simpler.
      
      2. In test cases where making requests through bdrv_* would be
         cumbersome because we'd need a BdrvChild. As we already got the
         functionality to disable request queuing from 1., use it in tests,
         too, for convenience.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      cf312932
  9. Jul 19, 2019
    • Hanna Reitz's avatar
      block: Do not poll in bdrv_do_drained_end() · e037c09c
      Hanna Reitz authored
      
      We should never poll anywhere in bdrv_do_drained_end() (including its
      recursive callees like bdrv_drain_invoke()), because it does not cope
      well with graph changes.  In fact, it has been written based on the
      postulation that no graph changes will happen in it.
      
      Instead, the callers that want to poll must poll, i.e. all currently
      globally available wrappers: bdrv_drained_end(),
      bdrv_subtree_drained_end(), bdrv_unapply_subtree_drain(), and
      bdrv_drain_all_end().  Graph changes there do not matter.
      
      They can poll simply by passing a pointer to a drained_end_counter and
      wait until it reaches 0.
      
      This patch also adds a non-polling global wrapper for
      bdrv_do_drained_end() that takes a drained_end_counter pointer.  We need
      such a variant because now no function called anywhere from
      bdrv_do_drained_end() must poll.  This includes
      BdrvChildRole.drained_end(), which already must not poll according to
      its interface documentation, but bdrv_child_cb_drained_end() just
      violates that by invoking bdrv_drained_end() (which does poll).
      Therefore, BdrvChildRole.drained_end() must take a *drained_end_counter
      parameter, which bdrv_child_cb_drained_end() can pass on to the new
      bdrv_drained_end_no_poll() function.
      
      Note that we now have a pattern of all drained_end-related functions
      either polling or receiving a *drained_end_counter to let the caller
      poll based on that.
      
      A problem with a single poll loop is that when the drained section in
      bdrv_set_aio_context_ignore() ends, some nodes in the subgraph may be in
      the old contexts, while others are in the new context already.  To let
      the collective poll in bdrv_drained_end() work correctly, we must not
      hold a lock to the old context, so that the old context can make
      progress in case it is different from the current context.
      
      (In the process, remove the comment saying that the current context is
      always the old context, because it is wrong.)
      
      In all other places, all nodes in a subtree must be in the same context,
      so we can just poll that.  The exception of course is
      bdrv_drain_all_end(), but that always runs in the main context, so we
      can just poll NULL (like bdrv_drain_all_begin() does).
      
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      e037c09c
  10. Jun 18, 2019
  11. Jun 12, 2019
    • Markus Armbruster's avatar
      Include qemu-common.h exactly where needed · a8d25326
      Markus Armbruster authored
      
      No header includes qemu-common.h after this commit, as prescribed by
      qemu-common.h's file comment.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-5-armbru@redhat.com>
      [Rebased with conflicts resolved automatically, except for
      include/hw/arm/xlnx-zynqmp.h hw/arm/nrf51_soc.c hw/arm/msf2-soc.c
      block/qcow2-refcount.c block/qcow2-cluster.c block/qcow2-cache.c
      target/arm/cpu.h target/lm32/cpu.h target/m68k/cpu.h target/mips/cpu.h
      target/moxie/cpu.h target/nios2/cpu.h target/openrisc/cpu.h
      target/riscv/cpu.h target/tilegx/cpu.h target/tricore/cpu.h
      target/unicore32/cpu.h target/xtensa/cpu.h; bsd-user/main.c and
      net/tap-bsd.c fixed up]
      a8d25326
  12. Jun 04, 2019
    • Kevin Wolf's avatar
      block: Adjust AioContexts when attaching nodes · 132ada80
      Kevin Wolf authored
      
      So far, we only made sure that updating the AioContext of a node
      affected the whole subtree. However, if a node is newly attached to a
      new parent, we also need to make sure that both the subtree of the node
      and the parent are in the same AioContext. This tries to move the new
      child node to the parent AioContext and returns an error if this isn't
      possible.
      
      BlockBackends now actually apply their AioContext to their root node.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      132ada80
    • Kevin Wolf's avatar
      block: Add BlockBackend.ctx · d861ab3a
      Kevin Wolf authored
      
      This adds a new parameter to blk_new() which requires its callers to
      declare from which AioContext this BlockBackend is going to be used (or
      the locks of which AioContext need to be taken anyway).
      
      The given context is only stored and kept up to date when changing
      AioContexts. Actually applying the stored AioContext to the root node
      is saved for another commit.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      d861ab3a
  13. May 28, 2019
    • Alberto Garcia's avatar
      block: Make bdrv_root_attach_child() unref child_bs on failure · b441dc71
      Alberto Garcia authored
      
      A consequence of the previous patch is that bdrv_attach_child()
      transfers the reference to child_bs from the caller to parent_bs,
      which will drop it on bdrv_close() or when someone calls
      bdrv_unref_child().
      
      But this only happens when bdrv_attach_child() succeeds. If it fails
      then the caller is responsible for dropping the reference to child_bs.
      
      This patch makes bdrv_attach_child() take the reference also when
      there is an error, freeing the caller for having to do it.
      
      A similar situation happens with bdrv_root_attach_child(), so the
      changes on this patch affect both functions.
      
      Signed-off-by: default avatarAlberto Garcia <berto@igalia.com>
      Message-id: 20dfb3d9ccec559cdd1a9690146abad5d204a186.1557754872.git.berto@igalia.com
      [mreitz: Removed now superfluous BdrvChild * variable in
               bdrv_open_child()]
      Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
      b441dc71
  14. May 20, 2019
    • Kevin Wolf's avatar
      blockjob: Remove AioContext notifiers · 657e1203
      Kevin Wolf authored
      
      The notifiers made sure that the job is quiesced and that the
      job->aio_context field is updated. The first part is unnecessary today
      since bdrv_set_aio_context_ignore() drains the block node, and this
      means drainig the block job, too. The second part can be done in the
      .set_aio_ctx callback of the block job BdrvChildRole.
      
      The notifiers were problematic because they poll the AioContext while
      the graph is in an inconsistent state with some nodes already in the new
      context, but others still in the old context. So removing the notifiers
      not only simplifies the code, but actually makes the code safer.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      657e1203
    • Kevin Wolf's avatar
      blockjob: Propagate AioContext change to all job nodes · 9ff7f0df
      Kevin Wolf authored
      
      Block jobs require that all of the nodes the job is using are in the
      same AioContext. Therefore all BdrvChild objects of the job propagate
      .(can_)set_aio_context to all other job nodes, so that the switch is
      checked and performed consistently even if both nodes are in different
      subtrees.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      9ff7f0df
  15. Mar 19, 2019
  16. Sep 25, 2018
    • Kevin Wolf's avatar
      block: Use a single global AioWait · cfe29d82
      Kevin Wolf authored
      
      When draining a block node, we recurse to its parent and for subtree
      drains also to its children. A single AIO_WAIT_WHILE() is then used to
      wait for bdrv_drain_poll() to become true, which depends on all of the
      nodes we recursed to. However, if the respective child or parent becomes
      quiescent and calls bdrv_wakeup(), only the AioWait of the child/parent
      is checked, while AIO_WAIT_WHILE() depends on the AioWait of the
      original node.
      
      Fix this by using a single AioWait for all callers of AIO_WAIT_WHILE().
      
      This may mean that the draining thread gets a few more unnecessary
      wakeups because an unrelated operation got completed, but we already
      wake it up when something _could_ have changed rather than only if it
      has certainly changed.
      
      Apart from that, drain is a slow path anyway. In theory it would be
      possible to use wakeups more selectively and still correctly, but the
      gains are likely not worth the additional complexity. In fact, this
      patch is a nice simplification for some places in the code.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      cfe29d82
    • Kevin Wolf's avatar
      blockjob: Lie better in child_job_drained_poll() · b5a7a057
      Kevin Wolf authored
      
      Block jobs claim in .drained_poll() that they are in a quiescent state
      as soon as job->deferred_to_main_loop is true. This is obviously wrong,
      they still have a completion BH to run. We only get away with this
      because commit 91af091f added an unconditional aio_poll(false) to the
      drain functions, but this is bypassing the regular drain mechanisms.
      
      However, just removing this and telling that the job is still active
      doesn't work either: The completion callbacks themselves call drain
      functions (directly, or indirectly with bdrv_reopen), so they would
      deadlock then.
      
      As a better lie, tell that the job is active as long as the BH is
      pending, but falsely call it quiescent from the point in the BH when the
      completion callback is called. At this point, nested drain calls won't
      deadlock because they ignore the job, and outer drains will wait for the
      job to really reach a quiescent state because the callback is already
      running.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      b5a7a057
    • Kevin Wolf's avatar
      blockjob: Wake up BDS when job becomes idle · 34dc97b9
      Kevin Wolf authored
      
      In the context of draining a BDS, the .drained_poll callback of block
      jobs is called. If this returns true (i.e. there is still some activity
      pending), the drain operation may call aio_poll() with blocking=true to
      wait for completion.
      
      As soon as the pending activity is completed and the job finally arrives
      in a quiescent state (i.e. its coroutine either yields with busy=false
      or terminates), the block job must notify the aio_poll() loop to wake
      up, otherwise we get a deadlock if both are running in different
      threads.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Reviewed-by: default avatarFam Zheng <famz@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      34dc97b9
  17. Aug 28, 2018
  18. Jun 18, 2018
    • Kevin Wolf's avatar
      block: Really pause block jobs on drain · 89bd0305
      Kevin Wolf authored
      
      We already requested that block jobs be paused in .bdrv_drained_begin,
      but no guarantee was made that the job was actually inactive at the
      point where bdrv_drained_begin() returned.
      
      This introduces a new callback BdrvChildRole.bdrv_drained_poll() and
      uses it to make bdrv_drain_poll() consider block jobs using the node to
      be drained.
      
      For the test case to work as expected, we have to switch from
      block_job_sleep_ns() to qemu_co_sleep_ns() so that the test job is even
      considered active and must be waited for when draining the node.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      89bd0305
  19. May 23, 2018
Loading