]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/ResetVector: add the macro to request guest termination
authorBrijesh Singh via groups.io <brijesh.singh=amd.com@groups.io>
Tue, 27 Jul 2021 18:10:24 +0000 (02:10 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 29 Jul 2021 01:04:51 +0000 (01:04 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275

The upcoming SEV-SNP support will need to make a few additional guest
termination requests depending on the failure type. Let's move the logic
to request the guest termination into a macro to keep the code readable.

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: Laszlo Ersek <lersek@redhat.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Acked-by: Ard Biesheuvel <ardb+tianocore@kernel.org>
Suggested-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
OvmfPkg/ResetVector/Ia32/AmdSev.asm

index 93ba917f36d2eb57a1832d9f9ae8f0f60d53bf99..aa95d06eaddb909207e50ebc755d22b62b0a166c 100644 (file)
@@ -38,6 +38,13 @@ BITS    32
 %define SEV_GHCB_MSR                0xc0010130\r
 %define SEV_STATUS_MSR              0xc0010131\r
 \r
+; The #VC was not for CPUID\r
+%define TERM_VC_NOT_CPUID           1\r
+\r
+; The unexpected response code\r
+%define TERM_UNEXPECTED_RESP_CODE   2\r
+\r
+\r
 ; Macro is used to issue the MSR protocol based VMGEXIT. The caller is\r
 ; responsible to populate values in the EDX:EAX registers. After the vmmcall\r
 ; returns, it verifies that the response code matches with the expected\r
@@ -73,6 +80,43 @@ BITS    32
     jne     SevEsUnexpectedRespTerminate\r
 %endmacro\r
 \r
+; Macro to terminate the guest using the VMGEXIT.\r
+; arg 1: reason code\r
+%macro TerminateVmgExit 1\r
+    mov     eax, %1\r
+    ;\r
+    ; Use VMGEXIT to request termination. At this point the reason code is\r
+    ; located in EAX, so shift it left 16 bits to the proper location.\r
+    ;\r
+    ; EAX[11:0]  => 0x100 - request termination\r
+    ; EAX[15:12] => 0x1   - OVMF\r
+    ; EAX[23:16] => 0xXX  - REASON CODE\r
+    ;\r
+    shl     eax, 16\r
+    or      eax, 0x1100\r
+    xor     edx, edx\r
+    mov     ecx, SEV_GHCB_MSR\r
+    wrmsr\r
+    ;\r
+    ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-bit\r
+    ; mode, so work around this by temporarily switching to 64-bit mode.\r
+    ;\r
+BITS    64\r
+    rep     vmmcall\r
+BITS    32\r
+\r
+    ;\r
+    ; We shouldn't come back from the VMGEXIT, but if we do, just loop.\r
+    ;\r
+%%TerminateHlt:\r
+    hlt\r
+    jmp     %%TerminateHlt\r
+%endmacro\r
+\r
+; Terminate the guest due to unexpected response code.\r
+SevEsUnexpectedRespTerminate:\r
+    TerminateVmgExit    TERM_UNEXPECTED_RESP_CODE\r
+\r
 ; Check if Secure Encrypted Virtualization (SEV) features are enabled.\r
 ;\r
 ; Register usage is tight in this routine, so multiple calls for the\r
@@ -227,48 +271,7 @@ SevEsDisabled:
 ;\r
 \r
 SevEsIdtNotCpuid:\r
-    ;\r
-    ; Use VMGEXIT to request termination.\r
-    ;   1 - #VC was not for CPUID\r
-    ;\r
-    mov     eax, 1\r
-    jmp     SevEsIdtTerminate\r
-\r
-SevEsUnexpectedRespTerminate:\r
-    ;\r
-    ; Use VMGEXIT to request termination.\r
-    ;   2 - Unexpected Response is received\r
-    ;\r
-    mov     eax, 2\r
-\r
-SevEsIdtTerminate:\r
-    ;\r
-    ; Use VMGEXIT to request termination. At this point the reason code is\r
-    ; located in EAX, so shift it left 16 bits to the proper location.\r
-    ;\r
-    ; EAX[11:0]  => 0x100 - request termination\r
-    ; EAX[15:12] => 0x1   - OVMF\r
-    ; EAX[23:16] => 0xXX  - REASON CODE\r
-    ;\r
-    shl     eax, 16\r
-    or      eax, 0x1100\r
-    xor     edx, edx\r
-    mov     ecx, SEV_GHCB_MSR\r
-    wrmsr\r
-    ;\r
-    ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-bit\r
-    ; mode, so work around this by temporarily switching to 64-bit mode.\r
-    ;\r
-BITS    64\r
-    rep     vmmcall\r
-BITS    32\r
-\r
-    ;\r
-    ; We shouldn't come back from the VMGEXIT, but if we do, just loop.\r
-    ;\r
-SevEsIdtHlt:\r
-    hlt\r
-    jmp     SevEsIdtHlt\r
+    TerminateVmgExit TERM_VC_NOT_CPUID\r
     iret\r
 \r
     ;\r