From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by mx.groups.io with SMTP id smtpd.web08.126.1663965314957224800 for ; Fri, 23 Sep 2022 13:35:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=SFym/5fK; spf=pass (domain: flex--dionnaglaze.bounces.google.com, ip: 209.85.219.202, mailfrom: 3ghguywskbyssx322pv0petv33v0t.r31stat0tszh.v63947.x3@flex--dionnaglaze.bounces.google.com) Received: by mail-yb1-f202.google.com with SMTP id n6-20020a5b0486000000b006aff8dc9865so780954ybp.11 for ; Fri, 23 Sep 2022 13:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=0gmyvadZeVtm1boJ+a1ElPZyhKNE0aixn+xW/+d5W2U=; b=SFym/5fKY5hHA8utdmXpyOMYXLROd6As8BsNU06eoiK6KzoZGeY8kNcEfY2l+NUr7X Dkn7J+vy8iJm0Nks31T8SFp6usu82KbjcbInFITczmxUBjVOVC6/lUqxcYEsk3ur5VnA MJRZ+p2ONn5vPWkNO53AlWOrDnnNNA3R/CIoC4WIzDjPs/1HpGAtEyD3BGjvHw4LdEdx Uc8JJb/lwF91pQ9r4jjUj38n4o97hB19OM3B7eNmxPdsCw05eUw+YuHinvT5jTGH4smh uZNvON2it1CB2vuI4MEk+vmYEXTmHbZjTQ32drf5uFzpTk4162W04SHyn2pFqhtJXWUR ufzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=0gmyvadZeVtm1boJ+a1ElPZyhKNE0aixn+xW/+d5W2U=; b=iE6rV2I2PuxfZHpAJjU3xbO8FBeb9bXXHsH4ab4fgt9vEKI/8zXayUJIE/zbR+9AXz vUVcJWa+zxCPx6OcwfKg3svtLN2U032gohVSrBTX8SE1dYEeAg+Z4rRER8jnI+FAWEUG n1kXMbFNdUoTXnlXKrNBjcYuBQfdQIQ6369ZIayweTNGGCW6hB6Wc5F9cQiil8wcKSOf FalL7pDY3ZiUdwDIXjRBPO/AoNFPKLa2i8urwMhlsKXHQhJZ4ZI12X5iUZ1UK2LGCkAB oGlTplutZCs2r153+GFAw69D2c7TjfmO5Kig+26cKQobNf1rHiBmVkXuBtrrOiwEnrkG JOgQ== X-Gm-Message-State: ACrzQf2dKe1gR29oAXj7Y4HbaBKIy0hoNo5S2m3YrD2utXMv4A+yGBzi hW4JLD3Nx20cwy2iu0CAZMXhC+caAR/j3hv71L9lCUFHtizEq/yyMT5VXmrRLBzQZc3GF++3Xnu U9MGxmcnWlkAqvGbf0RNLSGbucX3+wJ37ckfH39DlV8ijZVnwz7m3jqvkxGj/Nqt0fKXpZOYy X-Google-Smtp-Source: AMsMyM79Zfb5GZn9toiG04MVcpSCNUnMeLcy0dgJNbS83nZ3VLJH8BmD1+AOE7/GAvOvFSDyIOlgQKmdT0O6tLxDYw== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a0d:fcc3:0:b0:341:5d51:3fcc with SMTP id m186-20020a0dfcc3000000b003415d513fccmr10341554ywf.340.1663965314098; Fri, 23 Sep 2022 13:35:14 -0700 (PDT) Date: Fri, 23 Sep 2022 20:34:30 +0000 In-Reply-To: <20220923203431.1428535-1-dionnaglaze@google.com> Mime-Version: 1.0 References: <20220923203431.1428535-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog Message-ID: <20220923203431.1428535-4-dionnaglaze@google.com> Subject: [PATCHv2 3/4] MdeModulePkg: add EnableUnacceptedMemoryProtocol From: "Dionna Glaze" To: devel@edk2.groups.io Cc: Dionna Glaze , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky , Ard Biesheuvel Content-Type: text/plain; charset="UTF-8" Add a simple protocol that enables the use of the unaccepted memory type. Must be called before ExitBootServices to be effective. Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Ard Biesheuvel Signed-off-by: Dionna Glaze --- MdeModulePkg/Core/Dxe/DxeMain.h | 22 ++++++++++++++++ MdeModulePkg/Core/Dxe/DxeMain.inf | 3 ++- MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 5 ++++ MdeModulePkg/Core/Dxe/Mem/Page.c | 35 +++++++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 3 +++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index ac943c87a3..5f0114b04f 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -2708,6 +2708,28 @@ CoreResolveUnacceptedMemory ( VOID ); + +typedef struct _ENABLE_UNACCEPTED_MEMORY_PROTOCOL + ENABLE_UNACCEPTED_MEMORY_PROTOCOL; + +typedef EFI_STATUS (EFIAPI *ENABLE_UNACCEPTED_MEMORY)( + IN ENABLE_UNACCEPTED_MEMORY_PROTOCOL * + ); + +struct _ENABLE_UNACCEPTED_MEMORY_PROTOCOL { + ENABLE_UNACCEPTED_MEMORY Enable; +}; + +extern EFI_GUID gEnableUnacceptedMemoryProtocolGuid; + +/** + Implement the protocol for enabling unaccepted memory. + **/ +VOID +InstallEnableUnacceptedMemoryProtocol ( + VOID + ); + /** Install MemoryAttributesTable on memory allocation. diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeMain.inf index deb8bb2ba8..39dcac98bb 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -122,6 +122,7 @@ gEfiMemoryAttributesTableGuid ## SOMETIMES_PRODUCES ## SystemTable gEfiEndOfDxeEventGroupGuid ## SOMETIMES_CONSUMES ## Event gEfiHobMemoryAllocStackGuid ## SOMETIMES_CONSUMES ## SystemTable + gEnableUnacceptedMemoryProtocolGuid ## PRODUCES ## GUID # Install protocol [Ppis] gEfiVectorHandoffInfoPpiGuid ## UNDEFINED # HOB @@ -187,7 +188,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdFwVolDxeMaxEncapsulationDepth ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdEnableUnacceptedMemory ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableUnacceptedMemory ## CONSUMES ## SOMETIMES_PRODUCES # [Hob] # RESOURCE_DESCRIPTOR ## CONSUMES diff --git a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c index 8d1de32fe7..bc1a8ab6b2 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -354,6 +354,11 @@ DxeMain ( Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation); ASSERT_EFI_ERROR (Status); + // + // Install unaccepted memory configuration protocol + // + InstallEnableUnacceptedMemoryProtocol(); + // // If Loading modules At fixed address feature is enabled, install Load moduels at fixed address // Configuration Table so that user could easily to retrieve the top address to load Dxe and PEI diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index cbebe62a28..10e152d80d 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -96,6 +96,14 @@ EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = { // GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN gLoadFixedAddressCodeMemoryReady = FALSE; +EFI_STATUS EFIAPI CoreEnableUnacceptedMemory(IN ENABLE_UNACCEPTED_MEMORY_PROTOCOL *); + +struct { + ENABLE_UNACCEPTED_MEMORY enable; +} mEnableUnacceptedMemoryProtocol = { + CoreEnableUnacceptedMemory, +}; + /** Enter critical section by gaining lock on gMemoryLock. @@ -2205,6 +2213,33 @@ CoreResolveUnacceptedMemory ( return AcceptAllUnacceptedMemory(AcceptMemory); } +EFI_STATUS +EFIAPI +CoreEnableUnacceptedMemory ( + IN ENABLE_UNACCEPTED_MEMORY_PROTOCOL *This + ) +{ + return PcdSetBoolS(PcdEnableUnacceptedMemory, TRUE); +} + +VOID +InstallEnableUnacceptedMemoryProtocol ( + VOID + ) +{ + EFI_HANDLE Handle; + EFI_STATUS Status; + + Handle = NULL; + Status = CoreInstallMultipleProtocolInterfaces ( + &Handle, + &gEnableUnacceptedMemoryProtocolGuid, + &mEnableUnacceptedMemoryProtocol, + NULL + ); + ASSERT_EFI_ERROR (Status); +} + /** Make sure the memory map is following all the construction rules, it is the last time to check memory map error before exit boot services. diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index dd07b3725a..ce72c06a93 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -244,6 +244,9 @@ gEdkiiPerformanceMeasurementProtocolGuid = { 0xc85d06be, 0x5f75, 0x48ce, { 0xa8, 0x0f, 0x12, 0x36, 0xba, 0x3b, 0x87, 0xb1 } } gEdkiiSmmPerformanceMeasurementProtocolGuid = { 0xd56b6d73, 0x1a7b, 0x4015, { 0x9b, 0xb4, 0x7b, 0x07, 0x17, 0x29, 0xed, 0x24 } } + ## Bootloader protocol Guid for enabling unaccepted memory support. + gEnableUnacceptedMemoryProtocolGuid = { 0xc5a010fe, 0x38a7, 0x4531, { 0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49 } } + ## Guid is defined for CRC32 encapsulation scheme. # Include/Guid/Crc32GuidedSectionExtraction.h gEfiCrc32GuidedSectionExtractionGuid = { 0xFC1BCDB0, 0x7D31, 0x49aa, {0x93, 0x6A, 0xA4, 0x60, 0x0D, 0x9D, 0xD0, 0x83 } } -- 2.37.3.998.g577e59143f-goog