OvmfPkg/PlatformPei: set the Hypervisor Features PCD

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275

Version 2 of the GHCB specification added the support to query the
hypervisor feature bitmap. The feature bitmap provide information
such as whether to use the AP create VmgExit or use the AP jump table
approach to create the APs. The MpInitLib will use the
PcdGhcbHypervisorFeatures to determine which method to use for creating
the AP.

Query the hypervisor feature and set the PCD accordingly.

Cc: Michael Roth <michael.roth@amd.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
This commit is contained in:
Brijesh Singh 2021-12-09 11:27:52 +08:00 committed by mergify[bot]
parent f4e3ce5f53
commit f5a6e1bab5
2 changed files with 57 additions and 0 deletions

View File

@ -24,6 +24,12 @@
#include "Platform.h"
STATIC
UINT64
GetHypervisorFeature (
VOID
);
/**
Initialize SEV-SNP support if running as an SEV-SNP guest.
@ -36,11 +42,21 @@ AmdSevSnpInitialize (
{
EFI_PEI_HOB_POINTERS Hob;
EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
UINT64 HvFeatures;
EFI_STATUS PcdStatus;
if (!MemEncryptSevSnpIsEnabled ()) {
return;
}
//
// Query the hypervisor feature using the VmgExit and set the value in the
// hypervisor features PCD.
//
HvFeatures = GetHypervisorFeature ();
PcdStatus = PcdSet64S (PcdGhcbHypervisorFeatures, HvFeatures);
ASSERT_RETURN_ERROR (PcdStatus);
//
// Iterate through the system RAM and validate it.
//
@ -91,6 +107,45 @@ SevEsProtocolFailure (
CpuDeadLoop ();
}
/**
Get the hypervisor features bitmap
**/
STATIC
UINT64
GetHypervisorFeature (
VOID
)
{
UINT64 Status;
GHCB *Ghcb;
MSR_SEV_ES_GHCB_REGISTER Msr;
BOOLEAN InterruptState;
UINT64 Features;
Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
Ghcb = Msr.Ghcb;
//
// Initialize the GHCB
//
VmgInit (Ghcb, &InterruptState);
//
// Query the Hypervisor Features.
//
Status = VmgExit (Ghcb, SVM_EXIT_HYPERVISOR_FEATURES, 0, 0);
if ((Status != 0)) {
SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL);
}
Features = Ghcb->SaveArea.SwExitInfo2;
VmgDone (Ghcb, InterruptState);
return Features;
}
/**
This function can be used to register the GHCB GPA.

View File

@ -62,6 +62,7 @@
MtrrLib
MemEncryptSevLib
PcdLib
VmgExitLib
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
@ -107,6 +108,7 @@
gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize
gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr
gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures
[FixedPcd]
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress