vhost: fix guest/host physical address mapping
authorHaifeng Lin <haifeng.lin@huawei.com>
Thu, 1 Dec 2016 11:42:02 +0000 (19:42 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Tue, 17 Jan 2017 08:20:17 +0000 (09:20 +0100)
When reg_size < page_size the function read in
rte_mem_virt2phy would not return, because
host_user_addr is invalid.

Fixes: e246896178e6 ("vhost: get guest/host physical address mappings")
Cc: stable@dpdk.org
Signed-off-by: Haifeng Lin <haifeng.lin@huawei.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
lib/librte_vhost/vhost_user.c

index 6b83c15..50cb6d1 100644 (file)
@@ -447,14 +447,14 @@ add_guest_pages(struct virtio_net *dev, struct virtio_memory_region *reg,
        reg_size -= size;
 
        while (reg_size > 0) {
+               size = RTE_MIN(reg_size, page_size);
                host_phys_addr = rte_mem_virt2phy((void *)(uintptr_t)
                                                  host_user_addr);
-               add_one_guest_page(dev, guest_phys_addr, host_phys_addr,
-                                  page_size);
+               add_one_guest_page(dev, guest_phys_addr, host_phys_addr, size);
 
-               host_user_addr  += page_size;
-               guest_phys_addr += page_size;
-               reg_size -= page_size;
+               host_user_addr  += size;
+               guest_phys_addr += size;
+               reg_size -= size;
        }
 }