From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail03.groups.io (mail03.groups.io [45.79.227.220]) by spool.mail.gandi.net (Postfix) with ESMTPS id 048C0740038 for ; Thu, 11 Apr 2024 03:27:37 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=rF+0FplC91vfCx6IWqk2Uppw+8onG4qmD7MkvTrVyAg=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20240206; t=1712806056; v=1; b=gcDHOsZuJf6EfNUrDJp/V6Yu4Qeg7RZktx380sRd6D00n6jyaHRro5jDeH0k6nXGCbxIVfff kGz75okMkjafG6MgcsLYje+InAGl3JLPN9EUaG+zqECxpht9XXVJ6Je3XHqxaSKdt34aWXsifsO Sf6EaktT2MlNdzaM6tmLkWBDI3jCUrZQT3DU1SJpGxUKrkAz4Lz35WFK5eh21IBqvX5JUR/qz8M q63m0bLED1ph38+2zHMtdTgPNlDETU+UDHy4VqxSEZCucizfaqrxiMzf8E1B+9Vh1RYXbBxWQGZ 2RyKnPq1v54R1oNSC2D8OgKh/1D4Arc9AHqTbbWn5JR/g== X-Received: by 127.0.0.2 with SMTP id yn4JYY7687511xrpCQ6xRFwF; Wed, 10 Apr 2024 20:27:36 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by mx.groups.io with SMTP id smtpd.web10.9157.1712806056013726025 for ; Wed, 10 Apr 2024 20:27:36 -0700 X-CSE-ConnectionGUID: mBKbKKslTN+G7Dr+qJKY9A== X-CSE-MsgGUID: pF7bRqH7TdmipGv/fYUqtQ== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="19352144" X-IronPort-AV: E=Sophos;i="6.07,192,1708416000"; d="scan'208,217";a="19352144" X-Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2024 20:27:36 -0700 X-CSE-ConnectionGUID: tUUGyeE4SNSVf6Q4mS1LqQ== X-CSE-MsgGUID: E/ZFbAVBShCOmysxk8e4pQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,192,1708416000"; d="scan'208,217";a="21264886" X-Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orviesa007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 10 Apr 2024 20:27:35 -0700 X-Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 10 Apr 2024 20:27:34 -0700 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 10 Apr 2024 20:27:34 -0700 X-Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Wed, 10 Apr 2024 20:27:34 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.168) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 10 Apr 2024 20:27:34 -0700 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by SJ0PR11MB8295.namprd11.prod.outlook.com (2603:10b6:a03:479::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.25; Thu, 11 Apr 2024 03:27:32 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::2c31:82b7:9f26:5817]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::2c31:82b7:9f26:5817%5]) with mapi id 15.20.7430.045; Thu, 11 Apr 2024 03:27:31 +0000 From: "Ni, Ray" To: "Wu, Jiaxin" , "devel@edk2.groups.io" CC: Ard Biesheuvel , "Yao, Jiewen" , Gerd Hoffmann Subject: Re: [edk2-devel] [PATCH v1 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid Thread-Topic: [PATCH v1 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemoryGuid Thread-Index: AQHai08XLw9eZAp8oUSO/RtDhCH/3bFiaEJ5 Date: Thu, 11 Apr 2024 03:27:31 +0000 Message-ID: References: <20240410135724.15344-1-jiaxin.wu@intel.com> <20240410135724.15344-9-jiaxin.wu@intel.com> In-Reply-To: <20240410135724.15344-9-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|SJ0PR11MB8295:EE_ x-ms-office365-filtering-correlation-id: c7ebf38c-c833-4a03-b150-08dc59d7529b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: VtzQcpEtInXu+Eg+9gGDNfdQlG3imf8NKkIfIudnWmEwLa4ykNzYxoz/N03cJMs4X3Ayf4ZoNUljAMgDVI2MegNsnEFX1+R82yvp0PUAHbJXV51jWLvNWoP3wjH195V63zGxEPZD0nKhf+KnmVVMy5Q0Wx5VRVR3u58cKe49nmSe+8TSjgvfiMYd21hxJiyXqFZaSc5ck41sABOUIJYb7IK4adxpV7YDdb2VBf98JxCaVPrNDhEq82PqRJtBbcjDW5J3SysSUTTQAZ0qarU/b6YKP6dBipiOs4tX00NGOwRnVZaCqgHJIcDovuFmbyf4VCOdYtBZRz9tWNXijYkJOE697g1UWEXmC5K5QoJHO8vgPcMaJwRAHrXDyttzE6m/BhqyK2s3pX6Chmz/tmZXpl4MzUSfxJOKOPVwNPaVoedlmtwv3XWCFx88MPfyp4wlMnKdj3Z3lFI3x4yP10jz+PvbNk2IzMmYQcchW/zNdq6StkAt22kg9cj/Gck4K5fpYQa1sLN459eD/PruIKH/JQlh8U413Psl1CKpWZ0I/eZC2a7yA2Q4HGglr0a1T5Oza3UDLFv1n7V3VsFbnB9via0gJoDr+T9adDfuKU75iQ4OmtQRcBNispX2cZqSwN/lZNz9LSUkCT83r0ybssezKh/SRsCNeO59F7r8tY4ix76xj88hqtLy80oK+bDbF2shLJ4jArAA5rxO/G5f/oSlbA== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?i5thjmsSxWx3Ku5gieizXg5e2eZN0GrvnKE6EQClcNxcuhC4T6kxgNnt2b?= =?iso-8859-1?Q?IFZtsqK9UG2zA5y/K7P+Iob1CTwuYgeK05/sjH3vh1uNKRtkCBzc5ZnxWs?= =?iso-8859-1?Q?WVj3RXxeX0gw+KHaBYsmncbHcKIhCp/hKWG7NrtvRHu37ivJr0mR7CxCHG?= =?iso-8859-1?Q?eLTJtrrgQ66+4wkTG0PLSjDx/g4K6sMdPmQK2+gzscG3GPWha3ly+poISd?= =?iso-8859-1?Q?CFmGTxQbJpeMsZyaMLGvx6wfpZvDOEs/bV2XheBAnlklpSH9puoVu1N0Vz?= =?iso-8859-1?Q?WGafNATDO07H7aD6l8vMc5nX+tc4FY5u2A9E7KOwc29aOEbinF2b9TLrrA?= =?iso-8859-1?Q?yxg17gwop1K9LO495pJmklZQoNej4WQCzYj64DOnaRHjMjQfHPUOyPaZPK?= =?iso-8859-1?Q?egeSesnTMYWJWTvu9vrtzl09o2ieuwx3936fHNYFBUPcxSZUh8FEmAEibX?= =?iso-8859-1?Q?lTg1DQZBvEWkmL3d9Mz/zBZRvy0OuaZaKDHSCbcM7stNAumZGFHBABfjk+?= =?iso-8859-1?Q?AS60oksS6U7dVqCpCwMTl9jJBY6IMWwoSly/SayDdayWoPlLCfgWA9WsTB?= =?iso-8859-1?Q?UjCrnZR1mZeqOP4oHZgBkpMZpADRJJf4XP/Og/QktiZXbEnOXZ949FgQ60?= =?iso-8859-1?Q?fd2o58qdBjOUMlAxLspIz4pBqnuZqUtZ+RF7jjtY8t3bDtbgSL+o3h86lQ?= =?iso-8859-1?Q?gKuMdVSjdK5wRE/Hor7ypDk1TpDdy9L97O8wlqOs9cnHR6XRzL0Rb+PSrO?= =?iso-8859-1?Q?2ZfhtpH4FY2Biz+yoxCeHHPDYb859dmeBY9EaU1/UqVzYld1A/q2K4wFda?= =?iso-8859-1?Q?XYxP0HyoDtL9RzvDGdxi8/wfk0lTxnyu0FxBE+XAGBV32296/fTRE4pImb?= =?iso-8859-1?Q?u47Pb1tgcMeMTwbfBMfDQvlpWKC3Mua2GUMw0oLHY4RVj38pv6R6AKSS76?= =?iso-8859-1?Q?T1Lgnxow9VnqzSVJkeT6R1NTKHktg2pNzC545GcuQ5Zjp/HwhVi2aQ/4YI?= =?iso-8859-1?Q?YVmM9TpFLlRDm0QnK6HzsEmIazFxkrlLdArDMTCSDI3pMjIogeA8Z1kOgv?= =?iso-8859-1?Q?EYhOCiOFZOAvQIV5hQJVBYjlgSn9ymmvCCdhU+qthzedalLKTuQkrjJOx3?= =?iso-8859-1?Q?aUVmKahPuQ6yI/l3eYCaQoHP1vKsVgWojpdsSPM7r5hlJdJAtWHcMkEEJ7?= =?iso-8859-1?Q?wLuaMDqrIHNW/KH6YbqlgTKXMXBviLdYy+qOtlauLI6fOWC3AwtRSZqDu6?= =?iso-8859-1?Q?5sc58h2iZ8J9KU3vYDdke1HbQgVgMJnxVoIFMTrqaokv5mC3DrMRy0nHEn?= =?iso-8859-1?Q?9VfDn4lsU/ePJ236J0Fn2P9Jnoc+5NJaRBV4QYfCRHleiv9njLdoDXnlA8?= =?iso-8859-1?Q?aRk+aGRotKy90rctst3riKvJTteyzEuyERfZW6vY9h7g+WmxReroVOtSGc?= =?iso-8859-1?Q?WA+KPjm8OCKA5yXokZzoTr07SEg8do0bbyZwgdtfVhCXMP/N09EIQuPtHJ?= =?iso-8859-1?Q?2IledcSZSOS293l42SJdZ+Ncn+0uELdygGxo/KLx/Y44WH9rL2bI4uBovN?= =?iso-8859-1?Q?OMsYN/GyoUGRthypeXnCwCPYpccYz/D4/M/CMZHTYJgqP3z0Fp6OR0gXVJ?= =?iso-8859-1?Q?ys+1zPclbDUZE=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7ebf38c-c833-4a03-b150-08dc59d7529b X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Apr 2024 03:27:31.8305 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Zj4Yf88RCkgag32fGL9Qx/N2SmS81D1Mq+904J7Kd1FvDFNgpbGBwhYJ71bK+fPcxBCu9AtPnEo94mlRokAZ8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB8295 X-OriginatorOrg: intel.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 Resent-Date: Wed, 10 Apr 2024 20:27:36 -0700 Resent-From: ray.ni@intel.com Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: dmxbwjXUwoSgsnCJuNKMNkJvx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB824462523C11D209058661768C052MN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=gcDHOsZu; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.227.220 as permitted sender) smtp.mailfrom=bounce@groups.io --_000_MN6PR11MB824462523C11D209058661768C052MN6PR11MB8244namp_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I think the commit message can have more details to help OVMF developers un= derstand the needs of this patch. E.g.: Before using SmmRelocationLib, the PiSmmCpuDxeSmm driver allocates the SM= RAM to be used for SMI handler + save state area of each processor from Sms= t->AllocatePages(). With SmmRelocationLib, the SMRAM allocation for SMI handlers and save sta= te areas is moved to early PEI phase when the Smst->AllocatePages() service= is not available. So, the allocation is done by splitting the SMRAM out of the SMRAM regions reported from Guid HOB (gEfi= SmmSMramMemoryGuid). However, OVMF platform does not produce the GUID HOB. This patch produces= the HOB...... Thanks, Ray ________________________________ From: Wu, Jiaxin Sent: Wednesday, April 10, 2024 21:57 To: devel@edk2.groups.io Cc: Ard Biesheuvel ; Yao, Jiewen ; Gerd Hoffmann ; Ni, Ray Subject: [PATCH v1 08/13] OvmfPkg/PlatformInitLib: Create gEfiSmmSmramMemor= yGuid SmmRelocationLib instance will reserve the memory from gEfiSmmSmramMemoryGuid for the smbase relocation. So, system must produce the gEfiSmmSmramMemoryGuid. This patch is for the OVMF to produce the gEfiSmmSmramMemoryGuid HOB. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Ray Ni Signed-off-by: Jiaxin Wu --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 97 +++++++++++++-----= ---- .../Library/PlatformInitLib/PlatformInitLib.inf | 5 +- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 7b6e5102ad..8b98256225 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -1,9 +1,9 @@ /**@file Memory Detection for Virtual Machines. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent Module Name: MemDetect.c @@ -41,10 +41,12 @@ Module Name: #include #include #include +#include + #define MEGABYTE_SHIFT 20 VOID EFIAPI PlatformQemuUc32BaseInitialization ( @@ -1027,52 +1029,73 @@ PlatformQemuInitializeRam ( // // Determine total memory size available // PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob); - if (PlatformInfoHob->BootMode =3D=3D BOOT_ON_S3_RESUME) { - // - // Create the following memory HOB as an exception on the S3 boot path= . + // + // CpuMpPei saves the original contents of the borrowed area in permanen= t + // PEI RAM, in a backup buffer allocated with the normal PEI services. + // CpuMpPei restores the original contents ("returns" the borrowed area)= at + // End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before + // transferring control to the OS's wakeup vector in the FACS. + // + // We expect any other PEIMs that "borrow" memory similarly to CpuMpPei = to + // restore the original contents. Furthermore, we expect all such PEIMs + // (CpuMpPei included) to claim the borrowed areas by producing memory + // allocation HOBs, and to honor preexistent memory allocation HOBs when + // looking for an area to borrow. + // + QemuInitializeRamBelow1gb (PlatformInfoHob); + + if (PlatformInfoHob->SmmSmramRequire) { + UINT32 TsegSize; + UINTN BufferSize; + UINT8 SmramRanges; + EFI_PEI_HOB_POINTERS Hob; + EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *SmramHobDescriptorBlock; + + TsegSize =3D PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; + PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - Tseg= Size); + PlatformAddReservedMemoryBaseSizeHob ( + PlatformInfoHob->LowMemory - TsegSize, + TsegSize, + TRUE + ); + + SmramRanges =3D 2; + BufferSize =3D sizeof (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK) + (SmramRanges= - 1) * sizeof (EFI_SMRAM_DESCRIPTOR); + + Hob.Raw =3D BuildGuidHob ( + &gEfiSmmSmramMemoryGuid, + BufferSize + ); + ASSERT (Hob.Raw); + + SmramHobDescriptorBlock =3D (EFI_SMRAM_HOB= _DESCRIPTOR_BLOCK *)(Hob.Raw); + SmramHobDescriptorBlock->NumberOfSmmReservedRegions =3D SmramRanges; + // - // Normally we'd create memory HOBs only on the normal boot path. Howe= ver, - // CpuMpPei specifically needs such a low-memory HOB on the S3 path as - // well, for "borrowing" a subset of it temporarily, for the AP startu= p - // vector. + // Create first SMRAM descriptor, which contains data structures used = in S3 resume. + // One page is enough for the data structure // - // CpuMpPei saves the original contents of the borrowed area in perman= ent - // PEI RAM, in a backup buffer allocated with the normal PEI services. - // CpuMpPei restores the original contents ("returns" the borrowed are= a) at - // End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before - // transferring control to the OS's wakeup vector in the FACS. + SmramHobDescriptorBlock->Descriptor[0].PhysicalStart =3D PlatformInfoH= ob->LowMemory - TsegSize; + SmramHobDescriptorBlock->Descriptor[0].CpuStart =3D PlatformInfoH= ob->LowMemory - TsegSize; + SmramHobDescriptorBlock->Descriptor[0].PhysicalSize =3D EFI_PAGE_SIZE= ; + SmramHobDescriptorBlock->Descriptor[0].RegionState =3D EFI_SMRAM_CLO= SED | EFI_CACHEABLE | EFI_ALLOCATED; + // - // We expect any other PEIMs that "borrow" memory similarly to CpuMpPe= i to - // restore the original contents. Furthermore, we expect all such PEIM= s - // (CpuMpPei included) to claim the borrowed areas by producing memory - // allocation HOBs, and to honor preexistent memory allocation HOBs wh= en - // looking for an area to borrow. + // Create second SMRAM descriptor, which is free and will be used by S= MM foundation. // - QemuInitializeRamBelow1gb (PlatformInfoHob); + SmramHobDescriptorBlock->Descriptor[1].PhysicalStart =3D SmramHobDescr= iptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZE; + SmramHobDescriptorBlock->Descriptor[1].CpuStart =3D SmramHobDescr= iptorBlock->Descriptor[0].CpuStart + EFI_PAGE_SIZE; + SmramHobDescriptorBlock->Descriptor[1].PhysicalSize =3D TsegSize - EF= I_PAGE_SIZE; + SmramHobDescriptorBlock->Descriptor[1].RegionState =3D EFI_SMRAM_CLO= SED | EFI_CACHEABLE; } else { - // - // Create memory HOBs - // - QemuInitializeRamBelow1gb (PlatformInfoHob); - - if (PlatformInfoHob->SmmSmramRequire) { - UINT32 TsegSize; - - TsegSize =3D PlatformInfoHob->Q35TsegMbytes * SIZE_1MB; - PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory - Ts= egSize); - PlatformAddReservedMemoryBaseSizeHob ( - PlatformInfoHob->LowMemory - TsegSize, - TsegSize, - TRUE - ); - } else { - PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory); - } + PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob->LowMemory); + } + if (PlatformInfoHob->BootMode !=3D BOOT_ON_S3_RESUME) { // // If QEMU presents an E820 map, then create memory HOBs for the >=3D4= GB RAM // entries. Otherwise, create a single memory HOB with the flat >=3D4G= B // memory size read from the CMOS. // diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/= Library/PlatformInitLib/PlatformInitLib.inf index 5a79d95b68..2bb1c0296f 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -1,10 +1,10 @@ ## @file # Platform Initialization Lib # # This module provides platform specific function to detect boot mode. -# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -54,10 +54,13 @@ PeiHardwareInfoLib [LibraryClasses.X64] TdxLib +[Guids] + gEfiSmmSmramMemoryGuid + [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable [FixedPcd] -- 2.16.2.windows.1 -=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 (#117613): https://edk2.groups.io/g/devel/message/117613 Mute This Topic: https://groups.io/mt/105441999/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_MN6PR11MB824462523C11D209058661768C052MN6PR11MB8244namp_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I think the commit message can have more details to help OVMF developers un= derstand the needs of this patch.
E.g.:
  Before using SmmRelocationLib, the PiSmmCpuDxeSmm driver allocates t= he SMRAM to be used for SMI handler + save state area of each processor fro= m Smst->AllocatePages().
  With SmmRelocationLib, the SMRAM allocation for SMI handlers and sav= e state areas is moved to early PEI phase when the Smst->AllocatePages()= service is not available. So, the allocation is done by
  splitting the SMRAM out of the SMRAM regions reported from Guid HOB = (gEfiSmmSMramMemoryGuid).
  However, OVMF platform does not produce the GUID HOB. This patch pro= duces the HOB......

