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 B0C49A0524; Mon, 7 Dec 2020 12:09:18 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0537AF12; Mon, 7 Dec 2020 12:09:17 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id 256A9CF3; Mon, 7 Dec 2020 12:09:15 +0100 (CET) Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CqLCL72sDzM1dJ; Mon, 7 Dec 2020 19:08:30 +0800 (CST) Received: from localhost (10.174.243.127) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Mon, 7 Dec 2020 19:09:01 +0800 From: wangyunjian To: CC: , , , , , Yunjian Wang , Date: Mon, 7 Dec 2020 19:08:49 +0800 Message-ID: <1607339329-624-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1602840525-8848-1-git-send-email-wangyunjian@huawei.com> References: <1602840525-8848-1-git-send-email-wangyunjian@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.243.127] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v4] eal: fix 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, user mem maps will check if the newly mapped area is adjacent to any existing mapping, but will not check if the mapping is identical because it assumes that the API will never get called with the same mapping twice. This will result in duplicate entries in the user mem maps list. Fix it by also checking for duplicate mappings, and skipping them if they are found. Fixes: 0cbce3a167f1 ("vfio: skip DMA map failure if already mapped") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang Acked-by: Anatoly Burakov --- v4: Update commit log suggested by Anatoly Burakov --- 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 050082444e..0967215783 100644 --- a/lib/librte_eal/linux/eal_vfio.c +++ b/lib/librte_eal/linux/eal_vfio.c @@ -168,6 +168,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) @@ -175,6 +179,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