From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CACCA803D6 for ; Mon, 20 Mar 2017 01:35:30 -0700 (PDT) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ON300PIIUIP6CC0@mailout4.samsung.com> for edk2-devel@lists.01.org; Mon, 20 Mar 2017 17:35:13 +0900 (KST) Received: from epsmges1p2.samsung.com (unknown [182.195.42.54]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20170320083513epcas1p3ad2efcdbe591a06085564e94bb387001~tih4h9Osg2838828388epcas1p3i; Mon, 20 Mar 2017 08:35:13 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 46.C7.06709.1449FC85; Mon, 20 Mar 2017 17:35:13 +0900 (KST) Received: from epcpsbgm1new.samsung.com (u26.gpu120.samsung.co.kr [203.254.230.26]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20170320083513epcas1p3296f5fef6610fa19af50669a1465a669~tih4OyBph2360623606epcas1p3k; Mon, 20 Mar 2017 08:35:13 +0000 (GMT) X-AuditID: b6c32a36-f79c56d000001a35-02-58cf94419d8b Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id F0.92.06425.1449FC85; Mon, 20 Mar 2017 17:35:13 +0900 (KST) Received: from amit.kp-ubuntu.sisodomain.com ([107.108.221.253]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ON300DGTUII0J40@mmp1.samsung.com>; Mon, 20 Mar 2017 17:35:13 +0900 (KST) From: Suman Prakash To: edk2-devel@lists.01.org Cc: feng.tian@intel.com, Suman Prakash Date: Mon, 20 Mar 2017 14:04:55 +0530 Message-id: X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRmVeSWpSXmKPExsWy7bCmvq7jlPMRBr/bdSz2HDrKbDFpN7vF +1/n2R2YPRbvecnk0T37H4tH35ZVjAHMUVw2Kak5mWWpRfp2CVwZ57Y/YCu4q1Qxe11+A+Md qS5GTg4JAROJJW++M0HYYhIX7q1n62Lk4hAS2MEocXvSUSYIp51JYtXpr0wwHTs7DkElljNK PPi4HaqliUniz9TdzCBVbAKaEou7e1hBbBEBaYkNV9ezg9jMAjYSk1a2MoLYwgJREi2/L4LV swioSnzcc5QNxOYViJY4Ov8OM8Q2OYmTxyazgiyQEFjDJnHi7jagZg4gR1Zi0wGoGheJO3vP skPYwhKvjm+BsqUlVv27xQTR280o0f7xOpQzhVFi1ZJGqEH2EkceVkEcxyfx7ivI0SBhXomO NiEI00Pi4scyiJGOEjcfzgJbKyQQK3H21k32CYzSCxgZVjGKpRYU56anFhsWGOkVJ+YWl+al 6yXn525iBEebltkOxkXnfA4xCnAwKvHw3rh0LkKINbGsuDL3EKMEB7OSCO+OhPMRQrwpiZVV qUX58UWlOanFhxilOViUxHlZDSZGCAmkJ5akZqemFqQWwWSZODilGhgZ9WqCte7lyDPzXshJ X5N8wDgx+vhsqU9+7xTSLps4/Lxx9sbUX/U3j/5Zu29d2rcbrpOtXGZtSDXuYbx2/YSpKLd4 wsL2L1v44mv8jOuSGISY7pVynJp9+luGaLOmg5uUaozZ3IdFQS7mKT8yM9myTddxbZBQbd+y d+rLpTZTXKym/94g9kKJpTgj0VCLuag4EQB+7qbGsgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGLMWRmVeSWpSXmKPExsVy+t9jAV3HKecjDNqPSFjsOXSU2WLSbnaL 97/Oszsweyze85LJo3v2PxaPvi2rGAOYo9xsMlITU1KLFFLzkvNTMvPSbZVCQ9x0LZQU8hJz U22VInR9Q4KUFMoSc0qBPCMDNODgHOAerKRvl+CWcW77A7aCu0oVs9flNzDekepi5OSQEDCR 2NlxiAnCFpO4cG89WxcjF4eQwFJGiZ0rlzBBOC1MEiv23mABqWIT0JRY3N3DCmKLCEhLbLi6 nh3EZhawkZi0spURxBYWiJJY9fkR2FQWAVWJj3uOsoHYvALREhsuLWKG2CYncfLYZNYJjNwL GBlWMUqkFiQXFCel5xrmpZbrFSfmFpfmpesl5+duYgSH2TOpHYwHd7kfYhTgYFTi4TW4ei5C iDWxrLgy9xCjBAezkgjvjoTzEUK8KYmVValF+fFFpTmpxYcYTYEOmMgsJZqcD4yBvJJ4QxNz E3NjAwtzS0sTIyVx3sbZz8KFBNITS1KzU1MLUotg+pg4OKUaGGcHsr7/cYXT/JL8wzoBl4i+ g8U6M9kiExObIl7veHOyy+L2B+MONtuo/cuPrQtI5Vadvuq44o3ayt88kR/fLHStb11wxdDq 7SJLtgDWkwfnVjdOcBIpSX67239NX94+kQfh5za9dfoax+Wnn8acuP3k45k9L4unVVS8OGdZ v0rj8jef9jz7i0osxRmJhlrMRcWJAINIPrlJAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170320083513epcas1p3296f5fef6610fa19af50669a1465a669 X-Msg-Generator: CA X-Sender-IP: 203.254.230.26 X-Local-Sender: =?UTF-8?B?U1VNQU4gUFJBS0FTSCBCG1NTSVItU1NEIFNvbHV0aW9ucxs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBDaGllZiBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?U1VNQU4gUFJBS0FTSCBCG1NTSVItU1NEIFNvbHV0aW9ucxtT?= =?UTF-8?B?YW1zdW5nwqBFbGVjdHJvbmljcxtTZW5pb3IgQ2hpZWYgRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG1NXQUhRG0MxMElEMDdJRDAxMTAxMg==?= CMS-TYPE: 101P X-HopCount: 7 X-CMS-RootMailID: 20170320083513epcas1p3296f5fef6610fa19af50669a1465a669 X-RootMTR: 20170320083513epcas1p3296f5fef6610fa19af50669a1465a669 References: Subject: [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: Mon, 20 Mar 2017 08:35:31 -0000 MdeModulePkg/NvmExpressDxe: Memory leak fix in async code flow 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. 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 => 100755 MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c mode change 100644 => 100755 MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h mode change 100644 => 100755 MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c 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 = 2; Cq = Private->CqBuffer[QueueId] + Private->CqHdbl[QueueId].Cqh; HasNewItem = FALSE; + PciIo = Private->PciIo; + // // Submit asynchronous subtasks to the NVMe Submission Queue @@ -644,6 +646,26 @@ ProcessAsyncTaskList ( sizeof(EFI_NVM_EXPRESS_COMPLETION) ); + // + // Free the resources allocated before cmd submission + // + if (AsyncRequest->MapData != NULL) { + PciIo->Unmap (PciIo, AsyncRequest->MapData); + } + if (AsyncRequest->MapMeta != NULL) { + PciIo->Unmap (PciIo, AsyncRequest->MapMeta); + } + if (AsyncRequest->MapPrpList != NULL) { + PciIo->Unmap (PciIo, AsyncRequest->MapPrpList); + } + if (AsyncRequest->PrpListHost != NULL) { + PciIo->FreeBuffer ( + PciIo, + AsyncRequest->PrpListNo, + AsyncRequest->PrpListHost + ); + } + RemoveEntryList (Link); gBS->SignalEvent (AsyncRequest->CallerEvent); FreePool (AsyncRequest); @@ -666,7 +688,6 @@ ProcessAsyncTaskList ( } if (HasNewItem) { - PciIo = Private->PciIo; Data = 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 { 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; 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 = Packet; AsyncRequest->CommandId = Sq->Cid; AsyncRequest->CallerEvent = Event; + AsyncRequest->MapData = MapData; + AsyncRequest->MapMeta = MapMeta; + AsyncRequest->MapPrpList = MapPrpList; + AsyncRequest->PrpListNo = PrpListNo; + AsyncRequest->PrpListHost = PrpListHost; OldTpl = gBS->RaiseTPL (TPL_NOTIFY); InsertTailList (&Private->AsyncPassThruQueue, &AsyncRequest->Link); -- 1.9.1