Skip to content
Snippets Groups Projects
  1. Sep 11, 2023
  2. Sep 08, 2023
    • Stefan Hajnoczi's avatar
      io: follow coroutine AioContext in qio_channel_yield() · 06e0f098
      Stefan Hajnoczi authored
      
      The ongoing QEMU multi-queue block layer effort makes it possible for multiple
      threads to process I/O in parallel. The nbd block driver is not compatible with
      the multi-queue block layer yet because QIOChannel cannot be used easily from
      coroutines running in multiple threads. This series changes the QIOChannel API
      to make that possible.
      
      In the current API, calling qio_channel_attach_aio_context() sets the
      AioContext where qio_channel_yield() installs an fd handler prior to yielding:
      
        qio_channel_attach_aio_context(ioc, my_ctx);
        ...
        qio_channel_yield(ioc); // my_ctx is used here
        ...
        qio_channel_detach_aio_context(ioc);
      
      This API design has limitations: reading and writing must be done in the same
      AioContext and moving between AioContexts involves a cumbersome sequence of API
      calls that is not suitable for doing on a per-request basis.
      
      There is no fundamental reason why a QIOChannel needs to run within the
      same AioContext every time qio_channel_yield() is called. QIOChannel
      only uses the AioContext while inside qio_channel_yield(). The rest of
      the time, QIOChannel is independent of any AioContext.
      
      In the new API, qio_channel_yield() queries the AioContext from the current
      coroutine using qemu_coroutine_get_aio_context(). There is no need to
      explicitly attach/detach AioContexts anymore and
      qio_channel_attach_aio_context() and qio_channel_detach_aio_context() are gone.
      One coroutine can read from the QIOChannel while another coroutine writes from
      a different AioContext.
      
      This API change allows the nbd block driver to use QIOChannel from any thread.
      It's important to keep in mind that the block driver already synchronizes
      QIOChannel access and ensures that two coroutines never read simultaneously or
      write simultaneously.
      
      This patch updates all users of qio_channel_attach_aio_context() to the
      new API. Most conversions are simple, but vhost-user-server requires a
      new qemu_coroutine_yield() call to quiesce the vu_client_trip()
      coroutine when not attached to any AioContext.
      
      While the API is has become simpler, there is one wart: QIOChannel has a
      special case for the iohandler AioContext (used for handlers that must not run
      in nested event loops). I didn't find an elegant way preserve that behavior, so
      I added a new API called qio_channel_set_follow_coroutine_ctx(ioc, true|false)
      for opting in to the new AioContext model. By default QIOChannel uses the
      iohandler AioHandler. Code that formerly called
      qio_channel_attach_aio_context() now calls
      qio_channel_set_follow_coroutine_ctx(ioc, true) once after the QIOChannel is
      created.
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Acked-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Message-ID: <20230830224802.493686-5-stefanha@redhat.com>
      [eblake: also fix migration/rdma.c]
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      06e0f098
  3. Aug 30, 2023
    • Fabiano Rosas's avatar
      block-migration: Ensure we don't crash during migration cleanup · f187609f
      Fabiano Rosas authored
      
      We can fail the blk_insert_bs() at init_blk_migration(), leaving the
      BlkMigDevState without a dirty_bitmap and BlockDriverState. Account
      for the possibly missing elements when doing cleanup.
      
      Fix the following crashes:
      
      Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
      0x0000555555ec83ef in bdrv_release_dirty_bitmap (bitmap=0x0) at ../block/dirty-bitmap.c:359
      359         BlockDriverState *bs = bitmap->bs;
       #0  0x0000555555ec83ef in bdrv_release_dirty_bitmap (bitmap=0x0) at ../block/dirty-bitmap.c:359
       #1  0x0000555555bba331 in unset_dirty_tracking () at ../migration/block.c:371
       #2  0x0000555555bbad98 in block_migration_cleanup_bmds () at ../migration/block.c:681
      
      Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
      0x0000555555e971ff in bdrv_op_unblock (bs=0x0, op=BLOCK_OP_TYPE_BACKUP_SOURCE, reason=0x0) at ../block.c:7073
      7073        QLIST_FOREACH_SAFE(blocker, &bs->op_blockers[op], list, next) {
       #0  0x0000555555e971ff in bdrv_op_unblock (bs=0x0, op=BLOCK_OP_TYPE_BACKUP_SOURCE, reason=0x0) at ../block.c:7073
       #1  0x0000555555e9734a in bdrv_op_unblock_all (bs=0x0, reason=0x0) at ../block.c:7095
       #2  0x0000555555bbae13 in block_migration_cleanup_bmds () at ../migration/block.c:690
      
      Signed-off-by: default avatarFabiano Rosas <farosas@suse.de>
      Message-id: 20230731203338.27581-1-farosas@suse.de
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      f187609f
  4. Aug 29, 2023
  5. Jul 26, 2023
  6. Jul 25, 2023
  7. Jul 12, 2023
  8. Jul 08, 2023
  9. Jun 30, 2023
  10. Jun 20, 2023
  11. Jun 13, 2023
    • Steve Sistare's avatar
      exec/memory: Introduce RAM_NAMED_FILE flag · b0182e53
      Steve Sistare authored
      
      migrate_ignore_shared() is an optimization that avoids copying memory
      that is visible and can be mapped on the target.  However, a
      memory-backend-ram or a memory-backend-memfd block with the RAM_SHARED
      flag set is not migrated when migrate_ignore_shared() is true.  This is
      wrong, because the block has no named backing store, and its contents will
      be lost.  To fix, ignore shared memory iff it is a named file.  Define a
      new flag RAM_NAMED_FILE to distinguish this case.
      
      Signed-off-by: default avatarSteve Sistare <steven.sistare@oracle.com>
      Reviewed-by: default avatarPeter Xu <peterx@redhat.com>
      Message-Id: <1686151116-253260-1-git-send-email-steven.sistare@oracle.com>
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      b0182e53
  12. Jun 05, 2023
  13. Jun 01, 2023
  14. May 30, 2023
    • Stefan Hajnoczi's avatar
      aio: remove aio_disable_external() API · 60f782b6
      Stefan Hajnoczi authored
      All callers now pass is_external=false to aio_set_fd_handler() and
      aio_set_event_notifier(). The aio_disable_external() API that
      temporarily disables fd handlers that were registered is_external=true
      is therefore dead code.
      
      Remove aio_disable_external(), aio_enable_external(), and the
      is_external arguments to aio_set_fd_handler() and
      aio_set_event_notifier().
      
      The entire test-fdmon-epoll test is removed because its sole purpose was
      testing aio_disable_external().
      
      Parts of this patch were generated using the following coccinelle
      (https://coccinelle.lip6.fr/
      
      ) semantic patch:
      
        @@
        expression ctx, fd, is_external, io_read, io_write, io_poll, io_poll_ready, opaque;
        @@
        - aio_set_fd_handler(ctx, fd, is_external, io_read, io_write, io_poll, io_poll_ready, opaque)
        + aio_set_fd_handler(ctx, fd, io_read, io_write, io_poll, io_poll_ready, opaque)
      
        @@
        expression ctx, notifier, is_external, io_read, io_poll, io_poll_ready;
        @@
        - aio_set_event_notifier(ctx, notifier, is_external, io_read, io_poll, io_poll_ready)
        + aio_set_event_notifier(ctx, notifier, io_read, io_poll, io_poll_ready)
      
      Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-Id: <20230516190238.8401-21-stefanha@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      60f782b6
Loading