]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: set the Hypervisor Features PCD
authorBrijesh Singh <brijesh.singh@amd.com>
Thu, 9 Dec 2021 03:27:52 +0000 (11:27 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 9 Dec 2021 06:28:10 +0000 (06:28 +0000)
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>
OvmfPkg/PlatformPei/AmdSev.c
OvmfPkg/PlatformPei/PlatformPei.inf

index c60a153a059e044acd64cf822777d8461939330f..9b71f7cf2fabbbd03258313a0689affebd7d2105 100644 (file)
 \r
 #include "Platform.h"\r
 \r
+STATIC\r
+UINT64\r
+GetHypervisorFeature (\r
+  VOID\r
+  );\r
+\r
 /**\r
   Initialize SEV-SNP support if running as an SEV-SNP guest.\r
 \r
@@ -36,11 +42,21 @@ AmdSevSnpInitialize (
 {\r
   EFI_PEI_HOB_POINTERS         Hob;\r
   EFI_HOB_RESOURCE_DESCRIPTOR  *ResourceHob;\r
+  UINT64                       HvFeatures;\r
+  EFI_STATUS                   PcdStatus;\r
 \r
   if (!MemEncryptSevSnpIsEnabled ()) {\r
     return;\r
   }\r
 \r
+  //\r
+  // Query the hypervisor feature using the VmgExit and set the value in the\r
+  // hypervisor features PCD.\r
+  //\r
+  HvFeatures = GetHypervisorFeature ();\r
+  PcdStatus  = PcdSet64S (PcdGhcbHypervisorFeatures, HvFeatures);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
   //\r
   // Iterate through the system RAM and validate it.\r
   //\r
@@ -91,6 +107,45 @@ SevEsProtocolFailure (
   CpuDeadLoop ();\r
 }\r
 \r
+/**\r
+ Get the hypervisor features bitmap\r
+\r
+**/\r
+STATIC\r
+UINT64\r
+GetHypervisorFeature (\r
+  VOID\r
+  )\r
+{\r
+  UINT64                    Status;\r
+  GHCB                      *Ghcb;\r
+  MSR_SEV_ES_GHCB_REGISTER  Msr;\r
+  BOOLEAN                   InterruptState;\r
+  UINT64                    Features;\r
+\r
+  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);\r
+  Ghcb                    = Msr.Ghcb;\r
+\r
+  //\r
+  // Initialize the GHCB\r
+  //\r
+  VmgInit (Ghcb, &InterruptState);\r
+\r
+  //\r
+  // Query the Hypervisor Features.\r
+  //\r
+  Status = VmgExit (Ghcb, SVM_EXIT_HYPERVISOR_FEATURES, 0, 0);\r
+  if ((Status != 0)) {\r
+    SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL);\r
+  }\r
+\r
+  Features = Ghcb->SaveArea.SwExitInfo2;\r
+\r
+  VmgDone (Ghcb, InterruptState);\r
+\r
+  return Features;\r
+}\r
+\r
 /**\r
 \r
   This function can be used to register the GHCB GPA.\r
index bada5ea14439534fce51c82104febc530fdf5884..3c05b550e4bdba5a4a2f51362538d06c7bbccd3d 100644 (file)
@@ -62,6 +62,7 @@
   MtrrLib\r
   MemEncryptSevLib\r
   PcdLib\r
+  VmgExitLib\r
 \r
 [Pcd]\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize\r
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled\r
   gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr\r
+  gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures\r
 \r
 [FixedPcd]\r
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress\r