From: Maxime Coquelin Date: Thu, 5 Oct 2017 08:36:18 +0000 (+0200) Subject: vhost: handle IOTLB update and invalidate requests X-Git-Tag: spdx-start~1647 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e95f34d3808e620c4e5648e75f415b3d7c2feaf0;p=dpdk.git vhost: handle IOTLB update and invalidate requests Vhost-user device IOTLB protocol extension introduces VHOST_USER_IOTLB message type. The associated payload is the vhost_iotlb_msg struct defined in Kernel, which in this was can be either an IOTLB update or invalidate message. On IOTLB update, the virtqueues get notified of a new entry. Signed-off-by: Maxime Coquelin Acked-by: Yuanhan Liu --- diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 628da2d558..bcfd28f5e3 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -48,6 +48,7 @@ #include #include +#include "iotlb.h" #include "vhost.h" #include "vhost_user.h" @@ -77,6 +78,7 @@ static const char *vhost_message_str[VHOST_USER_MAX] = { [VHOST_USER_SEND_RARP] = "VHOST_USER_SEND_RARP", [VHOST_USER_NET_SET_MTU] = "VHOST_USER_NET_SET_MTU", [VHOST_USER_SET_SLAVE_REQ_FD] = "VHOST_USER_SET_SLAVE_REQ_FD", + [VHOST_USER_IOTLB_MSG] = "VHOST_USER_IOTLB_MSG", }; static uint64_t @@ -909,6 +911,43 @@ vhost_user_set_req_fd(struct virtio_net *dev, struct VhostUserMsg *msg) return 0; } +static int +vhost_user_iotlb_msg(struct virtio_net *dev, struct VhostUserMsg *msg) +{ + struct vhost_iotlb_msg *imsg = &msg->payload.iotlb; + uint16_t i; + uint64_t vva; + + switch (imsg->type) { + case VHOST_IOTLB_UPDATE: + vva = qva_to_vva(dev, imsg->uaddr); + if (!vva) + return -1; + + for (i = 0; i < dev->nr_vring; i++) { + struct vhost_virtqueue *vq = dev->virtqueue[i]; + + vhost_user_iotlb_cache_insert(vq, imsg->iova, vva, + imsg->size, imsg->perm); + } + break; + case VHOST_IOTLB_INVALIDATE: + for (i = 0; i < dev->nr_vring; i++) { + struct vhost_virtqueue *vq = dev->virtqueue[i]; + + vhost_user_iotlb_cache_remove(vq, imsg->iova, + imsg->size); + } + break; + default: + RTE_LOG(ERR, VHOST_CONFIG, "Invalid IOTLB message type (%d)\n", + imsg->type); + return -1; + } + + return 0; +} + /* return bytes# of read on success or negative val on failure. */ static int read_vhost_message(int sockfd, struct VhostUserMsg *msg) @@ -1140,6 +1179,10 @@ vhost_user_msg_handler(int vid, int fd) ret = vhost_user_set_req_fd(dev, &msg); break; + case VHOST_USER_IOTLB_MSG: + ret = vhost_user_iotlb_msg(dev, &msg); + break; + default: ret = -1; break; diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h index 0b2aff14e8..46c6ff9567 100644 --- a/lib/librte_vhost/vhost_user.h +++ b/lib/librte_vhost/vhost_user.h @@ -80,6 +80,7 @@ typedef enum VhostUserRequest { VHOST_USER_SEND_RARP = 19, VHOST_USER_NET_SET_MTU = 20, VHOST_USER_SET_SLAVE_REQ_FD = 21, + VHOST_USER_IOTLB_MSG = 22, VHOST_USER_MAX } VhostUserRequest;