Message ID | 1459342088-24311-7-git-send-email-pbonzini@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, 30 Mar 2016 14:48:05 +0200 Paolo Bonzini <pbonzini@redhat.com> wrote: > From: "Michael S. Tsirkin" <mst@redhat.com> > > In addition to handling IO in vcpu thread and in io thread, dataplane > introduces yet another mode: handling it by aio. > > This reuses the same handler as previous modes, which triggers races as > these were not designed to be reentrant. > > Use a separate handler just for aio, and disable regular handlers when > dataplane is active. > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > hw/block/dataplane/virtio-blk.c | 13 +++++++++++++ > hw/block/virtio-blk.c | 27 +++++++++++++++++---------- > include/hw/virtio/virtio-blk.h | 2 ++ > 3 files changed, 32 insertions(+), 10 deletions(-) > > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c > index 77221c1..47ad9ed 100644 > --- a/hw/block/virtio-blk.c > +++ b/hw/block/virtio-blk.c > @@ -577,20 +577,11 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) > } > } > > -static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) > +void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq) > { > - VirtIOBlock *s = VIRTIO_BLK(vdev); > VirtIOBlockReq *req; > MultiReqBuffer mrb = {}; > > - /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start > - * dataplane here instead of waiting for .set_status(). > - */ > - if (s->dataplane && !s->dataplane_started) { > - virtio_blk_data_plane_start(s->dataplane); > - return; > - } > - > assert(atomic_fetch_inc(&s->reentrancy_test) == 0); Hm, based on wrong branch? > blk_io_plug(s->blk); >
On 30/03/2016 17:25, Cornelia Huck wrote: >> > >> > - /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start >> > - * dataplane here instead of waiting for .set_status(). >> > - */ >> > - if (s->dataplane && !s->dataplane_started) { >> > - virtio_blk_data_plane_start(s->dataplane); >> > - return; >> > - } >> > - >> > assert(atomic_fetch_inc(&s->reentrancy_test) == 0); > Hm, based on wrong branch? > Indeed I had the testing patch in there for, well, testing. I'll repost with improved commit messages and the assertion removed. Paolo
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 378feb3..4a137df 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -183,6 +183,17 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s) g_free(s); } +static void virtio_blk_data_plane_handle_output(VirtIODevice *vdev, + VirtQueue *vq) +{ + VirtIOBlock *s = (VirtIOBlock *)vdev; + + assert(s->dataplane); + assert(s->dataplane_started); + + virtio_blk_handle_vq(s, vq); +} + /* Context: QEMU global mutex held */ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) { @@ -225,6 +236,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) /* Get this show started by hooking up our callbacks */ aio_context_acquire(s->ctx); + virtio_set_queue_aio(s->vq, virtio_blk_data_plane_handle_output); virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, true, true); aio_context_release(s->ctx); return; @@ -261,6 +273,7 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) /* Stop notifications for new requests from guest */ virtio_queue_aio_set_host_notifier_handler(s->vq, s->ctx, true, false); + virtio_set_queue_aio(s->vq, NULL); /* Drain and switch bs back to the QEMU main loop */ blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context()); diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 77221c1..47ad9ed 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -577,20 +577,11 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) } } -static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) +void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq) { - VirtIOBlock *s = VIRTIO_BLK(vdev); VirtIOBlockReq *req; MultiReqBuffer mrb = {}; - /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start - * dataplane here instead of waiting for .set_status(). - */ - if (s->dataplane && !s->dataplane_started) { - virtio_blk_data_plane_start(s->dataplane); - return; - } - assert(atomic_fetch_inc(&s->reentrancy_test) == 0); blk_io_plug(s->blk); @@ -606,6 +597,22 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) atomic_dec(&s->reentrancy_test); } +static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOBlock *s = (VirtIOBlock *)vdev; + + if (s->dataplane) { + /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start + * dataplane here instead of waiting for .set_status(). + */ + virtio_blk_data_plane_start(s->dataplane); + if (!s->dataplane_disabled) { + return; + } + } + virtio_blk_handle_vq(s, vq); +} + static void virtio_blk_dma_restart_bh(void *opaque) { VirtIOBlock *s = opaque; diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 073c632..b5117a8 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -87,4 +87,6 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb); void virtio_blk_submit_multireq(BlockBackend *blk, MultiReqBuffer *mrb); +void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); + #endif