Skip to content

Commit c30c4b2

Browse files
kirylhansendc
authored andcommitted
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 <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Link: https://lore.kernel.org/all/20230126221159.8635-4-kirill.shutemov%40linux.intel.com
1 parent 0da908c commit c30c4b2

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

arch/x86/coco/tdx/tdcall.S

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,26 @@ SYM_FUNC_START(__tdx_hypercall)
124124
push %r14
125125
push %r13
126126
push %r12
127+
push %rbp
128+
129+
/* Free RDI and RSI to be used as TDVMCALL arguments */
130+
movq %rdi, %rax
131+
movq %rsi, %rbp
132+
133+
/* Copy hypercall registers from arg struct: */
134+
movq TDX_HYPERCALL_r10(%rax), %r10
135+
movq TDX_HYPERCALL_r11(%rax), %r11
136+
movq TDX_HYPERCALL_r12(%rax), %r12
137+
movq TDX_HYPERCALL_r13(%rax), %r13
138+
movq TDX_HYPERCALL_r14(%rax), %r14
139+
movq TDX_HYPERCALL_r15(%rax), %r15
140+
141+
push %rax
127142

128143
/* Mangle function call ABI into TDCALL ABI: */
129144
/* Set TDCALL leaf ID (TDVMCALL (0)) in RAX */
130145
xor %eax, %eax
131146

132-
/* Copy hypercall registers from arg struct: */
133-
movq TDX_HYPERCALL_r10(%rdi), %r10
134-
movq TDX_HYPERCALL_r11(%rdi), %r11
135-
movq TDX_HYPERCALL_r12(%rdi), %r12
136-
movq TDX_HYPERCALL_r13(%rdi), %r13
137-
movq TDX_HYPERCALL_r14(%rdi), %r14
138-
movq TDX_HYPERCALL_r15(%rdi), %r15
139-
140147
movl $TDVMCALL_EXPOSE_REGS_MASK, %ecx
141148

142149
/*
@@ -148,7 +155,7 @@ SYM_FUNC_START(__tdx_hypercall)
148155
* HLT operation indefinitely. Since this is the not the desired
149156
* result, conditionally call STI before TDCALL.
150157
*/
151-
testq $TDX_HCALL_ISSUE_STI, %rsi
158+
testq $TDX_HCALL_ISSUE_STI, %rbp
152159
jz .Lskip_sti
153160
sti
154161
.Lskip_sti:
@@ -165,20 +172,22 @@ SYM_FUNC_START(__tdx_hypercall)
165172
testq %rax, %rax
166173
jne .Lpanic
167174

168-
/* TDVMCALL leaf return code is in R10 */
169-
movq %r10, %rax
175+
pop %rax
170176

171177
/* Copy hypercall result registers to arg struct if needed */
172-
testq $TDX_HCALL_HAS_OUTPUT, %rsi
178+
testq $TDX_HCALL_HAS_OUTPUT, %rbp
173179
jz .Lout
174180

175-
movq %r10, TDX_HYPERCALL_r10(%rdi)
176-
movq %r11, TDX_HYPERCALL_r11(%rdi)
177-
movq %r12, TDX_HYPERCALL_r12(%rdi)
178-
movq %r13, TDX_HYPERCALL_r13(%rdi)
179-
movq %r14, TDX_HYPERCALL_r14(%rdi)
180-
movq %r15, TDX_HYPERCALL_r15(%rdi)
181+
movq %r10, TDX_HYPERCALL_r10(%rax)
182+
movq %r11, TDX_HYPERCALL_r11(%rax)
183+
movq %r12, TDX_HYPERCALL_r12(%rax)
184+
movq %r13, TDX_HYPERCALL_r13(%rax)
185+
movq %r14, TDX_HYPERCALL_r14(%rax)
186+
movq %r15, TDX_HYPERCALL_r15(%rax)
181187
.Lout:
188+
/* TDVMCALL leaf return code is in R10 */
189+
movq %r10, %rax
190+
182191
/*
183192
* Zero out registers exposed to the VMM to avoid speculative execution
184193
* with VMM-controlled values. This needs to include all registers
@@ -189,6 +198,7 @@ SYM_FUNC_START(__tdx_hypercall)
189198
xor %r11d, %r11d
190199

191200
/* Restore callee-saved GPRs as mandated by the x86_64 ABI */
201+
pop %rbp
192202
pop %r12
193203
pop %r13
194204
pop %r14

0 commit comments

Comments
 (0)