x86/tdx: Refactor __tdx_hypercall() to allow pass down more arguments
RDI is the first argument to __tdx_hypercall() that used to pass pointer to struct tdx_hypercall_args. RSI is the second argument that contains flags, such as TDX_HCALL_HAS_OUTPUT and TDX_HCALL_ISSUE_STI. RDI and RSI can also be used as arguments to TDVMCALL leafs. Move RDI to RAX and RSI to RBP to free up them for the hypercall arguments. RAX saved on stack during TDCALL as it returns status code in the register. RBP value has to be restored before returning from __tdx_hypercall() as it is callee-saved register. This is preparatory patch. No functional change. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://lore.kernel.org/all/20230126221159.8635-4-kirill.shutemov%40linux.intel.com
This commit is contained in:
parent
0da908c291
commit
c30c4b2555
1 changed files with 30 additions and 20 deletions
|
@ -124,19 +124,26 @@ SYM_FUNC_START(__tdx_hypercall)
|
||||||
push %r14
|
push %r14
|
||||||
push %r13
|
push %r13
|
||||||
push %r12
|
push %r12
|
||||||
|
push %rbp
|
||||||
|
|
||||||
|
/* Free RDI and RSI to be used as TDVMCALL arguments */
|
||||||
|
movq %rdi, %rax
|
||||||
|
movq %rsi, %rbp
|
||||||
|
|
||||||
|
/* Copy hypercall registers from arg struct: */
|
||||||
|
movq TDX_HYPERCALL_r10(%rax), %r10
|
||||||
|
movq TDX_HYPERCALL_r11(%rax), %r11
|
||||||
|
movq TDX_HYPERCALL_r12(%rax), %r12
|
||||||
|
movq TDX_HYPERCALL_r13(%rax), %r13
|
||||||
|
movq TDX_HYPERCALL_r14(%rax), %r14
|
||||||
|
movq TDX_HYPERCALL_r15(%rax), %r15
|
||||||
|
|
||||||
|
push %rax
|
||||||
|
|
||||||
/* Mangle function call ABI into TDCALL ABI: */
|
/* Mangle function call ABI into TDCALL ABI: */
|
||||||
/* Set TDCALL leaf ID (TDVMCALL (0)) in RAX */
|
/* Set TDCALL leaf ID (TDVMCALL (0)) in RAX */
|
||||||
xor %eax, %eax
|
xor %eax, %eax
|
||||||
|
|
||||||
/* Copy hypercall registers from arg struct: */
|
|
||||||
movq TDX_HYPERCALL_r10(%rdi), %r10
|
|
||||||
movq TDX_HYPERCALL_r11(%rdi), %r11
|
|
||||||
movq TDX_HYPERCALL_r12(%rdi), %r12
|
|
||||||
movq TDX_HYPERCALL_r13(%rdi), %r13
|
|
||||||
movq TDX_HYPERCALL_r14(%rdi), %r14
|
|
||||||
movq TDX_HYPERCALL_r15(%rdi), %r15
|
|
||||||
|
|
||||||
movl $TDVMCALL_EXPOSE_REGS_MASK, %ecx
|
movl $TDVMCALL_EXPOSE_REGS_MASK, %ecx
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -148,7 +155,7 @@ SYM_FUNC_START(__tdx_hypercall)
|
||||||
* HLT operation indefinitely. Since this is the not the desired
|
* HLT operation indefinitely. Since this is the not the desired
|
||||||
* result, conditionally call STI before TDCALL.
|
* result, conditionally call STI before TDCALL.
|
||||||
*/
|
*/
|
||||||
testq $TDX_HCALL_ISSUE_STI, %rsi
|
testq $TDX_HCALL_ISSUE_STI, %rbp
|
||||||
jz .Lskip_sti
|
jz .Lskip_sti
|
||||||
sti
|
sti
|
||||||
.Lskip_sti:
|
.Lskip_sti:
|
||||||
|
@ -165,20 +172,22 @@ SYM_FUNC_START(__tdx_hypercall)
|
||||||
testq %rax, %rax
|
testq %rax, %rax
|
||||||
jne .Lpanic
|
jne .Lpanic
|
||||||
|
|
||||||
|
pop %rax
|
||||||
|
|
||||||
|
/* Copy hypercall result registers to arg struct if needed */
|
||||||
|
testq $TDX_HCALL_HAS_OUTPUT, %rbp
|
||||||
|
jz .Lout
|
||||||
|
|
||||||
|
movq %r10, TDX_HYPERCALL_r10(%rax)
|
||||||
|
movq %r11, TDX_HYPERCALL_r11(%rax)
|
||||||
|
movq %r12, TDX_HYPERCALL_r12(%rax)
|
||||||
|
movq %r13, TDX_HYPERCALL_r13(%rax)
|
||||||
|
movq %r14, TDX_HYPERCALL_r14(%rax)
|
||||||
|
movq %r15, TDX_HYPERCALL_r15(%rax)
|
||||||
|
.Lout:
|
||||||
/* TDVMCALL leaf return code is in R10 */
|
/* TDVMCALL leaf return code is in R10 */
|
||||||
movq %r10, %rax
|
movq %r10, %rax
|
||||||
|
|
||||||
/* Copy hypercall result registers to arg struct if needed */
|
|
||||||
testq $TDX_HCALL_HAS_OUTPUT, %rsi
|
|
||||||
jz .Lout
|
|
||||||
|
|
||||||
movq %r10, TDX_HYPERCALL_r10(%rdi)
|
|
||||||
movq %r11, TDX_HYPERCALL_r11(%rdi)
|
|
||||||
movq %r12, TDX_HYPERCALL_r12(%rdi)
|
|
||||||
movq %r13, TDX_HYPERCALL_r13(%rdi)
|
|
||||||
movq %r14, TDX_HYPERCALL_r14(%rdi)
|
|
||||||
movq %r15, TDX_HYPERCALL_r15(%rdi)
|
|
||||||
.Lout:
|
|
||||||
/*
|
/*
|
||||||
* Zero out registers exposed to the VMM to avoid speculative execution
|
* Zero out registers exposed to the VMM to avoid speculative execution
|
||||||
* with VMM-controlled values. This needs to include all registers
|
* with VMM-controlled values. This needs to include all registers
|
||||||
|
@ -189,6 +198,7 @@ SYM_FUNC_START(__tdx_hypercall)
|
||||||
xor %r11d, %r11d
|
xor %r11d, %r11d
|
||||||
|
|
||||||
/* Restore callee-saved GPRs as mandated by the x86_64 ABI */
|
/* Restore callee-saved GPRs as mandated by the x86_64 ABI */
|
||||||
|
pop %rbp
|
||||||
pop %r12
|
pop %r12
|
||||||
pop %r13
|
pop %r13
|
||||||
pop %r14
|
pop %r14
|
||||||
|
|
Loading…
Add table
Reference in a new issue