vhost: fix virtqueue not accessible
authorMarvin Liu <yong.liu@intel.com>
Mon, 4 Nov 2019 10:13:22 +0000 (18:13 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 8 Nov 2019 22:15:05 +0000 (23:15 +0100)
Log feature is disabled in vhost user, so that log address was invalid
when checking. Check whether log address is valid can work around it.
Log address should also be translated in packed ring virtqueue.

Fixes: fbda9f145927 ("vhost: translate incoming log address to GPA")
Cc: stable@dpdk.org
Signed-off-by: Marvin Liu <yong.liu@intel.com>
Reviewed-by: Adrian Moreno <amorenoz@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
lib/librte_vhost/vhost_user.c

index 3f649c8..cc660e0 100644 (file)
@@ -653,11 +653,21 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
        struct vhost_vring_addr *addr = &vq->ring_addrs;
        uint64_t len, expected_len;
 
+       if (addr->flags & (1 << VHOST_VRING_F_LOG)) {
+               vq->log_guest_addr =
+                       translate_log_addr(dev, vq, addr->log_guest_addr);
+               if (vq->log_guest_addr == 0) {
+                       RTE_LOG(DEBUG, VHOST_CONFIG,
+                               "(%d) failed to map log_guest_addr.\n",
+                               dev->vid);
+                       return dev;
+               }
+       }
+
        if (vq_is_packed(dev)) {
                len = sizeof(struct vring_packed_desc) * vq->size;
                vq->desc_packed = (struct vring_packed_desc *)(uintptr_t)
                        ring_addr_to_vva(dev, vq, addr->desc_user_addr, &len);
-               vq->log_guest_addr = 0;
                if (vq->desc_packed == NULL ||
                                len != sizeof(struct vring_packed_desc) *
                                vq->size) {
@@ -753,14 +763,6 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)
                vq->last_avail_idx = vq->used->idx;
        }
 
-       vq->log_guest_addr =
-               translate_log_addr(dev, vq, addr->log_guest_addr);
-       if (vq->log_guest_addr == 0) {
-               RTE_LOG(DEBUG, VHOST_CONFIG,
-                       "(%d) failed to map log_guest_addr .\n",
-                       dev->vid);
-               return dev;
-       }
        vq->access_ok = 1;
 
        VHOST_LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",