]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuDxe.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuDxe.c
index 8ddebabd02eaa2b3a02833717679ee69858f42e5..7d7270e10b4aed9a4be5321ff4678516e06bd95d 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   CPU DXE Module to produce CPU ARCH Protocol.\r
 \r
-  Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -25,6 +19,7 @@
 BOOLEAN                   InterruptState = FALSE;\r
 EFI_HANDLE                mCpuHandle = NULL;\r
 BOOLEAN                   mIsFlushingGCD;\r
+BOOLEAN                   mIsAllocatingPageTable = FALSE;\r
 UINT64                    mValidMtrrAddressMask;\r
 UINT64                    mValidMtrrBitsMask;\r
 UINT64                    mTimerPeriod = 0;\r
@@ -403,10 +398,24 @@ CpuSetMemoryAttributes (
   // to avoid unnecessary computing.\r
   //\r
   if (mIsFlushingGCD) {\r
-    DEBUG((DEBUG_INFO, "  Flushing GCD\n"));\r
+    DEBUG((DEBUG_VERBOSE, "  Flushing GCD\n"));\r
     return EFI_SUCCESS;\r
   }\r
 \r
+  //\r
+  // During memory attributes updating, new pages may be allocated to setup\r
+  // smaller granularity of page table. Page allocation action might then cause\r
+  // another calling of CpuSetMemoryAttributes() recursively, due to memory\r
+  // protection policy configured (such as PcdDxeNxMemoryProtectionPolicy).\r
+  // Since this driver will always protect memory used as page table by itself,\r
+  // there's no need to apply protection policy requested from memory service.\r
+  // So it's safe to just return EFI_SUCCESS if this time of calling is caused\r
+  // by page table memory allocation.\r
+  //\r
+  if (mIsAllocatingPageTable) {\r
+    DEBUG((DEBUG_VERBOSE, "  Allocating page table memory\n"));\r
+    return EFI_SUCCESS;\r
+  }\r
 \r
   CacheAttributes = Attributes & CACHE_ATTRIBUTE_MASK;\r
   MemoryAttributes = Attributes & MEMORY_ATTRIBUTE_MASK;\r
@@ -487,7 +496,7 @@ CpuSetMemoryAttributes (
   //\r
   // Set memory attribute by page table\r
   //\r
-  return AssignMemoryPageAttributes (NULL, BaseAddress, Length, MemoryAttributes, AllocatePages);\r
+  return AssignMemoryPageAttributes (NULL, BaseAddress, Length, MemoryAttributes, NULL);\r
 }\r
 \r
 /**\r
@@ -1092,7 +1101,7 @@ FreeMemorySpaceMap:
 }\r
 \r
 /**\r
-  Add and allocate CPU local APIC memory mapped space. \r
+  Add and allocate CPU local APIC memory mapped space.\r
 \r
   @param[in]ImageHandle     Image handle this driver.\r
 \r
@@ -1110,7 +1119,7 @@ AddLocalApicMemorySpace (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Try to allocate APIC memory mapped space, does not check return \r
+  // Try to allocate APIC memory mapped space, does not check return\r
   // status because it may be allocated by other driver, or DXE Core if\r
   // this range is built into Memory Allocation HOB.\r
   //\r
@@ -1149,7 +1158,7 @@ InitializeCpu (
 {\r
   EFI_STATUS  Status;\r
   EFI_EVENT   IdleLoopEvent;\r
-  \r
+\r
   InitializePageTableLib();\r
 \r
   InitializeFloatingPointUnits ();\r