* [PATCH v4 1/4] MdePkg/ProcessorBind: add defines for page allocation granularity
2017-03-03 15:11 [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity Ard Biesheuvel
@ 2017-03-03 15:11 ` Ard Biesheuvel
2017-03-03 15:11 ` [PATCH v4 2/4] MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros Ard Biesheuvel
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2017-03-03 15:11 UTC (permalink / raw)
To: edk2-devel, liming.gao, michael.d.kinney
Cc: star.zeng, jiewen.yao, Ard Biesheuvel
The UEFI spec differs between architectures in the minimum alignment
and granularity of page allocations that are visible to the OS as
EFI_MEMORY_RUNTIME regions.
So define macros that carry these values to the respective ProcessorBind.h
header files.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
MdePkg/Include/AArch64/ProcessorBind.h | 6 ++++++
MdePkg/Include/Arm/ProcessorBind.h | 6 ++++++
MdePkg/Include/Ebc/ProcessorBind.h | 6 ++++++
MdePkg/Include/Ia32/ProcessorBind.h | 6 ++++++
MdePkg/Include/Ipf/ProcessorBind.h | 6 ++++++
MdePkg/Include/X64/ProcessorBind.h | 6 ++++++
6 files changed, 36 insertions(+)
diff --git a/MdePkg/Include/AArch64/ProcessorBind.h b/MdePkg/Include/AArch64/ProcessorBind.h
index f100d96be079..775e7498c5c9 100644
--- a/MdePkg/Include/AArch64/ProcessorBind.h
+++ b/MdePkg/Include/AArch64/ProcessorBind.h
@@ -104,6 +104,12 @@ typedef INT64 INTN;
///
#define CPU_STACK_ALIGNMENT 16
+///
+/// Page allocation granularity for AARCH64
+///
+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000)
+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x10000)
+
//
// Modifier to ensure that all protocol member functions and EFI intrinsics
// use the correct C calling convention. All protocol member functions and
diff --git a/MdePkg/Include/Arm/ProcessorBind.h b/MdePkg/Include/Arm/ProcessorBind.h
index a543687e57fd..dde1fd1152ba 100644
--- a/MdePkg/Include/Arm/ProcessorBind.h
+++ b/MdePkg/Include/Arm/ProcessorBind.h
@@ -110,6 +110,12 @@ typedef INT32 INTN;
///
#define CPU_STACK_ALIGNMENT sizeof(UINT64)
+///
+/// Page allocation granularity for ARM
+///
+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000)
+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x1000)
+
//
// Modifier to ensure that all protocol member functions and EFI intrinsics
// use the correct C calling convention. All protocol member functions and
diff --git a/MdePkg/Include/Ebc/ProcessorBind.h b/MdePkg/Include/Ebc/ProcessorBind.h
index 075f768c7691..da8b1a6d802a 100644
--- a/MdePkg/Include/Ebc/ProcessorBind.h
+++ b/MdePkg/Include/Ebc/ProcessorBind.h
@@ -115,6 +115,12 @@ typedef unsigned long UINTN;
#define CPU_STACK_ALIGNMENT sizeof(UINTN)
///
+/// Page allocation granularity for EBC
+///
+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000)
+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x1000)
+
+///
/// Modifier to ensure that all protocol member functions and EFI intrinsics
/// use the correct C calling convention. All protocol member functions and
/// EFI intrinsics are required to modify their member functions with EFIAPI.
diff --git a/MdePkg/Include/Ia32/ProcessorBind.h b/MdePkg/Include/Ia32/ProcessorBind.h
index 086b1ff7b1b3..8ba2348261a2 100644
--- a/MdePkg/Include/Ia32/ProcessorBind.h
+++ b/MdePkg/Include/Ia32/ProcessorBind.h
@@ -257,6 +257,12 @@ typedef INT32 INTN;
///
#define CPU_STACK_ALIGNMENT sizeof(UINTN)
+///
+/// Page allocation granularity for IA-32.
+///
+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000)
+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x1000)
+
//
// Modifier to ensure that all protocol member functions and EFI intrinsics
// use the correct C calling convention. All protocol member functions and
diff --git a/MdePkg/Include/Ipf/ProcessorBind.h b/MdePkg/Include/Ipf/ProcessorBind.h
index c19e47d8f3ca..51885ca61359 100644
--- a/MdePkg/Include/Ipf/ProcessorBind.h
+++ b/MdePkg/Include/Ipf/ProcessorBind.h
@@ -248,6 +248,12 @@ typedef INT64 INTN;
///
#define CPU_STACK_ALIGNMENT 16
+///
+/// Page allocation granularity for Itanium
+///
+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000)
+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x2000)
+
//
// Modifier to ensure that all protocol member functions and EFI intrinsics
// use the correct C calling convention. All protocol member functions and
diff --git a/MdePkg/Include/X64/ProcessorBind.h b/MdePkg/Include/X64/ProcessorBind.h
index 23e6e55abff6..72cc85151cba 100644
--- a/MdePkg/Include/X64/ProcessorBind.h
+++ b/MdePkg/Include/X64/ProcessorBind.h
@@ -271,6 +271,12 @@ typedef INT64 INTN;
///
#define CPU_STACK_ALIGNMENT 16
+///
+/// Page allocation granularity for x64
+///
+#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (0x1000)
+#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (0x1000)
+
//
// Modifier to ensure that all protocol member functions and EFI intrinsics
// use the correct C calling convention. All protocol member functions and
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 2/4] MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros
2017-03-03 15:11 [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity Ard Biesheuvel
2017-03-03 15:11 ` [PATCH v4 1/4] MdePkg/ProcessorBind: add defines for " Ard Biesheuvel
@ 2017-03-03 15:11 ` Ard Biesheuvel
2017-03-03 15:11 ` [PATCH v4 3/4] MdeModulePkg/PiSmmCore: " Ard Biesheuvel
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2017-03-03 15:11 UTC (permalink / raw)
To: edk2-devel, liming.gao, michael.d.kinney
Cc: star.zeng, jiewen.yao, Ard Biesheuvel
Remove the local definitions for the default and runtime page allocation
granularity macros, and switch to the new MdePkg versions.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
MdeModulePkg/Core/Dxe/DxeMain.h | 25 --------------------
MdeModulePkg/Core/Dxe/Mem/Page.c | 22 ++++++++---------
MdeModulePkg/Core/Dxe/Mem/Pool.c | 8 +++----
MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 2 +-
MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 4 ++--
MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 8 +++----
6 files changed, 22 insertions(+), 47 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h
index 5668c1f2d648..1a0babba713a 100644
--- a/MdeModulePkg/Core/Dxe/DxeMain.h
+++ b/MdeModulePkg/Core/Dxe/DxeMain.h
@@ -123,31 +123,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
///
#define DEPEX_STACK_SIZE_INCREMENT 0x1000
-#if defined (MDE_CPU_IPF)
-///
-/// For Itanium machines make the default allocations 8K aligned
-///
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE * 2)
-#define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE * 2)
-
-#elif defined (MDE_CPU_AARCH64)
-///
-/// 64-bit ARM systems allow the OS to execute with 64 KB page size,
-/// so for improved interoperability with the firmware, align the
-/// runtime regions to 64 KB as well
-///
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB)
-#define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)
-
-#else
-///
-/// For generic EFI machines make the default allocations 4K aligned
-///
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE)
-#define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)
-
-#endif
-
typedef struct {
EFI_GUID *ProtocolGuid;
VOID **Protocol;
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index 7e8fa94d7d4f..260a30a214c7 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -15,8 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "DxeMain.h"
#include "Imem.h"
-#define EFI_DEFAULT_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE)
-
//
// Entry for tracking the memory regions for each memory type to coalesce similar memory types
//
@@ -287,12 +285,14 @@ AllocateMemoryMapEntry (
//
// The list is empty, to allocate one page to refuel the list
//
- FreeDescriptorEntries = CoreAllocatePoolPages (EfiBootServicesData, EFI_SIZE_TO_PAGES(DEFAULT_PAGE_ALLOCATION), DEFAULT_PAGE_ALLOCATION);
- if(FreeDescriptorEntries != NULL) {
+ FreeDescriptorEntries = CoreAllocatePoolPages (EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (DEFAULT_PAGE_ALLOCATION_GRANULARITY),
+ DEFAULT_PAGE_ALLOCATION_GRANULARITY);
+ if (FreeDescriptorEntries != NULL) {
//
// Enque the free memmory map entries into the list
//
- for (Index = 0; Index< DEFAULT_PAGE_ALLOCATION / sizeof(MEMORY_MAP); Index++) {
+ for (Index = 0; Index < DEFAULT_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
}
@@ -1222,14 +1222,14 @@ CoreInternalAllocatePages (
return EFI_INVALID_PARAMETER;
}
- Alignment = EFI_DEFAULT_PAGE_ALLOCATION_ALIGNMENT;
+ Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
if (MemoryType == EfiACPIReclaimMemory ||
MemoryType == EfiACPIMemoryNVS ||
MemoryType == EfiRuntimeServicesCode ||
MemoryType == EfiRuntimeServicesData) {
- Alignment = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
+ Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
}
if (Type == AllocateAddress) {
@@ -1398,7 +1398,7 @@ CoreInternalFreePages (
goto Done;
}
- Alignment = EFI_DEFAULT_PAGE_ALLOCATION_ALIGNMENT;
+ Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
ASSERT (Entry != NULL);
if (Entry->Type == EfiACPIReclaimMemory ||
@@ -1406,7 +1406,7 @@ CoreInternalFreePages (
Entry->Type == EfiRuntimeServicesCode ||
Entry->Type == EfiRuntimeServicesData) {
- Alignment = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
+ Alignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
}
@@ -1925,12 +1925,12 @@ CoreTerminateMemoryMap (
if (mMemoryTypeStatistics[Entry->Type].Runtime) {
ASSERT (Entry->Type != EfiACPIReclaimMemory);
ASSERT (Entry->Type != EfiACPIMemoryNVS);
- if ((Entry->Start & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {
+ if ((Entry->Start & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
- if (((Entry->End + 1) & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {
+ if (((Entry->End + 1) & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
DEBUG((DEBUG_ERROR | DEBUG_PAGE, "ExitBootServices: A RUNTIME memory entry is not on a proper alignment.\n"));
Status = EFI_INVALID_PARAMETER;
goto Done;
diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c
index ced64443c77d..5248ee2e6c02 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Pool.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c
@@ -352,9 +352,9 @@ CoreAllocatePoolI (
PoolType == EfiRuntimeServicesCode ||
PoolType == EfiRuntimeServicesData) {
- Granularity = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
+ Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
- Granularity = DEFAULT_PAGE_ALLOCATION;
+ Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
}
//
@@ -643,9 +643,9 @@ CoreFreePoolI (
Head->Type == EfiRuntimeServicesCode ||
Head->Type == EfiRuntimeServicesData) {
- Granularity = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
+ Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
} else {
- Granularity = DEFAULT_PAGE_ALLOCATION;
+ Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
}
if (PoolType != NULL) {
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
index 408bcd3527ee..35156aea14dd 100644
--- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
+++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c
@@ -104,7 +104,7 @@ InstallMemoryAttributesTable (
if ((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) == 0) {
DEBUG ((EFI_D_VERBOSE, "MemoryProtectionAttribute NON_EXECUTABLE_PE_DATA is not set, "));
- DEBUG ((EFI_D_VERBOSE, "because Runtime Driver Section Alignment is not %dK.\n", EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10));
+ DEBUG ((EFI_D_VERBOSE, "because Runtime Driver Section Alignment is not %dK.\n", RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));
return ;
}
diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
index 45f360cccf75..070228bc7265 100644
--- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
+++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
@@ -344,12 +344,12 @@ IsMemoryProtectionSectionAligned (
switch (MemoryType) {
case EfiRuntimeServicesCode:
case EfiACPIMemoryNVS:
- PageAlignment = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
+ PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
break;
case EfiRuntimeServicesData:
case EfiACPIReclaimMemory:
ASSERT (FALSE);
- PageAlignment = EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT;
+ PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
break;
case EfiBootServicesCode:
case EfiLoaderCode:
diff --git a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c
index 5ea20dbf8972..e7c4a9571250 100644
--- a/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c
+++ b/MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c
@@ -804,7 +804,7 @@ SetPropertiesTableSectionAlignment (
IN UINT32 SectionAlignment
)
{
- if (((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) &&
+ if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) &&
((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) {
DEBUG ((EFI_D_VERBOSE, "SetPropertiesTableSectionAlignment - Clear\n"));
mPropertiesTable.MemoryProtectionAttribute &= ~((UINT64)EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA);
@@ -1136,9 +1136,9 @@ InsertImageRecord (
}
SetPropertiesTableSectionAlignment (SectionAlignment);
- if ((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {
+ if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
DEBUG ((EFI_D_WARN, "!!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",
- SectionAlignment, EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10));
+ SectionAlignment, RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((EFI_D_WARN, "!!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
@@ -1338,7 +1338,7 @@ InstallPropertiesTable (
DEBUG ((EFI_D_INFO, "MemoryProtectionAttribute - 0x%016lx\n", mPropertiesTable.MemoryProtectionAttribute));
if ((mPropertiesTable.MemoryProtectionAttribute & EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) == 0) {
DEBUG ((EFI_D_ERROR, "MemoryProtectionAttribute NON_EXECUTABLE_PE_DATA is not set, "));
- DEBUG ((EFI_D_ERROR, "because Runtime Driver Section Alignment is not %dK.\n", EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10));
+ DEBUG ((EFI_D_ERROR, "because Runtime Driver Section Alignment is not %dK.\n", RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));
return ;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 3/4] MdeModulePkg/PiSmmCore: switch to MdePkg allocation granularity macros
2017-03-03 15:11 [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity Ard Biesheuvel
2017-03-03 15:11 ` [PATCH v4 1/4] MdePkg/ProcessorBind: add defines for " Ard Biesheuvel
2017-03-03 15:11 ` [PATCH v4 2/4] MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros Ard Biesheuvel
@ 2017-03-03 15:11 ` Ard Biesheuvel
2017-03-03 15:11 ` [PATCH v4 4/4] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity Ard Biesheuvel
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2017-03-03 15:11 UTC (permalink / raw)
To: edk2-devel, liming.gao, michael.d.kinney
Cc: star.zeng, jiewen.yao, Ard Biesheuvel
Remove the local definitions for the default and runtime page allocation
granularity macros, and switch to the new MdePkg versions.
Note that this replaces a reference to the 'default' version with the
more correct 'runtime' version, but this matters little in practice.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c | 6 +++---
MdeModulePkg/Core/PiSmmCore/Page.c | 4 ++--
MdeModulePkg/Core/PiSmmCore/PiSmmCore.h | 6 ------
3 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
index 6cfd35945ab1..e3c505ef18ab 100644
--- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
+++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c
@@ -795,7 +795,7 @@ SetMemoryAttributesTableSectionAlignment (
IN UINT32 SectionAlignment
)
{
- if (((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) &&
+ if (((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) &&
((mMemoryProtectionAttribute & EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA) != 0)) {
DEBUG ((DEBUG_VERBOSE, "SMM SetMemoryAttributesTableSectionAlignment - Clear\n"));
mMemoryProtectionAttribute &= ~((UINT64)EFI_MEMORY_ATTRIBUTES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA);
@@ -1125,9 +1125,9 @@ SmmInsertImageRecord (
}
SetMemoryAttributesTableSectionAlignment (SectionAlignment);
- if ((SectionAlignment & (EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT - 1)) != 0) {
+ if ((SectionAlignment & (RUNTIME_PAGE_ALLOCATION_GRANULARITY - 1)) != 0) {
DEBUG ((DEBUG_WARN, "SMM !!!!!!!! InsertImageRecord - Section Alignment(0x%x) is not %dK !!!!!!!!\n",
- SectionAlignment, EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT >> 10));
+ SectionAlignment, RUNTIME_PAGE_ALLOCATION_GRANULARITY >> 10));
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageAddress);
if (PdbPointer != NULL) {
DEBUG ((DEBUG_WARN, "SMM !!!!!!!! Image - %a !!!!!!!!\n", PdbPointer));
diff --git a/MdeModulePkg/Core/PiSmmCore/Page.c b/MdeModulePkg/Core/PiSmmCore/Page.c
index 1bc8fd82c867..4154c2e6a1ec 100644
--- a/MdeModulePkg/Core/PiSmmCore/Page.c
+++ b/MdeModulePkg/Core/PiSmmCore/Page.c
@@ -110,7 +110,7 @@ AllocateMemoryMapEntry (
Status = SmmInternalAllocatePagesEx (
AllocateAnyPages,
EfiRuntimeServicesData,
- EFI_SIZE_TO_PAGES(DEFAULT_PAGE_ALLOCATION),
+ EFI_SIZE_TO_PAGES (RUNTIME_PAGE_ALLOCATION_GRANULARITY),
&Mem,
TRUE
);
@@ -121,7 +121,7 @@ AllocateMemoryMapEntry (
//
// Enque the free memmory map entries into the list
//
- for (Index = 0; Index< DEFAULT_PAGE_ALLOCATION / sizeof(MEMORY_MAP); Index++) {
+ for (Index = 0; Index< RUNTIME_PAGE_ALLOCATION_GRANULARITY / sizeof(MEMORY_MAP); Index++) {
FreeDescriptorEntries[Index].Signature = MEMORY_MAP_SIGNATURE;
InsertTailList (&mFreeMemoryMapEntryList, &FreeDescriptorEntries[Index].Link);
}
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
index bdef026e6c68..45b9d9758be8 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.h
@@ -1151,12 +1151,6 @@ SmiHandlerProfileUnregisterHandler (
IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler
);
-///
-/// For generic EFI machines make the default allocations 4K aligned
-///
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE)
-#define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE)
-
extern UINTN mFullSmramRangeCount;
extern EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 4/4] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity
2017-03-03 15:11 [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity Ard Biesheuvel
` (2 preceding siblings ...)
2017-03-03 15:11 ` [PATCH v4 3/4] MdeModulePkg/PiSmmCore: " Ard Biesheuvel
@ 2017-03-03 15:11 ` Ard Biesheuvel
2017-03-03 15:31 ` [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page " Yao, Jiewen
2017-03-06 2:33 ` Gao, Liming
5 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2017-03-03 15:11 UTC (permalink / raw)
To: edk2-devel, liming.gao, michael.d.kinney
Cc: star.zeng, jiewen.yao, Ard Biesheuvel
Architectures such as AArch64 may run the OS with 16 KB or 64 KB sized
pages, and for this reason, the UEFI spec mandates a minimal allocation
granularity of 64 KB for regions that may require different memory
attributes at OS runtime.
So make PeiCore's implementation of AllocatePages () take this into
account as well.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
---
MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 39 +++++++++++++++++++-
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
index 4efe14313ca5..719372e06128 100644
--- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
+++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
@@ -140,6 +140,8 @@ PeiAllocatePages (
EFI_PHYSICAL_ADDRESS *FreeMemoryTop;
EFI_PHYSICAL_ADDRESS *FreeMemoryBottom;
UINTN RemainingPages;
+ UINTN Granularity;
+ UINTN Padding;
if ((MemoryType != EfiLoaderCode) &&
(MemoryType != EfiLoaderData) &&
@@ -153,6 +155,20 @@ PeiAllocatePages (
return EFI_INVALID_PARAMETER;
}
+ Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY;
+
+ if (RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY &&
+ (MemoryType == EfiACPIReclaimMemory ||
+ MemoryType == EfiACPIMemoryNVS ||
+ MemoryType == EfiRuntimeServicesCode ||
+ MemoryType == EfiRuntimeServicesData)) {
+
+ Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;
+
+ DEBUG ((DEBUG_INFO, "AllocatePages: aligning allocation to %d KB\n",
+ Granularity / SIZE_1KB));
+ }
+
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
Hob.Raw = PrivateData->HobList.Raw;
@@ -176,9 +192,27 @@ PeiAllocatePages (
}
//
- // Check to see if on 4k boundary, If not aligned, make the allocation aligned.
+ // Check to see if on correct boundary for the memory type.
+ // If not aligned, make the allocation aligned.
//
- *(FreeMemoryTop) -= *(FreeMemoryTop) & 0xFFF;
+ Padding = *(FreeMemoryTop) & (Granularity - 1);
+ if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < Padding) {
+ DEBUG ((DEBUG_ERROR, "AllocatePages failed: Out of space after padding.\n"));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ *(FreeMemoryTop) -= Padding;
+ if (Padding >= EFI_PAGE_SIZE) {
+ //
+ // Create a memory allocation HOB to cover
+ // the pages that we will lose to rounding
+ //
+ BuildMemoryAllocationHob (
+ *(FreeMemoryTop),
+ Padding & ~(UINTN)EFI_PAGE_MASK,
+ EfiConventionalMemory
+ );
+ }
//
// Verify that there is sufficient memory to satisfy the allocation.
@@ -192,6 +226,7 @@ PeiAllocatePages (
//
// The number of remaining pages needs to be greater than or equal to that of the request pages.
//
+ Pages = ALIGN_VALUE (Pages, EFI_SIZE_TO_PAGES (Granularity));
if (RemainingPages < Pages) {
DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));
DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity
2017-03-03 15:11 [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity Ard Biesheuvel
` (3 preceding siblings ...)
2017-03-03 15:11 ` [PATCH v4 4/4] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity Ard Biesheuvel
@ 2017-03-03 15:31 ` Yao, Jiewen
2017-03-06 2:33 ` Gao, Liming
5 siblings, 0 replies; 8+ messages in thread
From: Yao, Jiewen @ 2017-03-03 15:31 UTC (permalink / raw)
To: Ard Biesheuvel, edk2-devel@lists.01.org, Gao, Liming,
Kinney, Michael D
Cc: Zeng, Star
Thank you.
All reviewed-by: Jiewen.yao@intel.com
> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Friday, March 3, 2017 11:12 PM
> To: edk2-devel@lists.01.org; Gao, Liming <liming.gao@intel.com>; Kinney,
> Michael D <michael.d.kinney@intel.com>
> Cc: Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Ard
> Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation
> granularity
>
> This is now a 4-piece series, so that the allocation granularity used by
> PEI core, which is defined per-architecture in the UEFI spec, is not defined
> locally but centrally for all modules in all phases.
>
> Ard Biesheuvel (4):
> MdePkg/ProcessorBind: add defines for page allocation granularity
> MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros
> MdeModulePkg/PiSmmCore: switch to MdePkg allocation granularity macros
> MdeModulePkg/PeiCore: honour minimal runtime allocation granularity
>
> MdeModulePkg/Core/Dxe/DxeMain.h | 25 -------------
> MdeModulePkg/Core/Dxe/Mem/Page.c | 22 +++++------
> MdeModulePkg/Core/Dxe/Mem/Pool.c | 8 ++--
> MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 2 +-
> MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 4 +-
> MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 8 ++--
> MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 39
> +++++++++++++++++++-
> MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c | 6 +--
> MdeModulePkg/Core/PiSmmCore/Page.c | 4 +-
> MdeModulePkg/Core/PiSmmCore/PiSmmCore.h | 6 ---
> MdePkg/Include/AArch64/ProcessorBind.h | 6 +++
> MdePkg/Include/Arm/ProcessorBind.h | 6 +++
> MdePkg/Include/Ebc/ProcessorBind.h | 6 +++
> MdePkg/Include/Ia32/ProcessorBind.h | 6 +++
> MdePkg/Include/Ipf/ProcessorBind.h | 6 +++
> MdePkg/Include/X64/ProcessorBind.h | 6 +++
> 16 files changed, 100 insertions(+), 60 deletions(-)
>
> --
> 2.7.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity
2017-03-03 15:11 [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity Ard Biesheuvel
` (4 preceding siblings ...)
2017-03-03 15:31 ` [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page " Yao, Jiewen
@ 2017-03-06 2:33 ` Gao, Liming
2017-03-06 15:14 ` Ard Biesheuvel
5 siblings, 1 reply; 8+ messages in thread
From: Gao, Liming @ 2017-03-06 2:33 UTC (permalink / raw)
To: Ard Biesheuvel, edk2-devel@lists.01.org, Kinney, Michael D
Cc: Zeng, Star, Yao, Jiewen
Reviewed-by: Liming Gao <liming.gao@intel.com>
>-----Original Message-----
>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
>Sent: Friday, March 03, 2017 11:12 PM
>To: edk2-devel@lists.01.org; Gao, Liming <liming.gao@intel.com>; Kinney,
>Michael D <michael.d.kinney@intel.com>
>Cc: Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>;
>Ard Biesheuvel <ard.biesheuvel@linaro.org>
>Subject: [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation
>granularity
>
>This is now a 4-piece series, so that the allocation granularity used by
>PEI core, which is defined per-architecture in the UEFI spec, is not defined
>locally but centrally for all modules in all phases.
>
>Ard Biesheuvel (4):
> MdePkg/ProcessorBind: add defines for page allocation granularity
> MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros
> MdeModulePkg/PiSmmCore: switch to MdePkg allocation granularity macros
> MdeModulePkg/PeiCore: honour minimal runtime allocation granularity
>
> MdeModulePkg/Core/Dxe/DxeMain.h | 25 -------------
> MdeModulePkg/Core/Dxe/Mem/Page.c | 22 +++++------
> MdeModulePkg/Core/Dxe/Mem/Pool.c | 8 ++--
> MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 2 +-
> MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 4 +-
> MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 8 ++--
> MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 39
>+++++++++++++++++++-
> MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c | 6 +--
> MdeModulePkg/Core/PiSmmCore/Page.c | 4 +-
> MdeModulePkg/Core/PiSmmCore/PiSmmCore.h | 6 ---
> MdePkg/Include/AArch64/ProcessorBind.h | 6 +++
> MdePkg/Include/Arm/ProcessorBind.h | 6 +++
> MdePkg/Include/Ebc/ProcessorBind.h | 6 +++
> MdePkg/Include/Ia32/ProcessorBind.h | 6 +++
> MdePkg/Include/Ipf/ProcessorBind.h | 6 +++
> MdePkg/Include/X64/ProcessorBind.h | 6 +++
> 16 files changed, 100 insertions(+), 60 deletions(-)
>
>--
>2.7.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation granularity
2017-03-06 2:33 ` Gao, Liming
@ 2017-03-06 15:14 ` Ard Biesheuvel
0 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2017-03-06 15:14 UTC (permalink / raw)
To: Gao, Liming
Cc: edk2-devel@lists.01.org, Kinney, Michael D, Zeng, Star,
Yao, Jiewen
On 6 March 2017 at 03:33, Gao, Liming <liming.gao@intel.com> wrote:
> Reviewed-by: Liming Gao <liming.gao@intel.com>
>
Thanks all. Pushed to master
>>-----Original Message-----
>>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
>>Sent: Friday, March 03, 2017 11:12 PM
>>To: edk2-devel@lists.01.org; Gao, Liming <liming.gao@intel.com>; Kinney,
>>Michael D <michael.d.kinney@intel.com>
>>Cc: Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>;
>>Ard Biesheuvel <ard.biesheuvel@linaro.org>
>>Subject: [PATCH v4 0/4] MdePkg, MdeModulePkg: Enforce page allocation
>>granularity
>>
>>This is now a 4-piece series, so that the allocation granularity used by
>>PEI core, which is defined per-architecture in the UEFI spec, is not defined
>>locally but centrally for all modules in all phases.
>>
>>Ard Biesheuvel (4):
>> MdePkg/ProcessorBind: add defines for page allocation granularity
>> MdeModulePkg/DxeCore: switch to MdePkg allocation granularity macros
>> MdeModulePkg/PiSmmCore: switch to MdePkg allocation granularity macros
>> MdeModulePkg/PeiCore: honour minimal runtime allocation granularity
>>
>> MdeModulePkg/Core/Dxe/DxeMain.h | 25 -------------
>> MdeModulePkg/Core/Dxe/Mem/Page.c | 22 +++++------
>> MdeModulePkg/Core/Dxe/Mem/Pool.c | 8 ++--
>> MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c | 2 +-
>> MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 4 +-
>> MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 8 ++--
>> MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 39
>>+++++++++++++++++++-
>> MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c | 6 +--
>> MdeModulePkg/Core/PiSmmCore/Page.c | 4 +-
>> MdeModulePkg/Core/PiSmmCore/PiSmmCore.h | 6 ---
>> MdePkg/Include/AArch64/ProcessorBind.h | 6 +++
>> MdePkg/Include/Arm/ProcessorBind.h | 6 +++
>> MdePkg/Include/Ebc/ProcessorBind.h | 6 +++
>> MdePkg/Include/Ia32/ProcessorBind.h | 6 +++
>> MdePkg/Include/Ipf/ProcessorBind.h | 6 +++
>> MdePkg/Include/X64/ProcessorBind.h | 6 +++
>> 16 files changed, 100 insertions(+), 60 deletions(-)
>>
>>--
>>2.7.4
>
^ permalink raw reply [flat|nested] 8+ messages in thread