]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
OvmfPkg/IoMmuDxe: track all mappings
[mirror_edk2.git] / OvmfPkg / IoMmuDxe / AmdSevIoMmu.c
index bc57de5b572b6048b6be7a4954ca1ca149a078df..c86e734985552d2f9e5657109cfcd8e4750528da 100644 (file)
@@ -33,14 +33,11 @@ typedef struct {
 } MAP_INFO;\r
 \r
 //\r
-// List of MAP_INFO structures recycled by Unmap().\r
+// List of the MAP_INFO structures that have been set up by IoMmuMap() and not\r
+// yet torn down by IoMmuUnmap(). The list represents the full set of mappings\r
+// currently in effect.\r
 //\r
-// Recycled MAP_INFO structures are equally good for future recycling and\r
-// freeing.\r
-//\r
-STATIC LIST_ENTRY mRecycledMapInfos = INITIALIZE_LIST_HEAD_VARIABLE (\r
-                                        mRecycledMapInfos\r
-                                        );\r
+STATIC LIST_ENTRY mMapInfos = INITIALIZE_LIST_HEAD_VARIABLE (mMapInfos);\r
 \r
 #define COMMON_BUFFER_SIG SIGNATURE_64 ('C', 'M', 'N', 'B', 'U', 'F', 'F', 'R')\r
 \r
@@ -123,7 +120,6 @@ IoMmuMap (
   )\r
 {\r
   EFI_STATUS                                        Status;\r
-  LIST_ENTRY                                        *RecycledMapInfo;\r
   MAP_INFO                                          *MapInfo;\r
   EFI_ALLOCATE_TYPE                                 AllocateType;\r
   COMMON_BUFFER_HEADER                              *CommonBufferHeader;\r
@@ -150,19 +146,10 @@ IoMmuMap (
   // Allocate a MAP_INFO structure to remember the mapping when Unmap() is\r
   // called later.\r
   //\r
-  RecycledMapInfo = GetFirstNode (&mRecycledMapInfos);\r
-  if (RecycledMapInfo == &mRecycledMapInfos) {\r
-    //\r
-    // No recycled MAP_INFO structure, allocate a new one.\r
-    //\r
-    MapInfo = AllocatePool (sizeof (MAP_INFO));\r
-    if (MapInfo == NULL) {\r
-      Status = EFI_OUT_OF_RESOURCES;\r
-      goto Failed;\r
-    }\r
-  } else {\r
-    MapInfo = CR (RecycledMapInfo, MAP_INFO, Link, MAP_INFO_SIG);\r
-    RemoveEntryList (RecycledMapInfo);\r
+  MapInfo = AllocatePool (sizeof (MAP_INFO));\r
+  if (MapInfo == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Failed;\r
   }\r
 \r
   //\r
@@ -298,6 +285,10 @@ IoMmuMap (
       );\r
   }\r
 \r
+  //\r
+  // Track all MAP_INFO structures.\r
+  //\r
+  InsertHeadList (&mMapInfos, &MapInfo->Link);\r
   //\r
   // Populate output parameters.\r
   //\r
@@ -430,24 +421,20 @@ IoMmuUnmap (
       CommonBufferHeader->StashBuffer,\r
       MapInfo->NumberOfBytes\r
       );\r
-\r
-    //\r
-    // Recycle the MAP_INFO structure.\r
-    //\r
-    InsertTailList (&mRecycledMapInfos, &MapInfo->Link);\r
   } else {\r
     ZeroMem (\r
       (VOID *)(UINTN)MapInfo->PlainTextAddress,\r
       EFI_PAGES_TO_SIZE (MapInfo->NumberOfPages)\r
       );\r
     gBS->FreePages (MapInfo->PlainTextAddress, MapInfo->NumberOfPages);\r
-\r
-    //\r
-    // Free the MAP_INFO structure.\r
-    //\r
-    FreePool (MapInfo);\r
   }\r
 \r
+  //\r
+  // Forget and free the MAP_INFO structure.\r
+  //\r
+  RemoveEntryList (&MapInfo->Link);\r
+  FreePool (MapInfo);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r