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 85D4CA0532 for ; Wed, 22 Jan 2020 18:06:22 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 432E42BB9; Wed, 22 Jan 2020 18:06:22 +0100 (CET) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id E53962BB9 for ; Wed, 22 Jan 2020 18:06:20 +0100 (CET) Received: by mail-pf1-f195.google.com with SMTP id 2so119135pfg.12 for ; Wed, 22 Jan 2020 09:06:20 -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=gSDK4BrjNrfBfrdRNvvhVN5pf1/uo2Xq2ZizOvhLhFDMaRgLWQIQC+cus/YO290SBI y93GCbY7rCZLy8SkEfzM7Qy/HfdtnleMqVOxiVzpZLIyG4snH36FshQ9a0Cd6nIqgAz6 HPq854aFu6ql7XbXr+GTh9V27n7CC7YmNI4beIGp27wdt651fp7AL4/2Go10tCVirW7j KBWb8+LxyNlGVESoD1dkmNTAphpAlYN81AMOXrfAlAJ3O0l3+Yl6KJIlRWAkQIwoB8F6 ky6qOp3G/mwuw+2l7Wi+xF3PLbK72DuTZpKVseOBAok1pWMKO4yT82pCSh0xVLyCgpT1 hkrA== X-Gm-Message-State: APjAAAUabXjoE4vSivyIdcILhHMY7FeC0X+YjKV80Wy6b7LvCu63l1zJ owfWHATco/yguBhgJBLMch10Jg== 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-stable] [PATCH v2] mem: fix incorrect munmap in error unwind X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" 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