@param[in] PagetablePoint Page table entry pointer (PTE).\r
@param[in] Mode Set or Clear shared bit\r
\r
+ @retval EFI_SUCCESS Successfully set or clear the memory shared bit\r
+ @retval Others Other error as indicated\r
**/\r
-STATIC VOID\r
+STATIC\r
+EFI_STATUS\r
SetOrClearSharedBit (\r
IN OUT UINT64 *PageTablePointer,\r
IN TDX_PAGETABLE_MODE Mode,\r
)\r
{\r
UINT64 AddressEncMask;\r
- UINT64 Status;\r
+ UINT64 TdStatus;\r
+ EFI_STATUS Status;\r
EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;\r
\r
AddressEncMask = GetMemEncryptionAddressMask ();\r
PhysicalAddress &= ~AddressEncMask;\r
}\r
\r
- Status = TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, 0, NULL);\r
+ TdStatus = TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, 0, NULL);\r
+ if (TdStatus != 0) {\r
+ DEBUG ((DEBUG_ERROR, "%a: TdVmcall(MAPGPA) failed with %llx\n", __FUNCTION__, TdStatus));\r
+ ASSERT (FALSE);\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
\r
//\r
// If changing shared to private, must accept-page again\r
//\r
if (Mode == ClearSharedBit) {\r
Status = gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, NULL, (VOID **)&MemoryAcceptProtocol);\r
- ASSERT (!EFI_ERROR (Status));\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "%a: Failed to locate MemoryAcceptProtocol with %r\n", __FUNCTION__, Status));\r
+ ASSERT (FALSE);\r
+ return Status;\r
+ }\r
+\r
Status = MemoryAcceptProtocol->AcceptMemory (MemoryAcceptProtocol, PhysicalAddress, Length);\r
- ASSERT (!EFI_ERROR (Status));\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "%a: Failed to AcceptMemory with %r\n", __FUNCTION__, Status));\r
+ ASSERT (FALSE);\r
+ return Status;\r
+ }\r
}\r
\r
DEBUG ((\r
Mode,\r
Status\r
));\r
+\r
+ return EFI_SUCCESS;\r
}\r
\r
/**\r
// If we have at least 1GB to go, we can just update this entry\r
//\r
if (!(PhysicalAddress & (BIT30 - 1)) && (Length >= BIT30)) {\r
- SetOrClearSharedBit (&PageDirectory1GEntry->Uint64, Mode, PhysicalAddress, BIT30);\r
+ Status = SetOrClearSharedBit (&PageDirectory1GEntry->Uint64, Mode, PhysicalAddress, BIT30);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
DEBUG ((\r
DEBUG_VERBOSE,\r
"%a:%a: updated 1GB entry for Physical=0x%Lx\n",\r
// If we have at least 2MB left to go, we can just update this entry\r
//\r
if (!(PhysicalAddress & (BIT21-1)) && (Length >= BIT21)) {\r
- SetOrClearSharedBit (&PageDirectory2MEntry->Uint64, Mode, PhysicalAddress, BIT21);\r
+ Status = SetOrClearSharedBit (&PageDirectory2MEntry->Uint64, Mode, PhysicalAddress, BIT21);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
PhysicalAddress += BIT21;\r
Length -= BIT21;\r
} else {\r
goto Done;\r
}\r
\r
- SetOrClearSharedBit (&PageTableEntry->Uint64, Mode, PhysicalAddress, EFI_PAGE_SIZE);\r
+ Status = SetOrClearSharedBit (&PageTableEntry->Uint64, Mode, PhysicalAddress, EFI_PAGE_SIZE);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
PhysicalAddress += EFI_PAGE_SIZE;\r
Length -= EFI_PAGE_SIZE;\r
}\r