aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librte_vhost
diff options
context:
space:
mode:
Diffstat (limited to 'lib/librte_vhost')
-rw-r--r--lib/librte_vhost/vhost_user.c58
-rw-r--r--lib/librte_vhost/virtio_net.c6
2 files changed, 42 insertions, 22 deletions
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 04c92ceb..618d413f 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -741,7 +741,7 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg)
* In vhost-user, when we receive kick message, will test whether virtio
* device is ready for packet processing.
*/
-static void
+static int
vhost_user_set_vring_kick(struct virtio_net *dev, struct VhostUserMsg *pmsg)
{
struct vhost_vring_file file;
@@ -769,6 +769,8 @@ vhost_user_set_vring_kick(struct virtio_net *dev, struct VhostUserMsg *pmsg)
if (notify_ops->new_device(dev->vid) == 0)
dev->flags |= VIRTIO_DEV_RUNNING;
}
+
+ return 0;
}
static void
@@ -847,14 +849,19 @@ vhost_user_set_vring_enable(struct virtio_net *dev,
return 0;
}
-static void
+static int
vhost_user_set_protocol_features(struct virtio_net *dev,
uint64_t protocol_features)
{
- if (protocol_features & ~VHOST_USER_PROTOCOL_FEATURES)
- return;
+ if (protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) {
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "(%d) received invalid protocol features.\n",
+ dev->vid);
+ return -1;
+ }
dev->protocol_features = protocol_features;
+ return 0;
}
static int
@@ -949,7 +956,7 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg)
if (ret <= 0)
return ret;
- if (msg && msg->size) {
+ if (msg->size) {
if (msg->size > sizeof(msg->payload)) {
RTE_LOG(ERR, VHOST_CONFIG,
"invalid msg size: %d\n", msg->size);
@@ -1080,6 +1087,7 @@ vhost_user_msg_handler(int vid, int fd)
}
+ ret = 0;
switch (msg.request) {
case VHOST_USER_GET_FEATURES:
msg.payload.u64 = vhost_user_get_features();
@@ -1087,7 +1095,7 @@ vhost_user_msg_handler(int vid, int fd)
send_vhost_message(fd, &msg);
break;
case VHOST_USER_SET_FEATURES:
- vhost_user_set_features(dev, msg.payload.u64);
+ ret = vhost_user_set_features(dev, msg.payload.u64);
break;
case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -1096,14 +1104,14 @@ vhost_user_msg_handler(int vid, int fd)
send_vhost_message(fd, &msg);
break;
case VHOST_USER_SET_PROTOCOL_FEATURES:
- vhost_user_set_protocol_features(dev, msg.payload.u64);
+ ret = vhost_user_set_protocol_features(dev, msg.payload.u64);
break;
case VHOST_USER_SET_OWNER:
- vhost_user_set_owner();
+ ret = vhost_user_set_owner();
break;
case VHOST_USER_RESET_OWNER:
- vhost_user_reset_owner(dev);
+ ret = vhost_user_reset_owner(dev);
break;
case VHOST_USER_SET_MEM_TABLE:
@@ -1111,10 +1119,14 @@ vhost_user_msg_handler(int vid, int fd)
break;
case VHOST_USER_SET_LOG_BASE:
- vhost_user_set_log_base(dev, &msg);
-
- /* it needs a reply */
- msg.size = sizeof(msg.payload.u64);
+ ret = vhost_user_set_log_base(dev, &msg);
+ if (ret)
+ break;
+ /*
+ * The spec is not clear about it (yet), but QEMU doesn't expect
+ * any payload in the reply. But a reply is required.
+ */
+ msg.size = 0;
send_vhost_message(fd, &msg);
break;
case VHOST_USER_SET_LOG_FD:
@@ -1123,23 +1135,25 @@ vhost_user_msg_handler(int vid, int fd)
break;
case VHOST_USER_SET_VRING_NUM:
- vhost_user_set_vring_num(dev, &msg.payload.state);
+ ret = vhost_user_set_vring_num(dev, &msg.payload.state);
break;
case VHOST_USER_SET_VRING_ADDR:
- vhost_user_set_vring_addr(&dev, &msg.payload.addr);
+ ret = vhost_user_set_vring_addr(&dev, &msg.payload.addr);
break;
case VHOST_USER_SET_VRING_BASE:
- vhost_user_set_vring_base(dev, &msg.payload.state);
+ ret = vhost_user_set_vring_base(dev, &msg.payload.state);
break;
case VHOST_USER_GET_VRING_BASE:
ret = vhost_user_get_vring_base(dev, &msg.payload.state);
+ if (ret)
+ break;
msg.size = sizeof(msg.payload.state);
send_vhost_message(fd, &msg);
break;
case VHOST_USER_SET_VRING_KICK:
- vhost_user_set_vring_kick(dev, &msg);
+ ret = vhost_user_set_vring_kick(dev, &msg);
break;
case VHOST_USER_SET_VRING_CALL:
vhost_user_set_vring_call(dev, &msg);
@@ -1158,10 +1172,10 @@ vhost_user_msg_handler(int vid, int fd)
break;
case VHOST_USER_SET_VRING_ENABLE:
- vhost_user_set_vring_enable(dev, &msg.payload.state);
+ ret = vhost_user_set_vring_enable(dev, &msg.payload.state);
break;
case VHOST_USER_SEND_RARP:
- vhost_user_send_rarp(dev, &msg);
+ ret = vhost_user_send_rarp(dev, &msg);
break;
default:
@@ -1172,5 +1186,11 @@ vhost_user_msg_handler(int vid, int fd)
if (unlock_required)
vhost_user_unlock_all_queue_pairs(dev);
+ if (ret) {
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "vhost message handling failed.\n");
+ return -1;
+ }
+
return 0;
}
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index cfd69cea..eaee1c78 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -272,7 +272,7 @@ flush_shadow_used_ring(struct virtio_net *dev, struct vhost_virtqueue *vq)
static inline void __attribute__((always_inline))
update_shadow_used_ring(struct vhost_virtqueue *vq,
- uint16_t desc_idx, uint16_t len)
+ uint16_t desc_idx, uint32_t len)
{
uint16_t i = vq->shadow_used_idx++;
@@ -610,7 +610,7 @@ static inline int __attribute__((always_inline))
fill_vec_buf(struct virtio_net *dev, struct vhost_virtqueue *vq,
uint32_t avail_idx, uint32_t *vec_idx,
struct buf_vector *buf_vec, uint16_t *desc_chain_head,
- uint16_t *desc_chain_len)
+ uint32_t *desc_chain_len)
{
uint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];
uint32_t vec_id = *vec_idx;
@@ -684,7 +684,7 @@ reserve_avail_buf_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
uint16_t tries = 0;
uint16_t head_idx = 0;
- uint16_t len = 0;
+ uint32_t len = 0;
*num_buffers = 0;
cur_idx = vq->last_avail_idx;