From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 6C30B74003A for ; Fri, 5 Jan 2024 13:55:52 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=f5oTEdAFRajTnv1CYpl/vrreEZq2K0+S7Mimp8w7Cnc=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1704462951; v=1; b=rmbBlZXXzLFKjwy3F2ZhffTE1Obdc18Y/5gO1XEnpIs+jtRLO2CJIVAeOQa6Wx1NqpWcZppu GB0S+bFgoJojICyCxz9NYJP0D29G7YjmutYkAvgPtuJfUjiYmrmz8Ou3gCmLcTyhu3htpy7NGV6 jo1DguDDJ9lffJ6iFo6fZX/4= X-Received: by 127.0.0.2 with SMTP id aQ4NYY7687511xBMZlR5kNUV; Fri, 05 Jan 2024 05:55:51 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.23809.1704462950522253706 for ; Fri, 05 Jan 2024 05:55:50 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-484-ZxWKgq0WOlWlP8LIT765cQ-1; Fri, 05 Jan 2024 08:55:44 -0500 X-MC-Unique: ZxWKgq0WOlWlP8LIT765cQ-1 X-Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 192C23C0D180; Fri, 5 Jan 2024 13:55:44 +0000 (UTC) X-Received: from [10.39.193.6] (unknown [10.39.193.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 10B4D1121306; Fri, 5 Jan 2024 13:55:42 +0000 (UTC) Message-ID: <6146392b-5d24-1ef5-98b2-dccaa80fd970@redhat.com> Date: Fri, 5 Jan 2024 14:55:42 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/PiSmmCpuDxeSmm: Optimize PatchSmmSaveStateMap and FlushTlbForAll To: "Ni, Ray" , "Jin, Zhi" , "devel@edk2.groups.io" Cc: "Kumar, Rahul R" , Gerd Hoffmann , "Wu, Jiaxin" References: <20240105025406.907441-1-zhi.jin@intel.com> From: "Laszlo Ersek" In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: KQlovGpbPN8JFFmTfdGY92gmx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=rmbBlZXX; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 1/5/24 13:52, Ni, Ray wrote: > Reviewed-by: Ray Ni Thanks, please feel free to merge this! Laszlo >=20 >=20 > Thanks, > Ray >> -----Original Message----- >> From: Jin, Zhi >> Sent: Friday, January 5, 2024 10:54 AM >> To: devel@edk2.groups.io >> Cc: Jin, Zhi ; Ni, Ray ; Laszlo Ers= ek >> ; Kumar, Rahul R ; Gerd >> Hoffmann ; Wu, Jiaxin >> Subject: [PATCH v2 1/1] UefiCpuPkg/PiSmmCpuDxeSmm: Optimize >> PatchSmmSaveStateMap and FlushTlbForAll >> >> PatchSmmSaveStateMap patches the SMM entry (code) and SmmSaveState >> region (data) for each core, which can be improved to flush TLB once >> after all the memory entries have been patched. >> FlushTlbForAll flushes TLB for each core in serial, which can be >> improved to flush TLB in parrallel. >> >> v2: >> Add the missing FlushTlbForAll() back in PatchSmmSaveStateMap(). >> >> Cc: Ray Ni >> Cc: Laszlo Ersek >> Cc: Rahul Kumar >> Cc: Gerd Hoffmann >> Cc: Jiaxin Wu >> Signed-off-by: Zhi Jin >> --- >> .../PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 97 >> +++++++++++++------ >> 1 file changed, 65 insertions(+), 32 deletions(-) >> >> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c >> b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c >> index 15f998e501..12f3c0b8e8 100644 >> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c >> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c >> @@ -547,17 +547,14 @@ FlushTlbForAll ( >> VOID >> ) >> { >> - UINTN Index; >> - >> FlushTlbOnCurrentProcessor (NULL); >> - >> - for (Index =3D 0; Index < gSmst->NumberOfCpus; Index++) { >> - if (Index !=3D gSmst->CurrentlyExecutingCpu) { >> - // Force to start up AP in blocking mode, >> - SmmBlockingStartupThisAp (FlushTlbOnCurrentProcessor, Index, NULL= ); >> - // Do not check return status, because AP might not be present in= some >> corner cases. >> - } >> - } >> + InternalSmmStartupAllAPs ( >> + (EFI_AP_PROCEDURE2)FlushTlbOnCurrentProcessor, >> + 0, >> + NULL, >> + NULL, >> + NULL >> + ); >> } >> >> /** >> @@ -799,72 +796,108 @@ PatchSmmSaveStateMap ( >> UINTN TileCodeSize; >> UINTN TileDataSize; >> UINTN TileSize; >> + UINTN PageTableBase; >> >> - TileCodeSize =3D GetSmiHandlerSize (); >> - TileCodeSize =3D ALIGN_VALUE (TileCodeSize, SIZE_4KB); >> - TileDataSize =3D (SMRAM_SAVE_STATE_MAP_OFFSET - SMM_PSD_OFFSET) + >> sizeof (SMRAM_SAVE_STATE_MAP); >> - TileDataSize =3D ALIGN_VALUE (TileDataSize, SIZE_4KB); >> - TileSize =3D TileDataSize + TileCodeSize - 1; >> - TileSize =3D 2 * GetPowerOfTwo32 ((UINT32)TileSize); >> + TileCodeSize =3D GetSmiHandlerSize (); >> + TileCodeSize =3D ALIGN_VALUE (TileCodeSize, SIZE_4KB); >> + TileDataSize =3D (SMRAM_SAVE_STATE_MAP_OFFSET - SMM_PSD_OFFSET) + >> sizeof (SMRAM_SAVE_STATE_MAP); >> + TileDataSize =3D ALIGN_VALUE (TileDataSize, SIZE_4KB); >> + TileSize =3D TileDataSize + TileCodeSize - 1; >> + TileSize =3D 2 * GetPowerOfTwo32 ((UINT32)TileSize); >> + PageTableBase =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; >> >> DEBUG ((DEBUG_INFO, "PatchSmmSaveStateMap:\n")); >> for (Index =3D 0; Index < mMaxNumberOfCpus - 1; Index++) { >> // >> // Code >> // >> - SmmSetMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[Index] + SMM_HANDLER_OFFSET, >> TileCodeSize, >> - EFI_MEMORY_RO >> + EFI_MEMORY_RO, >> + TRUE, >> + NULL >> ); >> - SmmClearMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[Index] + SMM_HANDLER_OFFSET, >> TileCodeSize, >> - EFI_MEMORY_XP >> + EFI_MEMORY_XP, >> + FALSE, >> + NULL >> ); >> >> // >> // Data >> // >> - SmmClearMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[Index] + SMM_HANDLER_OFFSET + >> TileCodeSize, >> TileSize - TileCodeSize, >> - EFI_MEMORY_RO >> + EFI_MEMORY_RO, >> + FALSE, >> + NULL >> ); >> - SmmSetMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[Index] + SMM_HANDLER_OFFSET + >> TileCodeSize, >> TileSize - TileCodeSize, >> - EFI_MEMORY_XP >> + EFI_MEMORY_XP, >> + TRUE, >> + NULL >> ); >> } >> >> // >> // Code >> // >> - SmmSetMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[mMaxNumberOfCpus - 1] + >> SMM_HANDLER_OFFSET, >> TileCodeSize, >> - EFI_MEMORY_RO >> + EFI_MEMORY_RO, >> + TRUE, >> + NULL >> ); >> - SmmClearMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[mMaxNumberOfCpus - 1] + >> SMM_HANDLER_OFFSET, >> TileCodeSize, >> - EFI_MEMORY_XP >> + EFI_MEMORY_XP, >> + FALSE, >> + NULL >> ); >> >> // >> // Data >> // >> - SmmClearMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[mMaxNumberOfCpus - 1] + >> SMM_HANDLER_OFFSET + TileCodeSize, >> SIZE_32KB - TileCodeSize, >> - EFI_MEMORY_RO >> + EFI_MEMORY_RO, >> + FALSE, >> + NULL >> ); >> - SmmSetMemoryAttributes ( >> + ConvertMemoryPageAttributes ( >> + PageTableBase, >> + mPagingMode, >> mCpuHotPlugData.SmBase[mMaxNumberOfCpus - 1] + >> SMM_HANDLER_OFFSET + TileCodeSize, >> SIZE_32KB - TileCodeSize, >> - EFI_MEMORY_XP >> + EFI_MEMORY_XP, >> + TRUE, >> + NULL >> ); >> + >> + FlushTlbForAll (); >> } >> >> /** >> -- >> 2.39.2 >=20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113286): https://edk2.groups.io/g/devel/message/113286 Mute This Topic: https://groups.io/mt/103536553/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-