From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6D298A034C; Fri, 8 Apr 2022 16:52:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D01F9410EC; Fri, 8 Apr 2022 16:52:40 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id A71DB4003F; Fri, 8 Apr 2022 16:52:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649429559; x=1680965559; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=i3N4KrPerk4Vcig11gA1sZsATNgytYbL3hZOdjXT54Q=; b=Krd8FSCZ9xZOUBKmApgw8hNFqa5IEBk68BTsy8uOMOslfoDQJx0WvpYW of94pHtgn2aoqFdeLOGeteVwt69D+6pjnJQOe64NoLtijl5FpE9zkqGrG 1edbp13auT0rLpIAI62Q6GbQNgnj4ahUcy7xsY7LqdiOhQ5qOOMCmtuew J8hnFhXM2uXkRXedToL1koAZdkCIQyqNobOXfRArSZT3WKAjJTyXsngnj HtkwMREAlBzJLx4aYGBcZy0f9xaUpqJxS1bzYNDui3Tk0l8yMEgiI0tUf cnmiMbyE3mDqXs5/VL+kAu1gLqxtk17Mir68D/vEPZg54n7OGgA7JW0Rp A==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="249138742" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="249138742" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 07:52:37 -0700 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="525400846" Received: from bricha3-mobl.ger.corp.intel.com ([10.213.224.53]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 08 Apr 2022 07:52:36 -0700 Date: Fri, 8 Apr 2022 15:52:33 +0100 From: Bruce Richardson To: Kevin Laatz Cc: dev@dpdk.org, stable@dpdk.org, Conor Walsh Subject: Re: [PATCH 2/5] dma/idxd: fix memory leak due to free on incorrect pointer Message-ID: References: <20220408141504.1319913-1-kevin.laatz@intel.com> <20220408141504.1319913-3-kevin.laatz@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220408141504.1319913-3-kevin.laatz@intel.com> 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 On Fri, Apr 08, 2022 at 03:15:01PM +0100, Kevin Laatz wrote: > During PCI device close, any allocated memory needs to be free'd. > Currently, one of the free's is being called on an incorrect idxd_dmadev > struct member, namely 'batch_idx_ring', causing a memleak from the > pointer that should have been free'd. > This patch fixes this memleak by calling free on the correct pointer. > > Fixes: 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe") > Cc: stable@dpdk.org > Cc: bruce.richardson@intel.com > > Signed-off-by: Kevin Laatz > --- > drivers/dma/idxd/idxd_pci.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/dma/idxd/idxd_pci.c b/drivers/dma/idxd/idxd_pci.c > index 7036eb938d..fdb1f15750 100644 > --- a/drivers/dma/idxd/idxd_pci.c > +++ b/drivers/dma/idxd/idxd_pci.c > @@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev) > > /* free device memory */ > IDXD_PMD_DEBUG("Freeing device driver memory"); > - rte_free(idxd->batch_idx_ring); > + rte_free(idxd->batch_comp_ring); > rte_free(idxd->desc_ring); > This is largely my fault, I expect, for being "smart" and allocating the memory for both arrays from the one allocation. To clarify things, we need to: 1) update the commit log message explaining why it's the wrong pointer, i.e. that the two are in the one memory reservation 2) similarly add a comment to the rte_free call noting that it frees the idx_ring too. Alternatively, we can also consider adjusting the allocation code so both arrays are allocated separately, and on free are freed similarly. We would, however, need to double check that doing so introduces no perf hit. /Bruce