From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [119.145.14.65]) by dpdk.org (Postfix) with ESMTP id 02EA0106A; Tue, 6 Dec 2016 06:41:14 +0100 (CET) Received: from 172.24.1.36 (EHLO SZXEML424-HUB.china.huawei.com) ([172.24.1.36]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DRT14319; Tue, 06 Dec 2016 13:41:05 +0800 (CST) Received: from [127.0.0.1] (10.177.20.223) by SZXEML424-HUB.china.huawei.com (10.82.67.153) with Microsoft SMTP Server id 14.3.235.1; Tue, 6 Dec 2016 13:40:55 +0800 To: Yuanhan Liu References: <1480592522-26096-1-git-send-email-haifeng.lin@huawei.com> <20161206022829.GO24403@yliu-dev.sh.intel.com> CC: , , , From: linhaifeng Message-ID: <58464F64.6040909@huawei.com> Date: Tue, 6 Dec 2016 13:40:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <20161206022829.GO24403@yliu-dev.sh.intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.20.223] X-CFilter-Loop: Reflected Subject: Re: [dpdk-stable] [PATCH v2] vhost: fix add_guest_pages bug X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2016 05:41:16 -0000 在 2016/12/6 10:28, Yuanhan Liu 写道: > On Thu, Dec 01, 2016 at 07:42:02PM +0800, Haifeng Lin wrote: >> 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; > > I'd use RTE_MIN(reg_size, page_size) here. Also, this patch miss a > fixline (http://dpdk.org/dev): > > Fixes: e246896178e6 ("vhost: get guest/host physical address mappings") > > Applied to dpdk-next-virtio, with above fixed. > > Thanks for the fix! > > --yliu > >> 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 >> > > . > Hi,yliu The bug would happen like this: ----------------------------- | region | ----------------------------- : : remain : -------------- --------------- | hugepage | ... | hugepage | -------------- --------------- so the remain reg_size maybe smaller than a hugepage size, and "reg_size -= page_size" is not correct. apply all the patch?