From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 1FF8C81F40 for ; Mon, 27 Feb 2017 00:20:18 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2017 00:20:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,213,1484035200"; d="scan'208";a="938463102" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga003.jf.intel.com with ESMTP; 27 Feb 2017 00:20:17 -0800 Received: from fmsmsx120.amr.corp.intel.com (10.18.124.208) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 27 Feb 2017 00:20:17 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx120.amr.corp.intel.com (10.18.124.208) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 27 Feb 2017 00:20:17 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.204]) with mapi id 14.03.0248.002; Mon, 27 Feb 2017 16:20:13 +0800 From: "Zeng, Star" To: Ard Biesheuvel CC: "Tian, Feng" , "edk2-devel@lists.01.org" , "afish@apple.com" , "Gao, Liming" , "Yao, Jiewen" , "leif.lindholm@linaro.org" , "Kinney, Michael D" , "lersek@redhat.com" , "Zeng, Star" Thread-Topic: [edk2] [PATCH v3 4/6] MdeModulePkg/DxeCore: use separate lock for pool allocations Thread-Index: AQHSkF513ed2vNC51UmcofKTmeXmxqF8GF2w///kHoCAAIcCYA== Date: Mon, 27 Feb 2017 08:20:13 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B82C467@shsmsx102.ccr.corp.intel.com> References: <1488133805-4773-1-git-send-email-ard.biesheuvel@linaro.org> <1488133805-4773-5-git-send-email-ard.biesheuvel@linaro.org> <0C09AFA07DD0434D9E2A0C6AEB0483103B82C082@shsmsx102.ccr.corp.intel.com> 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 v3 4/6] MdeModulePkg/DxeCore: use separate lock for pool allocations X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Feb 2017 08:20:18 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable If it is really needed, I am fine to either this patch or another patch to = add it. :) Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ard = Biesheuvel Sent: Monday, February 27, 2017 4:16 PM To: Zeng, Star Cc: Tian, Feng ; edk2-devel@lists.01.org; afish@apple.= com; Gao, Liming ; Yao, Jiewen = ; leif.lindholm@linaro.org; Kinney, Michael D ;= lersek@redhat.com Subject: Re: [edk2] [PATCH v3 4/6] MdeModulePkg/DxeCore: use separate lock = for pool allocations On 27 February 2017 at 01:56, Zeng, Star wrote: > Minor comment: CoreFreePoolPagesI() has no need to have PoolType paramete= r, how about to remove it? > I need it after patch 6. But perhaps it is better to only add it there, not= here. > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of=20 > Ard Biesheuvel > Sent: Monday, February 27, 2017 2:30 AM > To: edk2-devel@lists.01.org; Yao, Jiewen ;=20 > leif.lindholm@linaro.org > Cc: Tian, Feng ; Ard Biesheuvel=20 > ; afish@apple.com; Gao, Liming=20 > ; Kinney, Michael D=20 > ; lersek@redhat.com; Zeng, Star=20 > > Subject: [edk2] [PATCH v3 4/6] MdeModulePkg/DxeCore: use separate lock=20 > for pool allocations > > In preparation of adding memory permission attribute management to the po= ol allocator, split off the locking of the pool metadata into a separate lo= ck. This is an improvement in itself, given that pool allocation can only i= nterfere with the page allocation bookkeeping if pool pages are allocated o= r released. But it is also required to ensure that the permission attribute= management does not deadlock, given that it may trigger page table splits = leading to additional page tables being allocated. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ard Biesheuvel > --- > MdeModulePkg/Core/Dxe/Mem/Pool.c | 53 ++++++++++++++++---- > 1 file changed, 43 insertions(+), 10 deletions(-) > > diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c=20 > b/MdeModulePkg/Core/Dxe/Mem/Pool.c > index 7afd2d312c1d..410615e0dee9 100644 > --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c > +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c > @@ -15,6 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. > #include "DxeMain.h" > #include "Imem.h" > > +STATIC EFI_LOCK mPoolMemoryLock =3D EFI_INITIALIZE_LOCK_VARIABLE=20 > +(TPL_NOTIFY); > + > #define POOL_FREE_SIGNATURE SIGNATURE_32('p','f','r','0') > typedef struct { > UINT32 Signature; > @@ -239,13 +241,13 @@ CoreInternalAllocatePool ( > // > // Acquire the memory lock and make the allocation > // > - Status =3D CoreAcquireLockOrFail (&gMemoryLock); > + Status =3D CoreAcquireLockOrFail (&mPoolMemoryLock); > if (EFI_ERROR (Status)) { > return EFI_OUT_OF_RESOURCES; > } > > *Buffer =3D CoreAllocatePoolI (PoolType, Size); > - CoreReleaseMemoryLock (); > + CoreReleaseLock (&mPoolMemoryLock); > return (*Buffer !=3D NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES; } > > @@ -289,6 +291,23 @@ CoreAllocatePool ( > return Status; > } > > +STATIC > +VOID * > +CoreAllocatePoolPagesI ( > + IN EFI_MEMORY_TYPE PoolType, > + IN UINTN NoPages, > + IN UINTN Granularity > + ) > +{ > + VOID *Buffer; > + > + CoreAcquireMemoryLock (); > + Buffer =3D CoreAllocatePoolPages (PoolType, NoPages, Granularity);=20 > + CoreReleaseMemoryLock (); > + > + return Buffer; > +} > + > /** > Internal function to allocate pool of a particular type. > Caller must have the memory lock held @@ -317,7 +336,7 @@ CoreAllocate= PoolI ( > UINTN NoPages; > UINTN Granularity; > > - ASSERT_LOCKED (&gMemoryLock); > + ASSERT_LOCKED (&mPoolMemoryLock); > > if (PoolType =3D=3D EfiACPIReclaimMemory || > PoolType =3D=3D EfiACPIMemoryNVS || > @@ -355,7 +374,7 @@ CoreAllocatePoolI ( > if (Index >=3D SIZE_TO_LIST (Granularity)) { > NoPages =3D EFI_SIZE_TO_PAGES(Size) + EFI_SIZE_TO_PAGES (Granularity= ) - 1; > NoPages &=3D ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1); > - Head =3D CoreAllocatePoolPages (PoolType, NoPages, Granularity); > + Head =3D CoreAllocatePoolPagesI (PoolType, NoPages, Granularity); > goto Done; > } > > @@ -383,7 +402,7 @@ CoreAllocatePoolI ( > // > // Get another page > // > - NewPage =3D CoreAllocatePoolPages(PoolType, EFI_SIZE_TO_PAGES (Granu= larity), Granularity); > + NewPage =3D CoreAllocatePoolPagesI (PoolType, EFI_SIZE_TO_PAGES=20 > + (Granularity), Granularity); > if (NewPage =3D=3D NULL) { > goto Done; > } > @@ -486,9 +505,9 @@ CoreInternalFreePool ( > return EFI_INVALID_PARAMETER; > } > > - CoreAcquireMemoryLock (); > + CoreAcquireLock (&mPoolMemoryLock); > Status =3D CoreFreePoolI (Buffer, PoolType); > - CoreReleaseMemoryLock (); > + CoreReleaseLock (&mPoolMemoryLock); > return Status; > } > > @@ -525,6 +544,19 @@ CoreFreePool ( > return Status; > } > > +STATIC > +VOID > +CoreFreePoolPagesI ( > + IN EFI_MEMORY_TYPE PoolType, > + IN EFI_PHYSICAL_ADDRESS Memory, > + IN UINTN NoPages > + ) > +{ > + CoreAcquireMemoryLock (); > + CoreFreePoolPages (Memory, NoPages); > + CoreReleaseMemoryLock (); > +} > + > /** > Internal function to free a pool entry. > Caller must have the memory lock held @@ -573,7 +605,7 @@ CoreFreePool= I ( > // > ASSERT (Tail->Signature =3D=3D POOL_TAIL_SIGNATURE); > ASSERT (Head->Size =3D=3D Tail->Size); > - ASSERT_LOCKED (&gMemoryLock); > + ASSERT_LOCKED (&mPoolMemoryLock); > > if (Tail->Signature !=3D POOL_TAIL_SIGNATURE) { > return EFI_INVALID_PARAMETER; > @@ -624,7 +656,7 @@ CoreFreePoolI ( > // > NoPages =3D EFI_SIZE_TO_PAGES(Size) + EFI_SIZE_TO_PAGES (Granularity= ) - 1; > NoPages &=3D ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1); > - CoreFreePoolPages ((EFI_PHYSICAL_ADDRESS) (UINTN) Head, NoPages); > + CoreFreePoolPagesI (Pool->MemoryType, (EFI_PHYSICAL_ADDRESS) > + (UINTN) Head, NoPages); > > } else { > > @@ -680,7 +712,8 @@ CoreFreePoolI ( > // > // Free the page > // > - CoreFreePoolPages ((EFI_PHYSICAL_ADDRESS) (UINTN)NewPage, EFI_SI= ZE_TO_PAGES (Granularity)); > + CoreFreePoolPagesI (Pool->MemoryType, (EFI_PHYSICAL_ADDRESS) (UI= NTN)NewPage, > + EFI_SIZE_TO_PAGES (Granularity)); > } > } > } > -- > 2.7.4 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel