Markus Armbruster
Committed by Peter Maydell

vfio-helpers: Fix qemu_vfio_open_pci() crash

qemu_vfio_open_common() initializes s->lock only after passing s to
qemu_vfio_dma_map() via qemu_vfio_init_ramblock().
qemu_vfio_dma_map() tries to lock the uninitialized lock and crashes.

Fix by initializing s->lock first.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1645840
Fixes: 418026ca
Cc: qemu-stable@nongnu.org
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 20181127084143.1113-1-armbru@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
@@ -411,13 +411,13 @@ static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr, @@ -411,13 +411,13 @@ static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr,
411 411
412 static void qemu_vfio_open_common(QEMUVFIOState *s) 412 static void qemu_vfio_open_common(QEMUVFIOState *s)
413 { 413 {
  414 + qemu_mutex_init(&s->lock);
414 s->ram_notifier.ram_block_added = qemu_vfio_ram_block_added; 415 s->ram_notifier.ram_block_added = qemu_vfio_ram_block_added;
415 s->ram_notifier.ram_block_removed = qemu_vfio_ram_block_removed; 416 s->ram_notifier.ram_block_removed = qemu_vfio_ram_block_removed;
416 ram_block_notifier_add(&s->ram_notifier); 417 ram_block_notifier_add(&s->ram_notifier);
417 s->low_water_mark = QEMU_VFIO_IOVA_MIN; 418 s->low_water_mark = QEMU_VFIO_IOVA_MIN;
418 s->high_water_mark = QEMU_VFIO_IOVA_MAX; 419 s->high_water_mark = QEMU_VFIO_IOVA_MAX;
419 qemu_ram_foreach_block(qemu_vfio_init_ramblock, s); 420 qemu_ram_foreach_block(qemu_vfio_init_ramblock, s);
420 - qemu_mutex_init(&s->lock);  
421 } 421 }
422 422
423 /** 423 /**