Thanks,
Ray


From: Wu, Jiaxin <jiaxin.wu@intel.com>
Sent: Wednesday, April 10, 2024 21:57
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiew= en <jiewen.yao@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; N= i, Ray <ray.ni@intel.com>
Subject: [PATCH v1 08/13] OvmfPkg/PlatformInitLib: Create gEfiS= mmSmramMemoryGuid
 
SmmRelocationLib instance will reserve the = memory from
gEfiSmmSmramMemoryGuid for the smbase relocation.

So, system must produce the gEfiSmmSmramMemoryGuid.

This patch is for the OVMF to produce the
gEfiSmmSmramMemoryGuid HOB.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 OvmfPkg/Library/PlatformInitLib/MemDetect.c    &n= bsp;   | 97 +++++++++++++---------
 .../Library/PlatformInitLib/PlatformInitLib.inf    |&n= bsp; 5 +-
 2 files changed, 64 insertions(+), 38 deletions(-)

diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c
index 7b6e5102ad..8b98256225 100644
--- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
+++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
@@ -1,9 +1,9 @@
 /**@file
   Memory Detection for Virtual Machines.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.&= lt;BR>
+  Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.&= lt;BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 Module Name:
 
   MemDetect.c
@@ -41,10 +41,12 @@ Module Name:
 #include <Library/QemuFwCfgSimpleParserLib.h>
 #include <Library/TdxLib.h>
 
 #include <Library/PlatformInitLib.h>
 
+#include <Guid/SmramMemoryReserve.h>
+
 #define MEGABYTE_SHIFT  20
 
 VOID
 EFIAPI
 PlatformQemuUc32BaseInitialization (
@@ -1027,52 +1029,73 @@ PlatformQemuInitializeRam (
   //
   // Determine total memory size available
   //
   PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob);
 
-  if (PlatformInfoHob->BootMode =3D=3D BOOT_ON_S3_RESUME) {
-    //
-    // Create the following memory HOB as an exception on t= he S3 boot path.
+  //
+  // CpuMpPei saves the original contents of the borrowed area in per= manent
+  // PEI RAM, in a backup buffer allocated with the normal PEI servic= es.
+  // CpuMpPei restores the original contents ("returns" the= borrowed area) at
+  // End-of-PEI. End-of-PEI in turn is emitted by S3Resume2Pei before=
+  // transferring control to the OS's wakeup vector in the FACS.
+  //
+  // We expect any other PEIMs that "borrow" memory similar= ly to CpuMpPei to
+  // restore the original contents. Furthermore, we expect all such P= EIMs
+  // (CpuMpPei included) to claim the borrowed areas by producing mem= ory
+  // allocation HOBs, and to honor preexistent memory allocation HOBs= when
+  // looking for an area to borrow.
+  //
+  QemuInitializeRamBelow1gb (PlatformInfoHob);
+
+  if (PlatformInfoHob->SmmSmramRequire) {
+    UINT32        &= nbsp;           &nbs= p;     TsegSize;
+    UINTN        &n= bsp;            = ;      BufferSize;
+    UINT8        &n= bsp;            = ;      SmramRanges;
+    EFI_PEI_HOB_POINTERS      = ;      Hob;
+    EFI_SMRAM_HOB_DESCRIPTOR_BLOCK  *SmramHobDescripto= rBlock;
+
+    TsegSize =3D PlatformInfoHob->Q35TsegMbytes * SIZE_1= MB;
+    PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob-&g= t;LowMemory - TsegSize);
+    PlatformAddReservedMemoryBaseSizeHob (
+      PlatformInfoHob->LowMemory - TsegSize, +      TsegSize,
+      TRUE
+      );
+
+    SmramRanges =3D 2;
+    BufferSize  =3D sizeof (EFI_SMRAM_HOB_DESCRIPTOR_B= LOCK) + (SmramRanges - 1) * sizeof (EFI_SMRAM_DESCRIPTOR);
+
+    Hob.Raw =3D BuildGuidHob (
+            &n= bsp;   &gEfiSmmSmramMemoryGuid,
+            &n= bsp;   BufferSize
+            &n= bsp;   );
+    ASSERT (Hob.Raw);
+
+    SmramHobDescriptorBlock     &n= bsp;            = ;           =3D (EFI_SMRA= M_HOB_DESCRIPTOR_BLOCK *)(Hob.Raw);
+    SmramHobDescriptorBlock->NumberOfSmmReservedRegions = =3D SmramRanges;
+
     //
-    // Normally we'd create memory HOBs only on the normal = boot path. However,
-    // CpuMpPei specifically needs such a low-memory HOB on= the S3 path as
-    // well, for "borrowing" a subset of it tempo= rarily, for the AP startup
-    // vector.
+    // Create first SMRAM descriptor, which contains data s= tructures used in S3 resume.
+    // One page is enough for the data structure
     //
-    // CpuMpPei saves the original contents of the borrowed= area in permanent
-    // PEI RAM, in a backup buffer allocated with the norma= l PEI services.
-    // CpuMpPei restores the original contents ("retur= ns" the borrowed area) at
-    // End-of-PEI. End-of-PEI in turn is emitted by S3Resum= e2Pei before
-    // transferring control to the OS's wakeup vector in th= e FACS.
+    SmramHobDescriptorBlock->Descriptor[0].PhysicalStart= =3D PlatformInfoHob->LowMemory - TsegSize;
+    SmramHobDescriptorBlock->Descriptor[0].CpuStart = ;     =3D PlatformInfoHob->LowMemory - TsegSize;
+    SmramHobDescriptorBlock->Descriptor[0].PhysicalSize&= nbsp; =3D EFI_PAGE_SIZE;
+    SmramHobDescriptorBlock->Descriptor[0].RegionState&n= bsp;  =3D EFI_SMRAM_CLOSED | EFI_CACHEABLE | EFI_ALLOCATED;
+
     //
-    // We expect any other PEIMs that "borrow" me= mory similarly to CpuMpPei to
-    // restore the original contents. Furthermore, we expec= t all such PEIMs
-    // (CpuMpPei included) to claim the borrowed areas by p= roducing memory
-    // allocation HOBs, and to honor preexistent memory all= ocation HOBs when
-    // looking for an area to borrow.
+    // Create second SMRAM descriptor, which is free and wi= ll be used by SMM foundation.
     //
-    QemuInitializeRamBelow1gb (PlatformInfoHob);
+    SmramHobDescriptorBlock->Descriptor[1].PhysicalStart= =3D SmramHobDescriptorBlock->Descriptor[0].PhysicalStart + EFI_PAGE_SIZ= E;
+    SmramHobDescriptorBlock->Descriptor[1].CpuStart = ;     =3D SmramHobDescriptorBlock->Descriptor[0].Cpu= Start + EFI_PAGE_SIZE;
+    SmramHobDescriptorBlock->Descriptor[1].PhysicalSize&= nbsp; =3D TsegSize - EFI_PAGE_SIZE;
+    SmramHobDescriptorBlock->Descriptor[1].RegionState&n= bsp;  =3D EFI_SMRAM_CLOSED | EFI_CACHEABLE;
   } else {
-    //
-    // Create memory HOBs
-    //
-    QemuInitializeRamBelow1gb (PlatformInfoHob);
-
-    if (PlatformInfoHob->SmmSmramRequire) {
-      UINT32  TsegSize;
-
-      TsegSize =3D PlatformInfoHob->Q35TsegMby= tes * SIZE_1MB;
-      PlatformAddMemoryRangeHob (BASE_1MB, Platfo= rmInfoHob->LowMemory - TsegSize);
-      PlatformAddReservedMemoryBaseSizeHob (
-        PlatformInfoHob->LowMemory -= TsegSize,
-        TsegSize,
-        TRUE
-        );
-    } else {
-      PlatformAddMemoryRangeHob (BASE_1MB, Platfo= rmInfoHob->LowMemory);
-    }
+    PlatformAddMemoryRangeHob (BASE_1MB, PlatformInfoHob-&g= t;LowMemory);
+  }
 
+  if (PlatformInfoHob->BootMode !=3D BOOT_ON_S3_RESUME) {
     //
     // If QEMU presents an E820 map, then create memor= y HOBs for the >=3D4GB RAM
     // entries. Otherwise, create a single memory HOB = with the flat >=3D4GB
     // memory size read from the CMOS.
     //
diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/= Library/PlatformInitLib/PlatformInitLib.inf
index 5a79d95b68..2bb1c0296f 100644
--- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
+++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
@@ -1,10 +1,10 @@
 ## @file
 #  Platform Initialization Lib
 #
 #  This module provides platform specific function to detect boo= t mode.
-#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.= <BR>
+#  Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.= <BR>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
 
@@ -54,10 +54,13 @@
   PeiHardwareInfoLib
 
 [LibraryClasses.X64]
   TdxLib
 
+[Guids]
+  gEfiSmmSmramMemoryGuid
+
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
   gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable
 
 [FixedPcd]
--
2.16.2.windows.1

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#117613) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB824462523C11D209058661768C052MN6PR11MB8244namp_--