From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C3440A0521; Thu, 23 Jul 2020 16:48:51 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1C0051BF7B; Thu, 23 Jul 2020 16:48:51 +0200 (CEST) Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) by dpdk.org (Postfix) with ESMTP id 2C268E07; Thu, 23 Jul 2020 16:48:48 +0200 (CEST) Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8BC26A299DF5D2E1A726; Thu, 23 Jul 2020 22:48:46 +0800 (CST) Received: from localhost (10.174.185.168) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 23 Jul 2020 22:48:39 +0800 From: wangyunjian To: , , CC: , , Yunjian Wang , Date: Thu, 23 Jul 2020 22:48:33 +0800 Message-ID: <1595515713-24640-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.185.168] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2] eal/linux: do not create user mem map repeatedly when it exists X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Yunjian Wang Currently, we will create new user mem map entry for the same memory segment, but in fact it has already been added to the user mem maps. It's not necessary to create it twice. To resolve the issue, add support to remove the same entry in the function compact_user_maps(). Fixes: 0cbce3a167f1 ("vfio: skip DMA map failure if already mapped") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang --- v2: * Remove the same entry in the function compact_user_maps() --- lib/librte_eal/linux/eal_vfio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c index abb12a354..df99307b7 100644 --- a/lib/librte_eal/linux/eal_vfio.c +++ b/lib/librte_eal/linux/eal_vfio.c @@ -167,6 +167,10 @@ adjust_map(struct user_mem_map *src, struct user_mem_map *end, static int merge_map(struct user_mem_map *left, struct user_mem_map *right) { + /* merge the same maps into one */ + if (memcmp(left, right, sizeof(struct user_mem_map)) == 0) + goto out; + if (left->addr + left->len != right->addr) return 0; if (left->iova + left->len != right->iova) @@ -174,6 +178,7 @@ merge_map(struct user_mem_map *left, struct user_mem_map *right) left->len += right->len; +out: memset(right, 0, sizeof(*right)); return 1; -- 2.23.0