Skip to content
  • Kevin Wolf's avatar
    960d5fb3
    block: Fix deadlock in bdrv_co_yield_to_drain() · 960d5fb3
    Kevin Wolf authored
    If bdrv_co_yield_to_drain() is called for draining a block node that
    runs in a different AioContext, it keeps that AioContext locked while it
    yields and schedules a BH in the AioContext to do the actual drain.
    
    As long as executing the BH is the very next thing that the event loop
    of the node's AioContext does, this actually happens to work, but when
    it tries to execute something else that wants to take the AioContext
    lock, it will deadlock. (In the bug report, this other thing is a
    virtio-scsi device running virtio_scsi_data_plane_handle_cmd().)
    
    Instead, always drop the AioContext lock across the yield and reacquire
    it only when the coroutine is reentered. The BH needs to unconditionally
    take the lock for itself now.
    
    This fixes the 'block_resize' QMP command on a block node that runs in
    an iothread.
    
    Cc: qemu-stable@nongnu.org
    Fixes: eb94b81a
    Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1903511
    
    
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    Message-Id: <20201203172311.68232-4-kwolf@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    960d5fb3
    block: Fix deadlock in bdrv_co_yield_to_drain()
    Kevin Wolf authored
    If bdrv_co_yield_to_drain() is called for draining a block node that
    runs in a different AioContext, it keeps that AioContext locked while it
    yields and schedules a BH in the AioContext to do the actual drain.
    
    As long as executing the BH is the very next thing that the event loop
    of the node's AioContext does, this actually happens to work, but when
    it tries to execute something else that wants to take the AioContext
    lock, it will deadlock. (In the bug report, this other thing is a
    virtio-scsi device running virtio_scsi_data_plane_handle_cmd().)
    
    Instead, always drop the AioContext lock across the yield and reacquire
    it only when the coroutine is reentered. The BH needs to unconditionally
    take the lock for itself now.
    
    This fixes the 'block_resize' QMP command on a block node that runs in
    an iothread.
    
    Cc: qemu-stable@nongnu.org
    Fixes: eb94b81a
    Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1903511
    
    
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    Message-Id: <20201203172311.68232-4-kwolf@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Loading