From nobody Sat Nov 2 12:22:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 148999893520255.28587879199927; Mon, 20 Mar 2017 01:35:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 66838803ED; Mon, 20 Mar 2017 01:35:32 -0700 (PDT) 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) 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) X-Original-To: edk2-devel@lists.01.org X-AuditID: b6c32a36-f79c56d000001a35-02-58cf94419d8b From: Suman Prakash To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: feng.tian@intel.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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->M= apData, AsyncRequest->MapMeta, AsyncRequest->MapPrpList and AsyncRequest->PrpLi= stHost when async command is completed. Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Suman Prakash Reviewed-by: Hao Wu --- 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/NvmExpre= ss.c mode change 100644 =3D> 100755 MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpre= ss.h mode change 100644 =3D> 100755 MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpre= ssPassthru.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 =3D 2; Cq =3D Private->CqBuffer[QueueId] + Private->CqHdbl[QueueId].Cqh; 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,=20 + AsyncRequest->PrpListNo,=20 + 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/MdeM= odulePkg/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); --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel