General code cleanup - PeVmxState.c

This commit is contained in:
Eugene D Myers 2020-04-30 17:46:57 -04:00
parent dd8692eb75
commit d604e8b4dc
1 changed files with 133 additions and 84 deletions

View File

@ -56,22 +56,28 @@ int GetMultiProcessorState(UINT32 CpuIndex)
{
UINT32 PeType = PE_PERM;
UINT64 * NumProcessors = (UINT64 *) PeVmData[PeType].SharedPageStm;
ROOT_VMX_STATE * RootState; // = (ROOT_VMX_STATE *) (NumProcessors + sizeof(*NumProcessors));
// = (ROOT_VMX_STATE *) (NumProcessors + sizeof(*NumProcessors));
ROOT_VMX_STATE * RootState;
UINT32 CpuNum;
DEBUG((EFI_D_ERROR, "%ld GetMultiProcessorState - Started\n", CpuIndex));
DEBUG((EFI_D_INFO, "%ld GetMultiProcessorState - Started\n", CpuIndex));
if(PeVmData[PeType].SharedPageStm == NULL)
{
DEBUG((EFI_D_ERROR, "%ld GetMultiProcessorState - SharedPageStm is NULL, not gathering state\n", CpuIndex));
DEBUG((EFI_D_ERROR,
"%ld GetMultiProcessorState - SharedPageStm is NULL, not gathering state\n",
CpuIndex));
return -2;
}
// first clear out the data structures and set the number of processors
RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64 );//sizeof(*NumProcessors) + sizeof(*NumProcessors));
//sizeof(*NumProcessors) + sizeof(*NumProcessors));
RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64 );
*NumProcessors = mHostContextCommon.CpuNum; // number of CPUs
ZeroMem ((VOID *)(UINTN) RootState, sizeof(ROOT_VMX_STATE) * mHostContextCommon.CpuNum);
ZeroMem ((VOID *)(UINTN) RootState,
sizeof(ROOT_VMX_STATE) * mHostContextCommon.CpuNum);
// make sure that the VMCS offsets are setup
@ -79,9 +85,14 @@ int GetMultiProcessorState(UINT32 CpuIndex)
// send an SMI to the other processors
if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMINULL, PESMIPSMI) != PESMINULL) //&PeSmiControl.PeSmiState = 1;
if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState,
PESMINULL,
PESMIPSMI) != PESMINULL)
{
DEBUG((EFI_D_ERROR, "%ld x - Aborting, SMI handler already there. PeSmiState %ld\n", CpuIndex, PeSmiControl.PeSmiState));
DEBUG((EFI_D_ERROR,
"%ld x - Aborting, SMI handler already there. PeSmiState %ld\n",
CpuIndex,
PeSmiControl.PeSmiState));
return -1; // need to tell about smi handler is already there
}
@ -92,14 +103,10 @@ int GetMultiProcessorState(UINT32 CpuIndex)
// get the local processor state
//CpuReadySync(CpuIndex);
GetRootVmxState(CpuIndex, &RootState[CpuIndex]);
// need to think about this --- without it this hangs, what in context of other processors
//InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPSMI, PESMINULL);//PeSmiControl.PeSmiState = 0; // all done - may need to sync processors in the case of
// another SMI coming in
CpuReadySync(CpuIndex); // wait for everyone to finish the job - PeSmiHandler will set PeSmiState to 0
CpuReadySync(CpuIndex); // wait for everyone to finish the job
//- PeSmiHandler will set PeSmiState to 0
// once everyone has synched up
for(CpuNum = 0; CpuNum < mHostContextCommon.CpuNum; CpuNum++)
@ -107,8 +114,10 @@ int GetMultiProcessorState(UINT32 CpuIndex)
PrintVmxState(CpuNum, &RootState[CpuNum]);
}
DEBUG((EFI_D_ERROR, "%ld GetMultiProcessorState - Completed. PeSmiState: %ld\n", CpuIndex, PeSmiControl.PeSmiState));
DEBUG((EFI_D_ERROR,
"%ld GetMultiProcessorState - Completed. PeSmiState: %ld\n",
CpuIndex,
PeSmiControl.PeSmiState));
return 0;
}
@ -140,14 +149,17 @@ void GetRootVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState)
RootState->Vmxon = mHostContextCommon.HostContextPerCpu[CpuIndex].Vmxon;
//UINT32 ApicId = (UINT32) (get_apic_id() & 0xFF);
RootState->LinkVMCS = VmRead64(VMCS_64_GUEST_VMCS_LINK_PTR_INDEX);
RootState->ExecutiveVMCS = VmRead64(VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_INDEX); // get the executive VMCS
// DEBUG((EFI_D_ERROR, "%ld GetRootVmxState\n VMXON: 0x%016llx\n ExecutiveVMCS: 0x%016llx\n LinkVMCS: 0x%016llx\n",
// CpuIndex,
// RootState->Vmxon,
// RootState->ExecutiveVMCS,
// RootState->LinkVMCS));
// get the executive VMCS
RootState->ExecutiveVMCS = VmRead64(VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_INDEX);
#if 0
DEBUG((EFI_D_ERROR, "%ld GetRootVmxState\n VMXON: 0x%016llx\n ExecutiveVMCS: 0x%016llx\n LinkVMCS: 0x%016llx\n",
CpuIndex,
RootState->Vmxon,
RootState->ExecutiveVMCS,
RootState->LinkVMCS));
#endif
RootState->RootGuestCR0 = VmReadN(VMCS_N_GUEST_CR0_INDEX);
RootState->RootGuestCR3 = VmReadN(VMCS_N_GUEST_CR3_INDEX);
RootState->RootGuestCR4 = VmReadN(VMCS_N_GUEST_CR4_INDEX);
@ -168,41 +180,36 @@ void GetRootVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState)
if(RootState->ExecutiveVMCS == RootState->Vmxon) // ref: section 34.15.4.7
{
// we are in root operation, so our VMCS of interest is in the VNCS-Link field
// we are in root operation, so our VMCS of interest
// is in the VNCS-Link field
if(RootState->LinkVMCS != 0xFFFFFFFFFFFFFFFF)
{
RootState->VmcsType = 1; // guest-VM being sericed by VMM
HostRootVMCS = RootState->LinkVMCS;
//HostRootVMCS = VmRead64(VMCS_64_GUEST_VMCS_LINK_PTR_INDEX);
RootState->VmxState = VMX_STATE_ROOT;
//DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d): execVMCS is vmxon: 0x%016llx using VMCS_LINK_POINTER\n",
//CpuIndex, RootState->VmcsType, HostRootVMCS));
}
else
{
HostRootVMCS = RootState->ExecutiveVMCS;
RootState->VmcsType = 2;
//HostRootVMCS = VmRead64(VMCS_64_GUEST_VMCS_LINK_PTR_INDEX);
RootState->VmxState = VMX_STATE_ROOT;
//DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d): execVMCS is vmxon: But LinkVMCS is 0xFFFFFFFFFFFFFFF so no current Vmcs. Using Executive Vmcs: %llx\n",
// CpuIndex, RootState->VmcsType, HostRootVMCS));
}
}
else
{
// in guest operation, so our VMCS of interest is in the executive-VMCS field
// in guest operation, so our VMCS of interest
// is in the executive-VMCS field
RootState->VmcsType = 3;
HostRootVMCS = RootState->ExecutiveVMCS;
RootState->VmxState = VMX_STATE_GUEST;
//DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d): execVMCS is guest VMCS: 0x%016llx using Executive VMCS\n",
//CpuIndex, RootState->VmcsType, HostRootVMCS));
}
AsmVmClear(&(CurrentVMCSSave));
AsmVmPtrStore(&CurrentVMCSSave);
RootGuestRIP_M = *(UINT64 *)((UINTN)CurrentVMCSSave + (UINTN)VMCS_N_GUEST_RIP_OFFSET);
RootGuestRIP_M = *(UINT64 *)((UINTN)CurrentVMCSSave +
(UINTN)VMCS_N_GUEST_RIP_OFFSET);
VmcsFlushStart:
FlushCount = 0;
@ -212,8 +219,12 @@ VmcsFlushStart:
{
// got here because the in-memory copy of the VMCS is different than
// what is in the processor - so we need to flush
//DEBUG((EFI_D_ERROR, "%ld - GetRootState: RootGuestRIPMemory: 0x%016llx, Location: 0x%016llx\n",
//CpuIndex, RootGuestRIPMemory, ((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_RIP_OFFSET)));
#if 0
DEBUG((EFI_D_INFO, "%ld - GetRootState: RootGuestRIPMemory: 0x%016llx, Location: 0x%016llx\n",
CpuIndex,
RootGuestRIPMemory,
((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_RIP_OFFSET)));
#endif
// first create a dummy VMCS
VmxRevId = AsmReadMsr32(IA32_VMX_BASIC_MSR_INDEX);
DummyVmcs[FlushCount] = (char *) AllocatePages(VmcsSizeInPages);
@ -222,8 +233,10 @@ VmcsFlushStart:
{
// ran out of memory - release everything and start over
// that way someone else hopefully gets a chance to complete
DEBUG((EFI_D_ERROR, "%ld - GetRootState: ran out of memory - so free everything and restart - Flushcount: %d\n",
CpuIndex, FlushCount));
DEBUG((EFI_D_ERROR,
"%ld - GetRootState: ran out of memory - so free everything and restart - Flushcount: %d\n",
CpuIndex,
FlushCount));
if(FlushCount == 0)
goto VmcsFlushStart;
@ -236,17 +249,18 @@ VmcsFlushStart:
memcpy(DummyVmcs[FlushCount], &VmxRevId, 4);
AsmVmPtrLoad((UINT64 *) &DummyVmcs[FlushCount]);
RootGuestRIP_M = *(UINT64 *)((UINTN)CurrentVMCSSave + (UINTN)VMCS_N_GUEST_RIP_OFFSET); // try again
RootGuestRIP_M = *(UINT64 *)((UINTN)CurrentVMCSSave +
(UINTN)VMCS_N_GUEST_RIP_OFFSET); // try again
FlushCount++;
}
AsmVmPtrLoad(&CurrentVMCSSave); // in any case, reload this and free the dummies if necessary
// in any case, reload this and free the dummies if necessary
AsmVmPtrLoad(&CurrentVMCSSave);
if(FlushCount > 0)
{
DEBUG((EFI_D_ERROR, "%ld GetRootVmxState - Flush necessary to get VMCS in sync. Flushcount=%d\n",
DEBUG((EFI_D_INFO, "%ld GetRootVmxState - Flush necessary to get VMCS in sync. Flushcount=%d\n",
CpuIndex, FlushCount));
//DEBUG((EFI_D_ERROR, "%ld GetRootVmxState: after Flush: VMCS_N_GUEST_RIP_MEMORY: 0x%016llx (test) \n", CpuIndex, RootGuestRIPMemory));
// release the buffers
for(i = 0; i < FlushCount; i++)
{
@ -259,24 +273,35 @@ VmcsFlushStart:
//AsmVmPtrLoad(&HostRootVMCS);
RootState->HostRootVMCS = HostRootVMCS;
//DEBUG((EFI_D_ERROR, "%ld - GetRootVmxState: HostRootVmcs 0x%016llx\n", CpuIndex, RootState->HostRootVMCS));
RootGuestCR0_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_CR0_OFFSET);
RootGuestCR3_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_CR3_OFFSET);
RootGuestCR4_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_CR4_OFFSET);
RootGuestGDTRBase_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_GDTR_BASE_OFFSET);
RootGuestGDTRLimit_M = (*(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_32_GUEST_GDTR_LIMIT_OFFSET)) & 0x00000000FFFFFFFF;
RootGuestIDTRBase_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_IDTR_BASE_OFFSET);
RootGuestIDTRLimit_M = (*(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_32_GUEST_LDTR_LIMIT_OFFSET)) & 0x00000000FFFFFFFF;
RootGuestRSP_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_RSP_OFFSET);
RootGuestRIP_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_RIP_OFFSET);
RootContExecVmcs_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_OFFSET);
RootContLinkVmcs_M = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_64_GUEST_VMCS_LINK_PTR_OFFSET);
RootGuestCR0_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_GUEST_CR0_OFFSET);
RootGuestCR3_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_GUEST_CR3_OFFSET);
RootGuestCR4_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_GUEST_CR4_OFFSET);
RootGuestGDTRBase_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_GUEST_GDTR_BASE_OFFSET);
RootGuestGDTRLimit_M = (*(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_32_GUEST_GDTR_LIMIT_OFFSET)) & 0x00000000FFFFFFFF;
RootGuestIDTRBase_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_GUEST_IDTR_BASE_OFFSET);
RootGuestIDTRLimit_M = (*(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_32_GUEST_LDTR_LIMIT_OFFSET)) & 0x00000000FFFFFFFF;
RootGuestRSP_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_GUEST_RSP_OFFSET);
RootGuestRIP_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_GUEST_RIP_OFFSET);
RootContExecVmcs_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_OFFSET);
RootContLinkVmcs_M = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_64_GUEST_VMCS_LINK_PTR_OFFSET);
#ifdef VMCSDEBUGPRINT
if(RootState->VmcsType !=2) // only want active Vmcs
{
DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d) HostRootVmcs 0x%016llx\n G_CR0 %llx\n G_CR3 %llx\n G_CR4 %llx\n G_GDTR %llx:%llx\n G_IDTR %llx:%llx\n G_RSP %llx\n G_RIP %llx\n",
DEBUG((EFI_D_INFO,
"%ld GetRootVmxState (%d) HostRootVmcs 0x%016llx\n G_CR0 %llx\n G_CR3 %llx\n G_CR4 %llx\n G_GDTR %llx:%llx\n G_IDTR %llx:%llx\n G_RSP %llx\n G_RIP %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->HostRootVMCS,
@ -290,7 +315,8 @@ VmcsFlushStart:
RootState->RootGuestRSP,
RootState->RootGuestRIP));
DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d) (control) HostRootVmcs 0x%016llx\n VMXON %llx\n ExecutiveVMCS %llx\n LinkVMCS %llx\n EPT %llx\n",
DEBUG((EFI_D_INFO,
"%ld GetRootVmxState (%d) (control) HostRootVmcs 0x%016llx\n VMXON %llx\n ExecutiveVMCS %llx\n LinkVMCS %llx\n EPT %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->HostRootVMCS,
@ -299,9 +325,9 @@ VmcsFlushStart:
RootState->LinkVMCS,
RootState->RootContEPT));
DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d) (memory) HostRootVmcs 0x%016llx\n G_CR0m %llx\n G_CR3m %llx\n G_CR4m %llx\n G_GDTRm %llx:%llx\n G_IDTRm %llx:%llx\n G_RSPm %llx\n G_RIPm %llx\n",
DEBUG((EFI_D_INFO,
"%ld GetRootVmxState (%d) (memory) HostRootVmcs 0x%016llx\n G_CR0m %llx\n G_CR3m %llx\n G_CR4m %llx\n G_GDTRm %llx:%llx\n G_IDTRm %llx:%llx\n G_RSPm %llx\n G_RIPm %llx\n",
CpuIndex,
// "GetRootVmxState (memory)\n G_CR0m %llx\n G_CR3m %llx\n G_CR4m %llx\n G_GDTRm %llx:%llx\n G_IDTRm %llx:%llx\n G_RSPm %llx\n G_RIPm %llx\n C_ExecVMCSm %llx\n C_LinkVMCSm %llx\n",
RootState->VmcsType,
RootState->HostRootVMCS,
RootGuestCR0_M,
@ -314,7 +340,8 @@ VmcsFlushStart:
RootGuestRSP_M,
RootGuestRIP_M));
DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d) (memory) HostRootVmcs 0x%016llx\n C_ExecVMCSm %llx\n C_LinkVMCSm %llx\n",
DEBUG((EFI_D_ERROR,
"%ld GetRootVmxState (%d) (memory) HostRootVmcs 0x%016llx\n C_ExecVMCSm %llx\n C_LinkVMCSm %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->HostRootVMCS,
@ -322,8 +349,6 @@ VmcsFlushStart:
RootContLinkVmcs_M));
}
#endif
//DEBUG((EFI_D_ERROR, "%ld GetRootVmxState: VMCS_N_GUEST_RIP_MEMORY: 0x%016llx VMCS_N_GUEST_RIP: 0x%016llx, Location: 0x%016llx (test) \n",
// CpuIndex, RootGuestRIP_M, RootState->RootGuestRIP, ((UINTN)HostRootVMCS + (UINTN)VMCS_N_GUEST_RIP_OFFSET)));
// need to save the root vmx host structures
#ifdef ZERO
@ -342,15 +367,23 @@ VmcsFlushStart:
else
#endif
{
RootState->RootHostCR0 = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_HOST_CR0_OFFSET);
RootState->RootHostCR3 = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_HOST_CR3_OFFSET);
RootState->RootHostCR4 = *(UINT64 *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_HOST_CR4_OFFSET);
RootState->RootHostGDTRBase = *(UINTN *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_HOST_GDTR_BASE_OFFSET);
RootState->RootHostIDTRBase = *(UINTN *)((UINTN)HostRootVMCS + (UINTN)VMCS_N_HOST_IDTR_BASE_OFFSET);
RootState->RootHostCR0 = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_HOST_CR0_OFFSET);
RootState->RootHostCR3 = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_HOST_CR3_OFFSET);
RootState->RootHostCR4 = *(UINT64 *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_HOST_CR4_OFFSET);
RootState->RootHostGDTRBase = *(UINTN *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_HOST_GDTR_BASE_OFFSET);
RootState->RootHostIDTRBase = *(UINTN *)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_HOST_IDTR_BASE_OFFSET);
RootState->RootHostRSP = *(UINTN*)((UINTN)HostRootVMCS + (UINTN)VMCS_N_HOST_RSP_OFFSET);
RootState->RootHostRIP = *(UINTN*)((UINTN)HostRootVMCS + (UINTN)VMCS_N_HOST_RIP_OFFSET);
RootState->RootHostEPT = *(UINTN*)((UINTN)HostRootVMCS + (UINTN)VMCS_64_CONTROL_EPT_PTR_OFFSET);
RootState->RootHostRSP = *(UINTN*)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_HOST_RSP_OFFSET);
RootState->RootHostRIP = *(UINTN*)((UINTN)HostRootVMCS +
(UINTN)VMCS_N_HOST_RIP_OFFSET);
RootState->RootHostEPT = *(UINTN*)((UINTN)HostRootVMCS +
(UINTN)VMCS_64_CONTROL_EPT_PTR_OFFSET);
}
// Indicate to the master that we are all done
@ -363,7 +396,8 @@ VmcsFlushStart:
#ifdef VMCSDEBUGPRINT
if(RootState->VmcsType != 2)
{
DEBUG((EFI_D_ERROR, "%ld GetRootVmxState (%d) \n H_CR0 %llx\n H_CR3 %llx\n H_CR4 %llx\n H_GDTR %llx\n H_IDTR %llx\n H_RSP %llx\n H_RIP %llx\n H_EPT %llx\n",
DEBUG((EFI_D_INFO,
"%ld GetRootVmxState (%d) \n H_CR0 %llx\n H_CR3 %llx\n H_CR4 %llx\n H_GDTR %llx\n H_IDTR %llx\n H_RSP %llx\n H_RIP %llx\n H_EPT %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->RootHostCR0,
@ -408,40 +442,54 @@ void SetupGetRootVmxState()
VMCS_N_GUEST_IDTR_BASE_OFFSET = GetVmcsOffset(VMCS_N_GUEST_IDTR_BASE_INDEX);
VMCS_32_GUEST_LDTR_LIMIT_OFFSET = GetVmcsOffset(VMCS_32_GUEST_LDTR_LIMIT_INDEX);
VMCS_N_GUEST_RSP_OFFSET = GetVmcsOffset(VMCS_N_GUEST_RSP_INDEX);
VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_OFFSET = GetVmcsOffset(VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_INDEX);
VMCS_64_GUEST_VMCS_LINK_PTR_OFFSET = GetVmcsOffset(VMCS_64_GUEST_VMCS_LINK_PTR_INDEX);
VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_OFFSET =
GetVmcsOffset(VMCS_64_CONTROL_EXECUTIVE_VMCS_PTR_INDEX);
VMCS_64_GUEST_VMCS_LINK_PTR_OFFSET =
GetVmcsOffset(VMCS_64_GUEST_VMCS_LINK_PTR_INDEX);
// need to initialize the VMCS Offset table, if it has not already been done
VMCS_OFFSET_READY = 1;
}
void PrintVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState)
{
if(RootState->ExecutiveVMCS == RootState->Vmxon) // ref: section 34.15.4.7
if(RootState->ExecutiveVMCS == RootState->Vmxon)// ref: section 34.15.4.7
{
// we are in root operation, so our VMCS of interest is in the VNCS-Link field
// we are in root operation,
//so our VMCS of interest is in the VNCS-Link field
if(RootState->LinkVMCS != 0xFFFFFFFFFFFFFFFF)
{
DEBUG((EFI_D_ERROR, "%ld PrintVmxState (%d): execVMCS is vmxon: 0x%016llx using VMCS_LINK_POINTER\n",
CpuIndex, RootState->VmcsType, RootState->LinkVMCS));
DEBUG((EFI_D_INFO,
"%ld PrintVmxState (%d): execVMCS is vmxon: 0x%016llx using VMCS_LINK_POINTER\n",
CpuIndex,
RootState->VmcsType,
RootState->LinkVMCS));
}
else
{
DEBUG((EFI_D_ERROR, "%ld PrintVmxState (%d): execVMCS is vmxon: But LinkVMCS is 0xFFFFFFFFFFFFFFF so no current Vmcs. Using Executive Vmcs: %llx\n",
CpuIndex, RootState->VmcsType, RootState->ExecutiveVMCS));
DEBUG((EFI_D_INFO,
"%ld PrintVmxState (%d): execVMCS is vmxon: But LinkVMCS is 0xFFFFFFFFFFFFFFF so no current Vmcs. Using Executive Vmcs: %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->ExecutiveVMCS));
}
}
else
{
// in guest operation, so our VMCS of interest is in the executive-VMCS field
// in guest operation,
// so our VMCS of interest is in the executive-VMCS field
DEBUG((EFI_D_ERROR, "%ld PrintVmxState (%d): execVMCS is guest VMCS: 0x%016llx using Executive VMCS\n",
CpuIndex, RootState->VmcsType, RootState->ExecutiveVMCS));
DEBUG((EFI_D_INFO,
"%ld PrintVmxState (%d): execVMCS is guest VMCS: 0x%016llx using Executive VMCS\n",
CpuIndex,
RootState->VmcsType,
RootState->ExecutiveVMCS));
}
if(RootState->VmcsType !=2) // only want active Vmcs
{
DEBUG((EFI_D_ERROR, "%ld PrintVmxState (%d) HostRootVmcs 0x%016llx\n G_CR0 %llx\n G_CR3 %llx\n G_CR4 %llx\n G_GDTR %llx:%llx\n G_IDTR %llx:%llx\n G_RSP %llx\n G_RIP %llx\n",
DEBUG((EFI_D_INFO,
"%ld PrintVmxState (%d) HostRootVmcs 0x%016llx\n G_CR0 %llx\n G_CR3 %llx\n G_CR4 %llx\n G_GDTR %llx:%llx\n G_IDTR %llx:%llx\n G_RSP %llx\n G_RIP %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->HostRootVMCS,
@ -455,7 +503,8 @@ void PrintVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState)
RootState->RootGuestRSP,
RootState->RootGuestRIP));
DEBUG((EFI_D_ERROR, "%ld PrintVmxState (%d) (control) HostRootVmcs 0x%016llx\n VMXON %llx\n ExecutiveVMCS %llx\n LinkVMCS %llx\n EPT %llx\n",
DEBUG((EFI_D_INFO,
"%ld PrintVmxState (%d) (control) HostRootVmcs 0x%016llx\n VMXON %llx\n ExecutiveVMCS %llx\n LinkVMCS %llx\n EPT %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->HostRootVMCS,
@ -464,7 +513,8 @@ void PrintVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState)
RootState->LinkVMCS,
RootState->RootContEPT));
DEBUG((EFI_D_ERROR, "%ld PrintVmxState (%d) \n H_CR0 %llx\n H_CR3 %llx\n H_CR4 %llx\n H_GDTR %llx\n H_IDTR %llx\n H_RSP %llx\n H_RIP %llx\n H_EPT %llx\n",
DEBUG((EFI_D_INFO,
"%ld PrintVmxState (%d) \n H_CR0 %llx\n H_CR3 %llx\n H_CR4 %llx\n H_GDTR %llx\n H_IDTR %llx\n H_RSP %llx\n H_RIP %llx\n H_EPT %llx\n",
CpuIndex,
RootState->VmcsType,
RootState->RootHostCR0,
@ -478,4 +528,3 @@ void PrintVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState)
}
}