From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [119.145.14.66]) by dpdk.org (Postfix) with ESMTP id 3FEE858C5 for ; Thu, 1 Dec 2016 12:42:25 +0100 (CET) Received: from 172.24.1.60 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.60]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CME13684; Thu, 01 Dec 2016 19:42:10 +0800 (CST) Received: from localhost (10.177.20.223) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Thu, 1 Dec 2016 19:42:03 +0800 From: Haifeng Lin To: , , CC: Date: Thu, 1 Dec 2016 19:42:02 +0800 Message-ID: <1480592522-26096-1-git-send-email-haifeng.lin@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.20.223] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2] vhost: fix add_guest_pages bug X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Dec 2016 11:42:27 -0000 When reg_size < page_size the function read in rte_mem_virt2phy would not return, becausue host_user_addr is invalid. Signed-off-by: Haifeng Lin --- v2: fix TYPO_SPELLING warning --- lib/librte_vhost/vhost_user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 6b83c15..ce55e85 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -447,14 +447,14 @@ add_guest_pages(struct virtio_net *dev, struct virtio_memory_region *reg, reg_size -= size; while (reg_size > 0) { + size = reg_size >= page_size ? page_size : reg_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; } } -- 1.8.3.1