From patchwork Mon Feb 6 10:53:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 123134 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AC8D941BE9; Mon, 6 Feb 2023 11:59:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 790A642D1A; Mon, 6 Feb 2023 11:59:15 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id DA0F540FAE for ; Mon, 6 Feb 2023 11:59:12 +0100 (CET) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4P9NSD0ftczkXrx; Mon, 6 Feb 2023 18:54:36 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 6 Feb 2023 18:59:10 +0800 From: Chengwen Feng To: , , Bruce Richardson , Anatoly Burakov CC: Subject: [PATCH 1/2] eal: fix mmap fail regarded as success Date: Mon, 6 Feb 2023 10:53:10 +0000 Message-ID: <20230206105311.9577-2-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230206105311.9577-1-fengchengwen@huawei.com> References: <20230206105311.9577-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The map_shared_memory() function should treat mmap MAP_FAILED as NULL because callers compare it with NULL to determine whether the map is failed. Fixes: 764bf26873b9 ("add FreeBSD support") Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Reviewed-by: David Marchand --- lib/eal/freebsd/eal_hugepage_info.c | 2 +- lib/eal/linux/eal_hugepage_info.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/eal/freebsd/eal_hugepage_info.c b/lib/eal/freebsd/eal_hugepage_info.c index 9dbe375bd3..e58e618469 100644 --- a/lib/eal/freebsd/eal_hugepage_info.c +++ b/lib/eal/freebsd/eal_hugepage_info.c @@ -33,7 +33,7 @@ map_shared_memory(const char *filename, const size_t mem_size, int flags) } retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); - return retval; + return retval == MAP_FAILED ? NULL : retval; } static void * diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c index a1b6cb31ff..24411d9c5b 100644 --- a/lib/eal/linux/eal_hugepage_info.c +++ b/lib/eal/linux/eal_hugepage_info.c @@ -50,7 +50,7 @@ map_shared_memory(const char *filename, const size_t mem_size, int flags) retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); - return retval; + return retval == MAP_FAILED ? NULL : retval; } static void * From patchwork Mon Feb 6 10:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 123135 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E4FD941BE9; Mon, 6 Feb 2023 11:59:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B12A342D38; Mon, 6 Feb 2023 11:59:16 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id DBABD427E9 for ; Mon, 6 Feb 2023 11:59:12 +0100 (CET) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4P9NWb0wyYzJsFB; Mon, 6 Feb 2023 18:57:31 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 6 Feb 2023 18:59:10 +0800 From: Chengwen Feng To: , , Rosen Xu , Tianfei Zhang , Wei Huang CC: Subject: [PATCH 2/2] raw/ifpga/base: fix mmap retcode check fail Date: Mon, 6 Feb 2023 10:53:11 +0000 Message-ID: <20230206105311.9577-3-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230206105311.9577-1-fengchengwen@huawei.com> References: <20230206105311.9577-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The MAP_FAILED should be used to determine whether the mapping is successful. Fixes: e41856b515ce ("raw/ifpga/base: enhance driver reliability in multi-process") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Reviewed-by: Rosen Xu --- drivers/raw/ifpga/base/opae_hw_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/raw/ifpga/base/opae_hw_api.c b/drivers/raw/ifpga/base/opae_hw_api.c index 1117c3e160..6d48d227d6 100644 --- a/drivers/raw/ifpga/base/opae_hw_api.c +++ b/drivers/raw/ifpga/base/opae_hw_api.c @@ -380,7 +380,7 @@ static pthread_mutex_t *opae_adapter_mutex_open(struct opae_adapter *adapter) PROT_READ | PROT_WRITE, MAP_SHARED, shm_id, 0); adapter->lock = (pthread_mutex_t *)ptr; - if (ptr) { + if (ptr != MAP_FAILED) { dev_info(NULL, "shared memory %s address is %p\n", shm_name, ptr); @@ -499,7 +499,7 @@ static void *opae_adapter_shm_alloc(struct opae_adapter *adapter) adapter->shm.size = size; adapter->shm.ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_id, 0); - if (adapter->shm.ptr) { + if (adapter->shm.ptr != MAP_FAILED) { dev_info(NULL, "shared memory %s address is %p\n", shm_name, adapter->shm.ptr);