]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: Enable APs to accept memory for TDVF
authorMin M Xu <min.m.xu@intel.com>
Tue, 20 Dec 2022 08:42:39 +0000 (16:42 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 21 Dec 2022 07:06:17 +0000 (07:06 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4172

TDVF APs once did nothing but spin around to wait for the Wakeup command.
This patch enables APs to handle the AcceptPages command. Once APs find
the AcceptPages command, it set its stack and jump to the function of
ApAcceptMemoryResourceRange (which will be introduced in the following
patch).

Cc: Erdem Aktas <erdemaktas@google.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
OvmfPkg/Include/TdxCommondefs.inc
OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm

index 970eac96592a0a821579ee81827497cb2172dc8d..a29d2fad42335a117b3f67f56cc4702daff40d2b 100644 (file)
@@ -15,8 +15,8 @@ FirmwareArgsOffset                        equ       800h
 WakeupArgsRelocatedMailBox                equ       800h\r
 AcceptPageArgsPhysicalStart               equ       800h\r
 AcceptPageArgsPhysicalEnd                 equ       808h\r
-AcceptPageArgsChunkSize                   equ       810h\r
-AcceptPageArgsPageSize                    equ       818h\r
+AcceptPageArgsTopStackAddress             equ       810h\r
+AcceptPageArgsApStackSize                 equ       818h\r
 CpuArrivalOffset                          equ       900h\r
 CpusExitingOffset                         equ       0a00h\r
 TalliesOffset                             equ       0a08h\r
index 034ac0ee9421dcbd51ae9d1e3c6b5b917d3efb59..4a984ecc10588e1190d298686c3949b454851dcc 100644 (file)
@@ -40,9 +40,70 @@ do_wait_loop:
     cmp     eax, MpProtectedModeWakeupCommandWakeup\r
     je      .do_wakeup\r
 \r
+    cmp     eax, MpProtectedModeWakeupCommandAcceptPages\r
+    je      .do_accept_pages\r
+\r
     ; Don't support this command, so ignore\r
     jmp     .check_command\r
 \r
+.do_accept_pages:\r
+    ;\r
+    ; Read the top stack address from arguments\r
+    mov     rsi, [rsp + AcceptPageArgsTopStackAddress]\r
+\r
+    ;\r
+    ; Calculate the top stack address of the AP.\r
+    ; ApStackAddr = BaseStackAddr + (vCpuIndex) * ApStackSize\r
+    xor     rdx, rdx\r
+    xor     rbx, rbx\r
+    xor     rax, rax\r
+    mov     eax, [rsp + AcceptPageArgsApStackSize]\r
+    mov     ebx, r9d    ; vCpuIndex\r
+    mul     ebx\r
+    add     rsi, rax    ; now rsi is ApStackAddr\r
+\r
+.start_accept_pages:\r
+    ;\r
+    ; Read the function address which will be called\r
+    mov     rax, [rsp + WakeupVectorOffset]\r
+\r
+    ;\r
+    ; vCPU index as the first argument\r
+    mov     ecx, r9d\r
+    mov     rdx, [rsp + AcceptPageArgsPhysicalStart]\r
+    mov     r8, [rsp + AcceptPageArgsPhysicalEnd]\r
+\r
+    ; save the Mailbox address to rbx\r
+    mov     rbx, rsp\r
+\r
+    ;\r
+    ; set AP Stack\r
+    mov     rsp, rsi\r
+    nop\r
+\r
+    ; save rax (the Mailbox address)\r
+    push    rbx\r
+\r
+    call    rax\r
+\r
+    ; recove rsp\r
+    pop     rbx\r
+    mov     rsp, rbx\r
+    ;\r
+    ; recover r8, r9\r
+    mov     rax, 1\r
+    tdcall\r
+\r
+    mov     eax, 0FFFFFFFFh\r
+    lock xadd dword [rsp + CpusExitingOffset], eax\r
+    dec     eax\r
+\r
+.check_exiting_cnt:\r
+    cmp     eax, 0\r
+    je      do_wait_loop\r
+    mov     eax, dword[rsp + CpusExitingOffset]\r
+    jmp     .check_exiting_cnt\r
+\r
 .do_wakeup:\r
     ;\r
     ; BSP sets these variables before unblocking APs\r