From patchwork Fri Oct 16 09:28:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 81069 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id BA675A04DB; Fri, 16 Oct 2020 11:29:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9D2281EB36; Fri, 16 Oct 2020 11:29:00 +0200 (CEST) Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id 8ECE71D5CA; Fri, 16 Oct 2020 11:28:58 +0200 (CEST) Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 8D3B13AC377A173C5D4C; Fri, 16 Oct 2020 17:28:56 +0800 (CST) Received: from localhost (10.174.187.156) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Fri, 16 Oct 2020 17:28:47 +0800 From: wangyunjian To: CC: , , , , Yunjian Wang , Date: Fri, 16 Oct 2020 17:28:45 +0800 Message-ID: <1602840525-8848-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1595515713-24640-1-git-send-email-wangyunjian@huawei.com> References: <1595515713-24640-1-git-send-email-wangyunjian@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.156] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v3] 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, a issue that a container has many devices and the application will map the same memory many times. The kernel driver returns EEXIST as long as there are overlapping memory areas. As a result, we repeatedly create new user mem map entry for the same memory segment and this will lead to no more space for other user mem maps. 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 Acked-by: Anatoly Burakov --- v3: Only update commit log and title --- 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 380f2f44a..7cff51e16 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;