Skip to content

Commit 36e493d

Browse files
mikechristiegregkh
authored andcommitted
vhost-scsi: Handle vhost_vq_work_queue failures for events
[ Upstream commit b1b2ce5 ] Currently, we can try to queue an event's work before the vhost_task is created. When this happens we just drop it in vhost_scsi_do_plug before even calling vhost_vq_work_queue. During a device shutdown we do the same thing after vhost_scsi_clear_endpoint has cleared the backends. In the next patches we will be able to kill the vhost_task before we have cleared the endpoint. In that case, vhost_vq_work_queue can fail and we will leak the event's memory. This has handle the failure by just freeing the event. This is safe to do, because vhost_vq_work_queue will only return failure for us when the vhost_task is killed and so userspace will not be able to handle events if we sent them. Signed-off-by: Mike Christie <michael.christie@oracle.com> Message-Id: <20240316004707.45557-2-michael.christie@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 53d5ac2 commit 36e493d

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

drivers/vhost/scsi.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,23 +497,29 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt)
497497
vq_err(vq, "Faulted on vhost_scsi_send_event\n");
498498
}
499499

500-
static void vhost_scsi_evt_work(struct vhost_work *work)
500+
static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop)
501501
{
502-
struct vhost_scsi *vs = container_of(work, struct vhost_scsi,
503-
vs_event_work);
504502
struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
505503
struct vhost_scsi_evt *evt, *t;
506504
struct llist_node *llnode;
507505

508506
mutex_lock(&vq->mutex);
509507
llnode = llist_del_all(&vs->vs_event_list);
510508
llist_for_each_entry_safe(evt, t, llnode, list) {
511-
vhost_scsi_do_evt_work(vs, evt);
509+
if (!drop)
510+
vhost_scsi_do_evt_work(vs, evt);
512511
vhost_scsi_free_evt(vs, evt);
513512
}
514513
mutex_unlock(&vq->mutex);
515514
}
516515

516+
static void vhost_scsi_evt_work(struct vhost_work *work)
517+
{
518+
struct vhost_scsi *vs = container_of(work, struct vhost_scsi,
519+
vs_event_work);
520+
vhost_scsi_complete_events(vs, false);
521+
}
522+
517523
static int vhost_scsi_copy_sgl_to_iov(struct vhost_scsi_cmd *cmd)
518524
{
519525
struct iov_iter *iter = &cmd->saved_iter;
@@ -1509,7 +1515,8 @@ vhost_scsi_send_evt(struct vhost_scsi *vs, struct vhost_virtqueue *vq,
15091515
}
15101516

15111517
llist_add(&evt->list, &vs->vs_event_list);
1512-
vhost_vq_work_queue(vq, &vs->vs_event_work);
1518+
if (!vhost_vq_work_queue(vq, &vs->vs_event_work))
1519+
vhost_scsi_complete_events(vs, true);
15131520
}
15141521

15151522
static void vhost_scsi_evt_handle_kick(struct vhost_work *work)

0 commit comments

Comments
 (0)