Skip to content

Commit

Permalink
vhost: fix deadlock when message handling failed
Browse files Browse the repository at this point in the history
[ upstream commit 9e89b06 ]

In vhost_user_msg_handler(), if vhost message handling
failed, we should check whether the queue is locked and
release the lock before returning. Or, it will cause a
deadlock later.

Fixes: 7f31d4e ("vhost: fix lock on device readiness notification")

Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
Tested-by: Wei Ling <weix.ling@intel.com>
Acked-by: David Marchand <david.marchand@redhat.com>
  • Loading branch information
wenwumax authored and steevenlee committed Jun 20, 2022
1 parent 4daae0c commit 63005df
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/librte_vhost/vhost_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,6 @@ vhost_user_msg_handler(int vid, int fd)
return -1;
}

ret = 0;
request = msg.request.master;
if (request > VHOST_USER_NONE && request < VHOST_USER_MAX &&
vhost_message_str[request]) {
Expand Down Expand Up @@ -2931,9 +2930,11 @@ vhost_user_msg_handler(int vid, int fd)
} else if (ret == RTE_VHOST_MSG_RESULT_ERR) {
VHOST_LOG_CONFIG(ERR,
"vhost message handling failed.\n");
return -1;
ret = -1;
goto unlock;
}

ret = 0;
for (i = 0; i < dev->nr_vring; i++) {
struct vhost_virtqueue *vq = dev->virtqueue[i];
bool cur_ready = vq_is_ready(dev, vq);
Expand All @@ -2944,10 +2945,11 @@ vhost_user_msg_handler(int vid, int fd)
}
}

unlock:
if (unlock_required)
vhost_user_unlock_all_queue_pairs(dev);

if (!virtio_is_ready(dev))
if (ret != 0 || !virtio_is_ready(dev))
goto out;

/*
Expand All @@ -2974,7 +2976,7 @@ vhost_user_msg_handler(int vid, int fd)
}

out:
return 0;
return ret;
}

static int process_slave_message_reply(struct virtio_net *dev,
Expand Down

0 comments on commit 63005df

Please sign in to comment.