28 IN SEV_SNP_PAGE_STATE State
34 case SevSnpPageShared: Cmd = SNP_PAGE_STATE_SHARED;
36 case SevSnpPagePrivate: Cmd = SNP_PAGE_STATE_PRIVATE;
45SnpPageStateFailureTerminate (
54 Msr.GhcbPhysicalAddress = 0;
55 Msr.GhcbTerminate.Function = GHCB_INFO_TERMINATE_REQUEST;
56 Msr.GhcbTerminate.ReasonCodeSet = GHCB_TERMINATE_GHCB;
57 Msr.GhcbTerminate.ReasonCode = GHCB_TERMINATE_GHCB_GENERAL;
71 IN SEV_SNP_PAGE_STATE State,
72 IN BOOLEAN UseLargeEntry,
85 SetMem (Info, InfoSize, 0);
88 IndexMax = (InfoSize -
sizeof (Info->Header)) /
sizeof (Info->Entry[0]);
89 NextAddress = EndAddress;
96 PscIndexMax = (IndexMax / SNP_PAGE_STATE_MAX_ENTRY) * SNP_PAGE_STATE_MAX_ENTRY;
97 if (PscIndexMax > 0) {
98 IndexMax =
MIN (IndexMax, PscIndexMax);
101 SvsmIndexMax = (IndexMax / SVSM_PVALIDATE_MAX_ENTRY) * SVSM_PVALIDATE_MAX_ENTRY;
102 if (SvsmIndexMax > 0) {
103 IndexMax =
MIN (IndexMax, SvsmIndexMax);
109 while ((BaseAddress < EndAddress) && (Index < IndexMax)) {
113 if (UseLargeEntry &&
IS_ALIGNED (BaseAddress, SIZE_2MB) &&
114 ((EndAddress - BaseAddress) >= SIZE_2MB))
116 RmpPageSize = PvalidatePageSize2MB;
117 NextAddress = BaseAddress + SIZE_2MB;
119 RmpPageSize = PvalidatePageSize4K;
120 NextAddress = BaseAddress + EFI_PAGE_SIZE;
123 Info->Entry[Index].GuestFrameNumber = BaseAddress >> EFI_PAGE_SHIFT;
124 Info->Entry[Index].PageSize = RmpPageSize;
125 Info->Entry[Index].Operation = MemoryStateToGhcbOp (State);
126 Info->Entry[Index].CurrentPage = 0;
127 Info->Header.EndEntry = (UINT16)Index;
129 BaseAddress = NextAddress;
138PageStateChangeVmgExit (
146 BOOLEAN InterruptState;
148 ASSERT (Count <= SNP_PAGE_STATE_MAX_ENTRY);
149 if (Count > SNP_PAGE_STATE_MAX_ENTRY) {
150 SnpPageStateFailureTerminate ();
159 GhcbInfo->Header.CurrentEntry = 0;
160 GhcbInfo->Header.EndEntry = Count - 1;
161 CopyMem (GhcbInfo->Entry, Start, sizeof (*Start) * Count);
172 while (GhcbInfo->Header.CurrentEntry <= GhcbInfo->Header.EndEntry) {
173 Ghcb->SaveArea.SwScratch = (UINT64)Ghcb->SharedBuffer;
176 Status =
CcExitVmgExit (Ghcb, SVM_EXIT_SNP_PAGE_STATE_CHANGE, 0, 0);
182 if ((Status != 0) || (Ghcb->SaveArea.SwExitInfo2)) {
183 SnpPageStateFailureTerminate ();
205 Header = &Info->Header;
207 for (Index = Header->CurrentEntry; Index <= Header->EndEntry;) {
208 Count =
MIN (Header->EndEntry - Index + 1, SNP_PAGE_STATE_MAX_ENTRY);
210 PageStateChangeVmgExit (Ghcb, &Info->Entry[Index], Count);
228 IN SEV_SNP_PAGE_STATE State,
229 IN BOOLEAN UseLargeEntry,
241 "%a:%a Address 0x%Lx - 0x%Lx State = %a LargeEntry = %d\n",
246 State == SevSnpPageShared ?
"Shared" :
"Private",
252 for (NextAddress = BaseAddress; NextAddress < EndAddress;) {
256 NextAddress = BuildPageStateBuffer (
269 if (State == SevSnpPageShared) {
276 PageStateChange (Info);
282 if (State == SevSnpPagePrivate) {
VOID EFIAPI AmdSvsmSnpPvalidate(IN SNP_PAGE_STATE_CHANGE_INFO *Info)
VOID EFIAPI CpuDeadLoop(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
UINT64 EFIAPI CcExitVmgExit(IN OUT GHCB *Ghcb, IN UINT64 ExitCode, IN UINT64 ExitInfo1, IN UINT64 ExitInfo2)
VOID EFIAPI CcExitVmgSetOffsetValid(IN OUT GHCB *Ghcb, IN GHCB_REGISTER Offset)
VOID EFIAPI CcExitVmgInit(IN OUT GHCB *Ghcb, IN OUT BOOLEAN *InterruptState)
VOID EFIAPI CcExitVmgDone(IN OUT GHCB *Ghcb, IN BOOLEAN InterruptState)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
UINT64 EFIAPI AsmWriteMsr64(IN UINT32 Index, IN UINT64 Value)
#define IS_ALIGNED(Value, Alignment)
#define DEBUG(Expression)
VOID InternalSetPageState(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINTN NumPages, IN SEV_SNP_PAGE_STATE State, IN BOOLEAN UseLargeEntry, IN VOID *PscBuffer, IN UINTN PscBufferSize)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)