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 09D73A0532; Wed, 22 Jan 2020 18:06:24 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6F18F2BF9; Wed, 22 Jan 2020 18:06:22 +0100 (CET) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 34B8D2BBE for ; Wed, 22 Jan 2020 18:06:21 +0100 (CET) Received: by mail-pf1-f196.google.com with SMTP id 4so126748pfz.9 for ; Wed, 22 Jan 2020 09:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QSKf8tFkrVlr1YpfLvlgAJQDve9stc3HQrw3osIHZ4g=; b=iBvkFQdMdz86OzK4vH4dJcbfcgPSsP8rEcp3MUK3bH4cQsKGmECoL34W6cgrMNQ0WM 05f4hrJ5bCKdEbYp8NsX1sLhdkV45eeGww5WHJ1vuSEFmoz99uP24u3jkedD3KT4mlNZ aRcHDrD37Kf2wtIcBDQ+ts+lJJzxKlFGPDs4dmrLVa5PgKpqmhK7DvH1qmGhd0APzU4a Drv9xzKl4XkBHbzQFW2EY9kupnDq/eqI80r25zph8eJpb7AzojO1VdMS18OfErUhxxXP iGPTp4Ta4eTL6qxid+hAxq9evGLjUtg8062nf8XuUUCh17CVC0fuu3yiguTqZaMyT00d kRIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QSKf8tFkrVlr1YpfLvlgAJQDve9stc3HQrw3osIHZ4g=; b=nDKQaxUVm9QiT40PKnrWuEixX8keWQS9jTIOQPj+CPExKeBNOzRlLJ7cZw12RQgMUA y2Cnzm+xRPH46nf1vfWHZlyCHg5spXBU361GomFGxO2JKAqNiha9hWb3IS++EM4mUs+L CVDq3lpRVdxgpNjF9zL9WENZ/aWp4OaVInhdae2QHjWblsCME++buPRqMX+ZXGxCyOJQ 8FTe3dQcO9g2XunPwlPyXI5jpyWXB0l6nVEnI8ZmbaQSUdBmVIZqw9X8uxWNvar6x+h1 OZRcXca5GXZX6vvllH5+LY52LbMTGNIagtTFKA/M9BgFJ3EPihWfDidSbLsbqth2ddDl eNLw== X-Gm-Message-State: APjAAAUVfbk4hHlmtGDzHk8YtpMIY/IloO0fwgxdAHM/IQaqM4tmOkY6 sfa00U7B7eEmhKRNGKpBX5a2sYf4OVM= X-Google-Smtp-Source: APXvYqwmNCNwPrnU//EWIqGew1TijYVSH5ZJBuZC41sKPbdUe+JpHeocE+uJ8xX/KDQp4qoIyd4wlQ== X-Received: by 2002:a63:1945:: with SMTP id 5mr12453034pgz.310.1579712779801; Wed, 22 Jan 2020 09:06:19 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c188sm21345813pga.83.2020.01.22.09.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 09:06:18 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , anatoly.burakov@intel.com, stable@dpdk.org Date: Wed, 22 Jan 2020 09:06:11 -0800 Message-Id: <20200122170611.23121-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200106205553.3696-1-stephen@networkplumber.org> References: <20200106205553.3696-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] mem: fix incorrect munmap in error unwind 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" The loop to unwind existing mmaps was only unmapping the first segment and the error paths after mmap() were not doing munmap of the current segment. Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists") Cc: anatoly.burakov@intel.com Cc: stable@dpdk.org Signed-off-by: Stephen Hemminger Acked-by: Anatoly Burakov --- v2 - incorporate feedback from David Marchand fix missing munmap of current segment lib/librte_eal/linux/eal/eal_memory.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_memory.c b/lib/librte_eal/linux/eal/eal_memory.c index 43e4ffc757bd..5604c2a7c04d 100644 --- a/lib/librte_eal/linux/eal/eal_memory.c +++ b/lib/librte_eal/linux/eal/eal_memory.c @@ -1928,7 +1928,7 @@ eal_legacy_hugepage_attach(void) if (flock(fd, LOCK_SH) < 0) { RTE_LOG(DEBUG, EAL, "%s(): Locking file failed: %s\n", __func__, strerror(errno)); - goto fd_error; + goto mmap_error; } /* find segment data */ @@ -1936,13 +1936,13 @@ eal_legacy_hugepage_attach(void) if (msl == NULL) { RTE_LOG(DEBUG, EAL, "%s(): Cannot find memseg list\n", __func__); - goto fd_error; + goto mmap_error; } ms = rte_mem_virt2memseg(map_addr, msl); if (ms == NULL) { RTE_LOG(DEBUG, EAL, "%s(): Cannot find memseg\n", __func__); - goto fd_error; + goto mmap_error; } msl_idx = msl - mcfg->memsegs; @@ -1950,7 +1950,7 @@ eal_legacy_hugepage_attach(void) if (ms_idx < 0) { RTE_LOG(DEBUG, EAL, "%s(): Cannot find memseg idx\n", __func__); - goto fd_error; + goto mmap_error; } /* store segment fd internally */ @@ -1963,18 +1963,15 @@ eal_legacy_hugepage_attach(void) close(fd_hugepage); return 0; +mmap_error: + munmap(hp[i].final_va, hp[i].size); fd_error: close(fd); error: - /* map all segments into memory to make sure we get the addrs */ - cur_seg = 0; - for (cur_seg = 0; cur_seg < i; cur_seg++) { - struct hugepage_file *hf = &hp[i]; - size_t map_sz = hf->size; - void *map_addr = hf->final_va; + /* unwind mmap's done so far */ + for (cur_seg = 0; cur_seg < i; cur_seg++) + munmap(hp[cur_seg].final_va, hp[cur_seg].size); - munmap(map_addr, map_sz); - } if (hp != NULL && hp != MAP_FAILED) munmap(hp, size); if (fd_hugepage >= 0) -- 2.20.1