Skip to content

Commit

Permalink
um: virtio_uml: Fix broken device handling in time-travel
Browse files Browse the repository at this point in the history
If a device implementation crashes, virtio_uml will mark it
as dead by calling virtio_break_device() and scheduling the
work that will remove it.

This still seems like the right thing to do, but it's done
directly while reading the message, and if time-travel is
used, this is in the time-travel handler, outside of the
normal Linux machinery. Therefore, we cannot acquire locks
or do normal "linux-y" things because e.g. lockdep will be
confused about the context.

Move handling this situation out of the read function and
into the actual IRQ handler and response handling instead,
so that in the case of time-travel we don't call it in the
wrong context.

Chances are the system will still crash immediately, since
the device implementation crashing may also cause the time-
travel controller to go down, but at least all of that now
happens without strange warnings from lockdep.

Fixes: c8177ab ("um: time-travel: rework interrupt handling in ext mode")
Cc: stable@vger.kernel.org
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
jmberg-intel authored and richardweinberger committed May 27, 2022
1 parent d5a9597 commit af9fb41
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions arch/um/drivers/virtio_uml.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct virtio_uml_device {

u8 config_changed_irq:1;
uint64_t vq_irq_vq_map;
int recv_rc;
};

struct virtio_uml_vq_info {
Expand Down Expand Up @@ -148,14 +149,6 @@ static int vhost_user_recv(struct virtio_uml_device *vu_dev,

rc = vhost_user_recv_header(fd, msg);

if (rc == -ECONNRESET && vu_dev->registered) {
struct virtio_uml_platform_data *pdata;

pdata = vu_dev->pdata;

virtio_break_device(&vu_dev->vdev);
schedule_work(&pdata->conn_broken_wk);
}
if (rc)
return rc;
size = msg->header.size;
Expand All @@ -164,15 +157,32 @@ static int vhost_user_recv(struct virtio_uml_device *vu_dev,
return full_read(fd, &msg->payload, size, false);
}

static void vhost_user_check_reset(struct virtio_uml_device *vu_dev,
int rc)
{
struct virtio_uml_platform_data *pdata = vu_dev->pdata;

if (rc != -ECONNRESET)
return;

if (!vu_dev->registered)
return;

virtio_break_device(&vu_dev->vdev);
schedule_work(&pdata->conn_broken_wk);
}

static int vhost_user_recv_resp(struct virtio_uml_device *vu_dev,
struct vhost_user_msg *msg,
size_t max_payload_size)
{
int rc = vhost_user_recv(vu_dev, vu_dev->sock, msg,
max_payload_size, true);

if (rc)
if (rc) {
vhost_user_check_reset(vu_dev, rc);
return rc;
}

if (msg->header.flags != (VHOST_USER_FLAG_REPLY | VHOST_USER_VERSION))
return -EPROTO;
Expand Down Expand Up @@ -369,6 +379,7 @@ static irqreturn_t vu_req_read_message(struct virtio_uml_device *vu_dev,
sizeof(msg.msg.payload) +
sizeof(msg.extra_payload));

vu_dev->recv_rc = rc;
if (rc)
return IRQ_NONE;

Expand Down Expand Up @@ -412,7 +423,9 @@ static irqreturn_t vu_req_interrupt(int irq, void *data)
if (!um_irq_timetravel_handler_used())
ret = vu_req_read_message(vu_dev, NULL);

if (vu_dev->vq_irq_vq_map) {
if (vu_dev->recv_rc) {
vhost_user_check_reset(vu_dev, vu_dev->recv_rc);
} else if (vu_dev->vq_irq_vq_map) {
struct virtqueue *vq;

virtio_device_for_each_vq((&vu_dev->vdev), vq) {
Expand Down

0 comments on commit af9fb41

Please sign in to comment.