Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MsvmPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
gMsvmPkgTokenSpaceGuid.PcdHighMmioGapBasePageNumber ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdHighMmioGapSizeInPages ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdHostEmulatorsWhenHardwareIsolated ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdHvEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdLoadOempTable ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdLowMmioGapBasePageNumber ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdLowMmioGapSizeInPages ## CONSUMES
Expand Down
7 changes: 5 additions & 2 deletions MsvmPkg/AcpiPlatformDxe/Facp.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ Return Value:
}

//
// Set the hypervisor vendor identity to MsHyperV
// Set the hypervisor vendor identity to MsHyperV when Hv is enabled.
//
CopyMem(&facp->HypervisorVendorIdentity, "MsHyperV", 8);
if (PcdGetBool(PcdHvEnabled))
{
CopyMem(&facp->HypervisorVendorIdentity, "MsHyperV", 8);
}

if (PcdGetBool(PcdLowPowerS0IdleEnabled))
{
Expand Down
6 changes: 6 additions & 0 deletions MsvmPkg/EfiHvDxe/EfiHv.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Library/CrashLib.h>
#include <Library/DebugLib.h>
#include <Library/HostVisibilityLib.h>
#include <Library/PcdLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/HvHypercallLib.h>
Expand Down Expand Up @@ -2320,6 +2321,11 @@ EfiHvInitialize (
{
EFI_STATUS status;

if (!PcdGetBool(PcdHvEnabled))
{
return EFI_UNSUPPORTED;
}

InitializeListHead(&mHostVisiblePageList);

#if defined (MDE_CPU_X64)
Expand Down
3 changes: 3 additions & 0 deletions MsvmPkg/EfiHvDxe/EfiHvDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
[Protocols.AARCH64]
gHardwareInterruptProtocolGuid ## CONSUMES

[Pcd]
gMsvmPkgTokenSpaceGuid.PcdHvEnabled ## CONSUMES

[Pcd.X64]
gMsvmPkgTokenSpaceGuid.PcdIsolationSharedGpaBoundary ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdIsolationSharedGpaCanonicalizationBitmask ## CONSUMES
Expand Down
28 changes: 15 additions & 13 deletions MsvmPkg/EventLogDxe/EventLogDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
**/

#include "EventLogDxe.h"
#include <IsolationTypes.h>
#include <Library/UefiDriverEntryPoint.h>
#include "StatusCode.h"
#include "EventLogger.h"

EFI_HV_PROTOCOL *mHv;
EFI_HV_IVM_PROTOCOL *mHvIvm;

EFI_STATUS
Expand Down Expand Up @@ -43,24 +43,26 @@ Return Value:
EFI_STATUS status;

DEBUG((DEBUG_INIT, "EventLog Driver Starting\n"));

//
// Initialize the event channel management and then the status code protocol
// The IVM protocol is required for hardware-isolated VMs. Check this
// before EventLoggerInitialize, which installs protocols — returning
// error after that would leave dangling protocol entries.
//
status = EventLoggerInitialize();

if (EFI_ERROR(status))
if (IsHardwareIsolatedNoParavisor())
{
goto Exit;
}

status = gBS->LocateProtocol(&gEfiHvProtocolGuid, NULL, (VOID **)&mHv);
status = gBS->LocateProtocol(&gEfiHvIvmProtocolGuid, NULL, (VOID **)&mHvIvm);

if (EFI_ERROR(status))
{
goto Exit;
if (EFI_ERROR(status))
{
goto Exit;
}
}

status = gBS->LocateProtocol(&gEfiHvIvmProtocolGuid, NULL, (VOID **)&mHvIvm);
//
// Initialize the event channel management and then the status code protocol
//
status = EventLoggerInitialize();

if (EFI_ERROR(status))
{
Expand Down
3 changes: 1 addition & 2 deletions MsvmPkg/EventLogDxe/EventLogDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
[Protocols]
gEfiEventLogProtocolGuid ## PRODUCES
gEfiFirmwareVolume2ProtocolGuid ## CONSUMES
gEfiHvIvmProtocolGuid ## CONSUMES
gEfiHvProtocolGuid ## CONSUMES
gEfiHvIvmProtocolGuid ## SOMETIMES_CONSUMES
gEfiRscHandlerProtocolGuid ## CONSUMES
gEfiStatusCodeRuntimeProtocolGuid ## PRODUCES

Expand Down
32 changes: 32 additions & 0 deletions MsvmPkg/Include/Ppi/SecPlatformType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @file
SEC Platform Type PPI definition.

This PPI is installed by the SEC phase to communicate the platform type
to PEI modules.

Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef SEC_PLATFORM_TYPE_H_
#define SEC_PLATFORM_TYPE_H_

///
/// Platform type values passed by the loader.
///
typedef enum {
MsvmSecPlatformHyperV = 0, // Hyper-V with MS extensions
MsvmSecPlatformGeneric = 1, // Generic virtualization (no MS extensions)
} MSVM_SEC_PLATFORM_TYPE;

///
/// PPI carrying the platform type from SEC to PEI.
///
typedef struct {
MSVM_SEC_PLATFORM_TYPE PlatformType;
} MSVM_SEC_PLATFORM_TYPE_PPI;

extern EFI_GUID gMsvmSecPlatformTypePpiGuid;

#endif // SEC_PLATFORM_TYPE_H_
125 changes: 65 additions & 60 deletions MsvmPkg/Library/CrashLib/AArch64/Crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Library/BiosDeviceLib.h>
#include <Library/DebugLib.h>
#include <Library/HvHypercallLib.h>
#include <Library/PcdLib.h>
#include <Hv/HvGuestCpuid.h>
#include <Hv/HvGuestMsr.h>
#include <BiosInterface.h>
Expand Down Expand Up @@ -51,72 +52,76 @@ ReportCrash(
IN UINTN MessageLength
)
{
//
// Set the guest ID before writing crash registers, if necessary.
//
HV_REGISTER_VALUE registerValue;
HV_STATUS status = AsmGetVpRegister(HvRegisterGuestOsId, &registerValue);
ASSERT(status == HV_STATUS_SUCCESS);

if (registerValue.Reg64 == 0)
if (PcdGetBool(PcdHvEnabled))
{
DEBUG((EFI_D_INFO, "GuestOsId is not set in ReportCrash(); setting now.\n"));

HV_GUEST_OS_ID_CONTENTS guestOsId;
guestOsId.AsUINT64 = 0;
guestOsId.OsId = HvGuestOsMicrosoftUndefined;
guestOsId.VendorId = HvGuestOsVendorMicrosoft;

status = AsmSetVpRegister64(HvRegisterGuestOsId, guestOsId.AsUINT64);
//
// Set the guest ID before writing crash registers, if necessary.
//
HV_REGISTER_VALUE registerValue;
HV_STATUS status = AsmGetVpRegister(HvRegisterGuestOsId, &registerValue);
ASSERT(status == HV_STATUS_SUCCESS);
}
else
{
DEBUG((EFI_D_VERBOSE, "GuestOsId is 0x%llx.\n", (UINTN)registerValue.Reg64));
}

//
// Determine if crash MSRs are supported
//
status = AsmGetVpRegister(HvRegisterPrivilegesAndFeaturesInfo, &registerValue);
ASSERT(status == HV_STATUS_SUCCESS);

DEBUG((EFI_D_VERBOSE, "HvRegisterFeaturesInfo (low) is 0x%llx.\n", (UINTN)registerValue.Reg128.Low64));
DEBUG((EFI_D_VERBOSE, "HvRegisterFeaturesInfo (high) is 0x%llx.\n", (UINTN)registerValue.Reg128.High64));

HV_HYPERVISOR_FEATURES hvFeatures;
*((PHV_UINT128)&hvFeatures) = registerValue.Reg128;
if (registerValue.Reg64 == 0)
{
DEBUG((EFI_D_INFO, "GuestOsId is not set in ReportCrash(); setting now.\n"));

HV_GUEST_OS_ID_CONTENTS guestOsId;
guestOsId.AsUINT64 = 0;
guestOsId.OsId = HvGuestOsMicrosoftUndefined;
guestOsId.VendorId = HvGuestOsVendorMicrosoft;

status = AsmSetVpRegister64(HvRegisterGuestOsId, guestOsId.AsUINT64);
ASSERT(status == HV_STATUS_SUCCESS);
}
else
{
DEBUG((EFI_D_VERBOSE, "GuestOsId is 0x%llx.\n", (UINTN)registerValue.Reg64));
}

//
// Determine if crash MSRs are supported
//
status = AsmGetVpRegister(HvRegisterPrivilegesAndFeaturesInfo, &registerValue);
ASSERT(status == HV_STATUS_SUCCESS);

if (!hvFeatures.GuestCrashRegsAvailable)
{
DEBUG((EFI_D_INFO, "GuestCrashRegister enlightenment is not available.\n"));
return;
DEBUG((EFI_D_VERBOSE, "HvRegisterFeaturesInfo (low) is 0x%llx.\n", (UINTN)registerValue.Reg128.Low64));
DEBUG((EFI_D_VERBOSE, "HvRegisterFeaturesInfo (high) is 0x%llx.\n", (UINTN)registerValue.Reg128.High64));

HV_HYPERVISOR_FEATURES hvFeatures;
*((PHV_UINT128)&hvFeatures) = registerValue.Reg128;

if (hvFeatures.GuestCrashRegsAvailable)
{
//
// N.B. For ARM64, the crash control registers cannot currently be read for capabilities.
//

AsmSetVpRegister64(HvRegisterGuestCrashP0, Param0);
AsmSetVpRegister64(HvRegisterGuestCrashP1, Param1);
AsmSetVpRegister64(HvRegisterGuestCrashP2, Param2);
AsmSetVpRegister64(HvRegisterGuestCrashP3, MessageBuffer);
AsmSetVpRegister64(HvRegisterGuestCrashP4, MessageLength);

//
// Write the control register.
//
HV_CRASH_CTL_REG_CONTENTS writeCrashCtlReg;
writeCrashCtlReg.AsUINT64 = 0;
writeCrashCtlReg.CrashNotify = 1;

writeCrashCtlReg.CrashMessage = 1;
writeCrashCtlReg.NoCrashDump = 1;
writeCrashCtlReg.PreOSId = MSVM_PKG_CRASH_ID;

AsmSetVpRegister64(HvRegisterGuestCrashCtl, writeCrashCtlReg.AsUINT64);
DEBUG((EFI_D_INFO, "ReportCrash successful.\n"));
}
else
{
DEBUG((EFI_D_INFO, "GuestCrashRegister enlightenment is not available.\n"));
}
}

//
// N.B. For ARM64, the crash control registers cannot currently be read for capabilities.
//

AsmSetVpRegister64(HvRegisterGuestCrashP0, Param0);
AsmSetVpRegister64(HvRegisterGuestCrashP1, Param1);
AsmSetVpRegister64(HvRegisterGuestCrashP2, Param2);
AsmSetVpRegister64(HvRegisterGuestCrashP3, MessageBuffer);
AsmSetVpRegister64(HvRegisterGuestCrashP4, MessageLength);

//
// Write the control register.
//
HV_CRASH_CTL_REG_CONTENTS writeCrashCtlReg;
writeCrashCtlReg.AsUINT64 = 0;
writeCrashCtlReg.CrashNotify = 1;

writeCrashCtlReg.CrashMessage = 1;
writeCrashCtlReg.NoCrashDump = 1;
writeCrashCtlReg.PreOSId = MSVM_PKG_CRASH_ID;

AsmSetVpRegister64(HvRegisterGuestCrashCtl, writeCrashCtlReg.AsUINT64);
DEBUG((EFI_D_INFO, "ReportCrash successful.\n"));

//
// Tell the host to collect EFI diagnostics.
//
Expand Down
3 changes: 3 additions & 0 deletions MsvmPkg/Library/CrashLib/CrashLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
[LibraryClasses.AARCH64]
ArmSmcLib
HvHypercallLib

[Pcd.AARCH64]
gMsvmPkgTokenSpaceGuid.PcdHvEnabled ## CONSUMES
4 changes: 3 additions & 1 deletion MsvmPkg/MsvmPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
gMsvmUnableToBootEventGuid = {0x3c8d08a8, 0x42c5, 0x4c33, {0xa6, 0xd8, 0x13, 0xf4, 0xda, 0x4a, 0xa6, 0x85}}

[Ppis]
gMsvmSecPlatformTypePpiGuid = {0x7a3b9e2c, 0x4d15, 0x4f8a, {0xb1, 0x0e, 0x3c, 0x5d, 0x8f, 0x2a, 0x6b, 0x47}}

[Protocols]
gMsvmAziHsmProtocolGuid = {0x38976D4E, 0x7454, 0x40CF, {0x9E, 0x12, 0x95, 0xCE, 0x61, 0xA4, 0xCD, 0x6C}}
gMsvmAziHsmProtocolGuid = {0x38976D4E, 0x7454, 0x40CF, {0x9E, 0x12, 0x95, 0xCE, 0x61, 0xA4, 0xCD, 0x6C}}
# Hyper-V Protocol
gEfiHvProtocolGuid = {0xa261a0f1, 0xaa53, 0x4c83, {0x94, 0xda, 0x12, 0x0c, 0xdf, 0x6d, 0x8c, 0x8d}}
gEfiHvIvmProtocolGuid = {0xc40a31b5, 0x3899, 0x4f76, {0xbf, 0x7e, 0x32, 0x95, 0x83, 0x3f, 0xee, 0xe7}}
Expand Down Expand Up @@ -304,6 +305,7 @@
gMsvmPkgTokenSpaceGuid.PcdTpmLocalityRegsEnabled|FALSE|BOOLEAN|0x6065
gMsvmPkgTokenSpaceGuid.PcdMtrrsInitializedAtLoad|FALSE|BOOLEAN|0x6067
gMsvmPkgTokenSpaceGuid.PcdVmbusEnabled|TRUE|BOOLEAN|0x6068
gMsvmPkgTokenSpaceGuid.PcdHvEnabled|TRUE|BOOLEAN|0x6069
gMsvmPkgTokenSpaceGuid.PcdForceDmaBounceEnabled|FALSE|BOOLEAN|0x6076

# UEFI_CONFIG_PROCESSOR_INFORMATION
Expand Down
1 change: 1 addition & 0 deletions MsvmPkg/MsvmPkgAARCH64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@
gMsvmPkgTokenSpaceGuid.PcdHostEmulatorsWhenHardwareIsolated|FALSE
gMsvmPkgTokenSpaceGuid.PcdTpmLocalityRegsEnabled|FALSE
gMsvmPkgTokenSpaceGuid.PcdVmbusEnabled|TRUE
gMsvmPkgTokenSpaceGuid.PcdHvEnabled|TRUE
gMsvmPkgTokenSpaceGuid.PcdForceDmaBounceEnabled|FALSE

# UEFI_CONFIG_PROCESSOR_INFORMATION
Expand Down
1 change: 1 addition & 0 deletions MsvmPkg/MsvmPkgX64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@
gMsvmPkgTokenSpaceGuid.PcdHostEmulatorsWhenHardwareIsolated|FALSE
gMsvmPkgTokenSpaceGuid.PcdTpmLocalityRegsEnabled|FALSE
gMsvmPkgTokenSpaceGuid.PcdVmbusEnabled|TRUE
gMsvmPkgTokenSpaceGuid.PcdHvEnabled|TRUE
gMsvmPkgTokenSpaceGuid.PcdForceDmaBounceEnabled|FALSE

# UEFI_CONFIG_PROCESSOR_INFORMATION
Expand Down
11 changes: 11 additions & 0 deletions MsvmPkg/PlatformPei/Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,17 @@ ConfigSetUefiConfigFlags(
PEI_FAIL_FAST_IF_FAILED(PcdSetBoolS(PcdTpmLocalityRegsEnabled, (UINT8) ConfigFlags->Flags.TpmLocalityRegsEnabled));
PEI_FAIL_FAST_IF_FAILED(PcdSetBoolS(PcdMtrrsInitializedAtLoad, (UINT8) ConfigFlags->Flags.MtrrsInitializedAtLoad));
PEI_FAIL_FAST_IF_FAILED(PcdSetBoolS(PcdVmbusEnabled, !ConfigFlags->Flags.VmbusDisabled));

//
// VMBus requires Hv. PcdHvEnabled was already set from the SEC platform
// type PPI in InitializePlatform(). Validate consistency here.
//
if (!PcdGetBool(PcdHvEnabled) && !ConfigFlags->Flags.VmbusDisabled)
{
DEBUG((DEBUG_ERROR, "Invalid config: VMBus enabled but Hv disabled.\n"));
FAIL_FAST_UNEXPECTED_HOST_BEHAVIOR();
}

PEI_FAIL_FAST_IF_FAILED(PcdSetBoolS(PcdPciDisableBusEnumeration, (UINT8) ConfigFlags->Flags.PciResourcesPreAssigned));
PEI_FAIL_FAST_IF_FAILED(PcdSetBoolS(PcdForceDmaBounceEnabled, (UINT8) ConfigFlags->Flags.ForceDmaBounceEnabled));

Expand Down
Loading
Loading