From patchwork Thu Jun 16 02:33:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 13884 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 387E7C562; Thu, 16 Jun 2016 04:33:38 +0200 (CEST) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by dpdk.org (Postfix) with ESMTP id 263C4C544 for ; Thu, 16 Jun 2016 04:33:35 +0200 (CEST) Received: by mail-pa0-f51.google.com with SMTP id bz2so13154827pad.1 for ; Wed, 15 Jun 2016 19:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ib4pygXmNcVfDFjV0lIdPRHqYn/Xrv4/e0VFQyiSO00=; b=W3cVKpqngjqE9rM/3y1hudlTVJY3rnWalHlhmTcMFSKdPYdnHCMD/IJQIScRyDiqQz ipICiGTOdvAB3OdH1HKApzA4eb7d3FKSuzXX8NS8Hpr6GX0VOuXA/Tuin48QYaMn58Sn kr2hR6Y4S2NIyq2bEt2lnDC7GSeQFev5PlmERdqKjGaApQ3S8AONRL6lCOCRnPLpLns8 j0wtqbgI0HtA2/FH4ebChBUYKZ+j+U7u0dmkZ8n5deR8YohXLIJr8vmw9qz/8Vua5hLA DE/bB1BCLeUCZY0EQg/nW8NNAH5Y0klRY2Kak95gwR/bThD/MSGiBbGfUAmiJQYEjFRw rp1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ib4pygXmNcVfDFjV0lIdPRHqYn/Xrv4/e0VFQyiSO00=; b=mTMNvEWwevq1kOAgBhFb9q+/Ys4G2R9L9Yw7KedIwsM7LtJBotfPxR7olTYZvmSqDX 0JWyvRKzZZ3WTzLCCd2y8YwIAqPsgDaAWbMmyQV7GaLzM/PxyiD9Oqo1TAr2/Pq3I8Pu WqCzX53CitLDCtB/jBlqXPD1rc62ZY/6MstpNgoTmzXszVBtcuESnng/dS/6i5nEsq+r xYcppvYnKM5kOC9i3nZVWyccCKHw2yHH4MZ06R3yLTWLhACB0FJXnvuIiUTn3d4iUASM L9heE1RWCWiv3YN5lDF4vP6YvCFHANdk4O70Apt6B7ejGopmk2JPwG4CnSTJLv9xAeWV Ibtw== X-Gm-Message-State: ALyK8tLfjGSi28SPTiBCBKRZHmsbMjZWNVOizcs32xn8dRNha2/S4H5/2KNf61nRLjKAcQ== X-Received: by 10.66.167.168 with SMTP id zp8mr2287291pab.20.1466044414401; Wed, 15 Jun 2016 19:33:34 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id x10sm47039895pfd.8.2016.06.15.19.33.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Jun 2016 19:33:33 -0700 (PDT) From: Tetsuya Mukawa To: dev@dpdk.org Cc: david.marchand@6wind.com, john.mcnamara@intel.com, michalx.k.jastrzebski@intel.com, Tetsuya Mukawa Date: Thu, 16 Jun 2016 11:33:11 +0900 Message-Id: <1466044391-3210-3-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466044391-3210-1-git-send-email-mukawa@igel.co.jp> References: <1466044391-3210-1-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1465961172-28253-1-git-send-email-mukawa@igel.co.jp> References: <1465961172-28253-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v2] eal: Fix resource leak while secondary process maps pci devices X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch fixes resource leak of pci_uio_map_secondary(). If pci_map_resource() succeeds but mapped address is different from an address primary process mapped, this should be error. Then the addresses secondary process mapped should be freed. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/eal_common_pci_uio.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c index 488b6dd..83314c3 100644 --- a/lib/librte_eal/common/eal_common_pci_uio.c +++ b/lib/librte_eal/common/eal_common_pci_uio.c @@ -53,7 +53,7 @@ EAL_REGISTER_TAILQ(rte_uio_tailq) static int pci_uio_map_secondary(struct rte_pci_device *dev) { - int fd, i; + int fd, i, j; struct mapped_pci_resource *uio_res; struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); @@ -85,6 +85,17 @@ pci_uio_map_secondary(struct rte_pci_device *dev) "Cannot mmap device resource file %s to address: %p\n", uio_res->maps[i].path, uio_res->maps[i].addr); + if (mapaddr != MAP_FAILED) { + /* unmap addrs correctly mapped */ + for (j = 0; j < i; j++) + pci_unmap_resource( + uio_res->maps[j].addr, + (size_t)uio_res->maps[j].size); + + /* unmap addr wrongly mapped */ + pci_unmap_resource(mapaddr, + (size_t)uio_res->maps[i].size); + } return -1; } }