Skip to contentSkip to conversation

Block patches

GIT PULL Applied Stefan Hajnoczi 2 participants 4 messages Aug 22, 2019 – Aug 27, 2019

lore
Share & tools
lore
#0 lore raw

The following changes since commit 33f18cf7dca7741d3647d514040904ce83edd73d:

Merge remote-tracking branch 'remotes/kraxel/tags/audio-20190821-pull-request' into staging (2019-08-21 15:18:50 +0100)

are available in the Git repository at:

https://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 5d4c1ed3d46d7e2010b389fe5f3376f605182ab0:

vhost-user-scsi: prevent using uninitialized vqs (2019-08-22 16:52:23 +0100)

----------------------------------------------------------------
Pull request

----------------------------------------------------------------

Raphael Norwitz (1):
vhost-user-scsi: prevent using uninitialized vqs

Stefan Hajnoczi (1):
util/async: hold AioContext ref to prevent use-after-free

 hw/scsi/vhost-user-scsi.c | 2 +-
 util/async.c              | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.21.0
#1 lore raw

[Qemu-devel] [PULL 1/2] util/async: hold AioContext ref to prevent use-after-free

The tests/test-bdrv-drain /bdrv-drain/iothread/drain test case does the following:

1. The preadv coroutine calls aio_bh_schedule_oneshot() and then yields.
2. The one-shot BH executes in another AioContext. All it does is call aio_co_wakeup(preadv_co).
3. The preadv coroutine is re-entered and returns.

There is a race condition in aio_co_wake() where the preadv coroutine returns and the test case destroys the preadv IOThread. aio_co_wake() can still be running in the other AioContext and it performs an access to the freed IOThread AioContext.

Here is the race in aio_co_schedule():

QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines,

                            co, co_scheduled_next);

<-- race: co may execute before we invoke qemu_bh_schedule()! qemu_bh_schedule(ctx->co_schedule_bh);

So if co causes ctx to be freed then we're in trouble. Fix this problem by holding a reference to ctx.

Message-id: [email protected]
Message-Id: <[email protected]>

---
 util/async.c | 8 ++++++++
 1 file changed, 8 insertions(+)
util/async.c +8 -0
index 8d2105729c..4e4c7af51e 100644
@@ -459,9 +459,17 @@ void aio_co_schedule(AioContext *ctx, Coroutine *co)
         abort();
     }
 
+    /* The coroutine might run and release the last ctx reference before we
+     * invoke qemu_bh_schedule().  Take a reference to keep ctx alive until
+     * we're done.
+     */
+    aio_context_ref(ctx);
+
     QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines,
                               co, co_scheduled_next);
     qemu_bh_schedule(ctx->co_schedule_bh);
+
+    aio_context_unref(ctx);
 }
 
 void aio_co_wake(struct Coroutine *co)
Signature · 1 line
2.21.0
#2 lore raw

[Qemu-devel] [PULL 2/2] vhost-user-scsi: prevent using uninitialized vqs

In reply to Stefan Hajnoczi

From: Raphael Norwitz <[email protected]>

Of the 3 virtqueues, seabios only sets cmd, leaving ctrl and event without a physical address. This can cause vhost_verify_ring_part_mapping to return ENOMEM, causing the following logs:

qemu-system-x86_64: Unable to map available ring for ring 0
qemu-system-x86_64: Verify ring failure on region 0

The qemu commit e6cc11d64fc998c11a4dfcde8fda3fc33a74d844 has already resolved the issue for vhost scsi devices but the fix was never applied to vhost-user scsi devices.

Message-id: [email protected]
Message-Id: <[email protected]>

---
 hw/scsi/vhost-user-scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/vhost-user-scsi.c +1 -1
index 31c9d34637..6a6c15dd32 100644
@@ -93,7 +93,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)
     }
 
     vsc->dev.nvqs = 2 + vs->conf.num_queues;
-    vsc->dev.vqs = g_new(struct vhost_virtqueue, vsc->dev.nvqs);
+    vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs);
     vsc->dev.vq_index = 0;
     vsc->dev.backend_features = 0;
     vqs = vsc->dev.vqs;
Signature · 1 line
2.21.0
#3 lore raw
In reply to Stefan Hajnoczi
Quoted 9 lines · Stefan Hajnoczi

The following changes since commit 33f18cf7dca7741d3647d514040904ce83edd73d:

Merge remote-tracking branch 'remotes/kraxel/tags/audio-20190821-pull-request' into staging (2019-08-21 15:18:50 +0100)

are available in the Git repository at:

https://github.com/stefanha/qemu.git tags/block-pull-request

Quoted 8 lines

for you to fetch changes up to 5d4c1ed3d46d7e2010b389fe5f3376f605182ab0:

vhost-user-scsi: prevent using uninitialized vqs (2019-08-22 16:52:23 +0100)

----------------------------------------------------------------
Pull request

----------------------------------------------------------------

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.2
for any user-visible changes.

-- PMM