]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/ResetVector: pre-validate the data pages used in SEC phase
authorBrijesh Singh via groups.io <brijesh.singh=amd.com@groups.io>
Thu, 9 Dec 2021 03:27:35 +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

An SEV-SNP guest requires that private memory (aka pages mapped encrypted)
must be validated before being accessed.

The validation process consist of the following sequence:

1) Set the memory encryption attribute in the page table (aka C-bit).
   Note: If the processor is in non-PAE mode, then all the memory accesses
   are considered private.
2) Add the memory range as private in the RMP table. This can be performed
   using the Page State Change VMGEXIT defined in the GHCB specification.
3) Use the PVALIDATE instruction to set the Validated Bit in the RMP table.

During the guest creation time, the VMM encrypts the OVMF_CODE.fd using
the SEV-SNP firmware provided LAUNCH_UPDATE_DATA command. In addition to
encrypting the content, the command also validates the memory region.
This allows us to execute the code without going through the validation
sequence.

During execution, the reset vector need to access some data pages
(such as page tables, SevESWorkarea, Sec stack). The data pages are
accessed as private memory. The data pages are not part of the
OVMF_CODE.fd, so they were not validated during the guest creation.

There are two approaches we can take to validate the data pages before
the access:

a) Enhance the OVMF reset vector code to validate the pages as described
   above (go through step 2 - 3).
OR
b) Validate the pages during the guest creation time. The SEV firmware
   provides a command which can be used by the VMM to validate the pages
   without affecting the measurement of the launch.

Approach #b seems much simpler; it does not require any changes to the
OVMF reset vector code.

Update the OVMF metadata with the list of regions that must be
pre-validated by the VMM before the boot.

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: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
OvmfPkg/ResetVector/ResetVector.inf
OvmfPkg/ResetVector/ResetVector.nasmb
OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm

index 1c5d84184ed715a0a510c28908bec72549413c64..a4154ca90c28d6deee1f92e23136b837ae50a7ac 100644 (file)
@@ -57,6 +57,7 @@
 [FixedPcd]\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase\r
   gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase\r
   gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize\r
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase\r
index fbaeab5f5168c848333471cb4e640455c08d6600..cc364748b5925c9bde013ac972b1ab3ca8f72fb8 100644 (file)
   %define SEV_SNP_SECRETS_SIZE  (FixedPcdGet32 (PcdOvmfSnpSecretsSize))\r
   %define CPUID_BASE  (FixedPcdGet32 (PcdOvmfCpuidBase))\r
   %define CPUID_SIZE  (FixedPcdGet32 (PcdOvmfCpuidSize))\r
+  %define SNP_SEC_MEM_BASE_DESC_1 (FixedPcdGet32 (PcdOvmfSecPageTablesBase))\r
+  %define SNP_SEC_MEM_SIZE_DESC_1 (FixedPcdGet32 (PcdOvmfSecGhcbBase) - SNP_SEC_MEM_BASE_DESC_1)\r
+  ;\r
+  ; The PcdOvmfSecGhcbBase reserves two GHCB pages. The first page is used\r
+  ; as GHCB shared page and second is used for bookkeeping to support the\r
+  ; nested GHCB in SEC phase. The bookkeeping page is mapped private. The VMM\r
+  ; does not need to validate the shared page but it need to validate the\r
+  ; bookkeeping page.\r
+  ;\r
+  %define SNP_SEC_MEM_BASE_DESC_2 (GHCB_BASE + 0x1000)\r
+  %define SNP_SEC_MEM_SIZE_DESC_2 (SEV_SNP_SECRETS_BASE - SNP_SEC_MEM_BASE_DESC_2)\r
+  %define SNP_SEC_MEM_BASE_DESC_3 (CPUID_BASE + CPUID_SIZE)\r
+  %define SNP_SEC_MEM_SIZE_DESC_3 (FixedPcdGet32 (PcdOvmfPeiMemFvBase) - SNP_SEC_MEM_BASE_DESC_3)\r
 \r
 %include "X64/IntelTdxMetadata.asm"\r
 %include "Ia32/Flat32ToFlat64.asm"\r
index 0cc12ad3473f183ef6ff4e8d2e721023a8cd149f..d03fc6d45175070a74c8a8410340d77a3e5a4bda 100644 (file)
@@ -43,6 +43,16 @@ _DescriptorSev:
   DD OVMF_SEV_METADATA_VERSION                              ; Version\r
   DD (OvmfSevGuidedStructureEnd - _DescriptorSev - 16) / 12 ; Number of sections\r
 \r
+; Region need to be pre-validated by the hypervisor\r
+PreValidate1:\r
+  DD  SNP_SEC_MEM_BASE_DESC_1\r
+  DD  SNP_SEC_MEM_SIZE_DESC_1\r
+  DD  OVMF_SECTION_TYPE_SNP_SEC_MEM\r
+PreValidate2:\r
+  DD  SNP_SEC_MEM_BASE_DESC_2\r
+  DD  SNP_SEC_MEM_SIZE_DESC_2\r
+  DD  OVMF_SECTION_TYPE_SNP_SEC_MEM\r
+\r
 ; SEV-SNP Secrets page\r
 SevSnpSecrets:\r
   DD  SEV_SNP_SECRETS_BASE\r
@@ -55,5 +65,10 @@ CpuidSec:
   DD  CPUID_SIZE\r
   DD  OVMF_SECTION_TYPE_CPUID\r
 \r
+; Region need to be pre-validated by the hypervisor\r
+PreValidate3:\r
+  DD  SNP_SEC_MEM_BASE_DESC_3\r
+  DD  SNP_SEC_MEM_SIZE_DESC_3\r
+  DD  OVMF_SECTION_TYPE_SNP_SEC_MEM\r
 OvmfSevGuidedStructureEnd:\r
   ALIGN   16\r