Skip to content

Commit 3e11c6e

Browse files
mikechristiemstsirkin
authored andcommitted
vhost: create worker at end of vhost_dev_set_owner
vsock can start queueing work after VHOST_VSOCK_SET_GUEST_CID, so after we have called vhost_worker_create it can be calling vhost_work_queue and trying to access the vhost worker/task. If vhost_dev_alloc_iovecs fails, then vhost_worker_free could free the worker/task from under vsock. This moves vhost_worker_create to the end of vhost_dev_set_owner where we know we can no longer fail in that path. If it fails after the VHOST_SET_OWNER and userspace closes the device, then the normal vsock release handling will do the right thing. Signed-off-by: Mike Christie <michael.christie@oracle.com> Message-Id: <20230626232307.97930-2-michael.christie@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 3845308 commit 3e11c6e

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

drivers/vhost/vhost.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,20 +572,27 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
572572

573573
vhost_attach_mm(dev);
574574

575+
err = vhost_dev_alloc_iovecs(dev);
576+
if (err)
577+
goto err_iovecs;
578+
575579
if (dev->use_worker) {
580+
/*
581+
* This should be done last, because vsock can queue work
582+
* before VHOST_SET_OWNER so it simplifies the failure path
583+
* below since we don't have to worry about vsock queueing
584+
* while we free the worker.
585+
*/
576586
err = vhost_worker_create(dev);
577587
if (err)
578588
goto err_worker;
579589
}
580590

581-
err = vhost_dev_alloc_iovecs(dev);
582-
if (err)
583-
goto err_iovecs;
584-
585591
return 0;
586-
err_iovecs:
587-
vhost_worker_free(dev);
592+
588593
err_worker:
594+
vhost_dev_free_iovecs(dev);
595+
err_iovecs:
589596
vhost_detach_mm(dev);
590597
err_mm:
591598
return err;

0 commit comments

Comments
 (0)