From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2673D803F9 for ; Mon, 20 Mar 2017 19:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490062181; x=1521598181; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=ucY0HIS1f2gdFP7p9Wc75J102B3ey8d4VXGOtiIxSlo=; b=RKj5/p266xsspNkP3RZNA4U0dOJo5e9Wel0q5kIc8UEY+imFzbUnqyV4 hocyDDeIXMdq7/6VArgUL04VGCHz8A==; Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2017 19:09:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,197,1486454400"; d="scan'208";a="77578537" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga005.jf.intel.com with ESMTP; 20 Mar 2017 19:09:36 -0700 Received: from fmsmsx115.amr.corp.intel.com (10.18.116.19) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 20 Mar 2017 19:09:18 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx115.amr.corp.intel.com (10.18.116.19) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 20 Mar 2017 19:09:17 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.59]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.204]) with mapi id 14.03.0248.002; Tue, 21 Mar 2017 10:08:33 +0800 From: "Wu, Hao A" To: Suman Prakash , "edk2-devel@lists.01.org" CC: "Tian, Feng" Thread-Topic: [edk2] [PATCH-V1] MdeModulePkg/NvmExpressDxe: Memory leak fix in async code flow Thread-Index: AQHSoVUP3lDGPDKBYEGDviot71KCSKGejNig Date: Tue, 21 Mar 2017 02:08:32 +0000 Message-ID: References: In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH-V1] MdeModulePkg/NvmExpressDxe: Memory leak fix in async code flow X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Mar 2017 02:09:41 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Hao Wu I have removed some tab usages and trailing white space cases in the patch. Pushed as commit: f2333c707dd04f069c102bcae004561ec590a3a0 Best Regards, Hao Wu > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Suman Prakash > Sent: Monday, March 20, 2017 4:35 PM > To: edk2-devel@lists.01.org > Cc: Tian, Feng > Subject: [edk2] [PATCH-V1] MdeModulePkg/NvmExpressDxe: Memory leak > fix in async code flow >=20 > MdeModulePkg/NvmExpressDxe: Memory leak fix > in async code flow >=20 > For async commands, the buffer allocated for Prp list is > not getting freed, which will cause memory leak for async > read write command. For example testing async command flow > with custom application to send multiple read write commands > were resulting in decrease of available memory page in memmap, > which eventually resulted in system hang. Hence freeing AsyncRequest- > >MapData, > AsyncRequest->MapMeta, AsyncRequest->MapPrpList and AsyncRequest- > >PrpListHost > when async command is completed. >=20 > Cc: Feng Tian > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Suman Prakash > --- > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c | 23 > +++++++++++++++++++++- > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h | 5 +++++ > .../Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 5 +++++ > 3 files changed, 32 insertions(+), 1 deletion(-) > mode change 100644 =3D> 100755 > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > mode change 100644 =3D> 100755 > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h > mode change 100644 =3D> 100755 > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c >=20 > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > old mode 100644 > new mode 100755 > index 39f49bd..ec6af58 > --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > @@ -548,6 +548,8 @@ ProcessAsyncTaskList ( > QueueId =3D 2; > Cq =3D Private->CqBuffer[QueueId] + Private->CqHdbl[QueueId].C= qh; > HasNewItem =3D FALSE; > + PciIo =3D Private->PciIo; > + >=20 > // > // Submit asynchronous subtasks to the NVMe Submission Queue > @@ -644,6 +646,26 @@ ProcessAsyncTaskList ( > sizeof(EFI_NVM_EXPRESS_COMPLETION) > ); >=20 > + // > + // Free the resources allocated before cmd submission > + // > + if (AsyncRequest->MapData !=3D NULL) { > + PciIo->Unmap (PciIo, AsyncRequest->MapData); > + } > + if (AsyncRequest->MapMeta !=3D NULL) { > + PciIo->Unmap (PciIo, AsyncRequest->MapMeta); > + } > + if (AsyncRequest->MapPrpList !=3D NULL) { > + PciIo->Unmap (PciIo, AsyncRequest->MapPrpList); > + } > + if (AsyncRequest->PrpListHost !=3D NULL) { > + PciIo->FreeBuffer ( > + PciIo, > + AsyncRequest->PrpListNo, > + AsyncRequest->PrpListHost > + ); > + } > + > RemoveEntryList (Link); > gBS->SignalEvent (AsyncRequest->CallerEvent); > FreePool (AsyncRequest); > @@ -666,7 +688,6 @@ ProcessAsyncTaskList ( > } >=20 > if (HasNewItem) { > - PciIo =3D Private->PciIo; > Data =3D ReadUnaligned32 ((UINT32*)&Private->CqHdbl[QueueId]); > PciIo->Mem.Write ( > PciIo, > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h > b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h > old mode 100644 > new mode 100755 > index 6a1c257..fa4a34a > --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h > +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h > @@ -292,6 +292,11 @@ typedef struct { >=20 > EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet; > UINT16 CommandId; > + VOID *MapPrpList; > + UINTN PrpListNo; > + VOID *PrpListHost; > + VOID *MapData; > + VOID *MapMeta; > EFI_EVENT CallerEvent; > } NVME_PASS_THRU_ASYNC_REQ; >=20 > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c > b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c > old mode 100644 > new mode 100755 > index 2c30009..f0cca72 > --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c > +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c > @@ -627,6 +627,11 @@ NvmExpressPassThru ( > AsyncRequest->Packet =3D Packet; > AsyncRequest->CommandId =3D Sq->Cid; > AsyncRequest->CallerEvent =3D Event; > + AsyncRequest->MapData =3D MapData; > + AsyncRequest->MapMeta =3D MapMeta; > + AsyncRequest->MapPrpList =3D MapPrpList; > + AsyncRequest->PrpListNo =3D PrpListNo; > + AsyncRequest->PrpListHost =3D PrpListHost; >=20 > OldTpl =3D gBS->RaiseTPL (TPL_NOTIFY); > InsertTailList (&Private->AsyncPassThruQueue, &AsyncRequest->Link); > -- > 1.9.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel