Skip to content

Commit 752d133

Browse files
kirylhansendc
authored andcommitted
x86/tdx: Expand __tdx_hypercall() to handle more arguments
So far __tdx_hypercall() only handles six arguments for VMCALL. Expanding it to six more register would allow to cover more use-cases like ReportFatalError() and Hyper-V hypercalls. With all preparations in place, the expansion is pretty straight forward. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Link: https://lore.kernel.org/all/20230126221159.8635-5-kirill.shutemov%40linux.intel.com
1 parent c30c4b2 commit 752d133

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

arch/x86/coco/tdx/tdcall.S

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
/*
1414
* Bitmasks of exposed registers (with VMM).
1515
*/
16+
#define TDX_RDX BIT(2)
17+
#define TDX_RBX BIT(3)
18+
#define TDX_RSI BIT(6)
19+
#define TDX_RDI BIT(7)
20+
#define TDX_R8 BIT(8)
21+
#define TDX_R9 BIT(9)
1622
#define TDX_R10 BIT(10)
1723
#define TDX_R11 BIT(11)
1824
#define TDX_R12 BIT(12)
@@ -27,9 +33,9 @@
2733
* details can be found in TDX GHCI specification, section
2834
* titled "TDCALL [TDG.VP.VMCALL] leaf".
2935
*/
30-
#define TDVMCALL_EXPOSE_REGS_MASK ( TDX_R10 | TDX_R11 | \
31-
TDX_R12 | TDX_R13 | \
32-
TDX_R14 | TDX_R15 )
36+
#define TDVMCALL_EXPOSE_REGS_MASK \
37+
( TDX_RDX | TDX_RBX | TDX_RSI | TDX_RDI | TDX_R8 | TDX_R9 | \
38+
TDX_R10 | TDX_R11 | TDX_R12 | TDX_R13 | TDX_R14 | TDX_R15 )
3339

3440
/*
3541
* __tdx_module_call() - Used by TDX guests to request services from
@@ -124,19 +130,26 @@ SYM_FUNC_START(__tdx_hypercall)
124130
push %r14
125131
push %r13
126132
push %r12
133+
push %rbx
127134
push %rbp
128135

129136
/* Free RDI and RSI to be used as TDVMCALL arguments */
130137
movq %rdi, %rax
131138
movq %rsi, %rbp
132139

133140
/* Copy hypercall registers from arg struct: */
141+
movq TDX_HYPERCALL_r8(%rax), %r8
142+
movq TDX_HYPERCALL_r9(%rax), %r9
134143
movq TDX_HYPERCALL_r10(%rax), %r10
135144
movq TDX_HYPERCALL_r11(%rax), %r11
136145
movq TDX_HYPERCALL_r12(%rax), %r12
137146
movq TDX_HYPERCALL_r13(%rax), %r13
138147
movq TDX_HYPERCALL_r14(%rax), %r14
139148
movq TDX_HYPERCALL_r15(%rax), %r15
149+
movq TDX_HYPERCALL_rdi(%rax), %rdi
150+
movq TDX_HYPERCALL_rsi(%rax), %rsi
151+
movq TDX_HYPERCALL_rbx(%rax), %rbx
152+
movq TDX_HYPERCALL_rdx(%rax), %rdx
140153

141154
push %rax
142155

@@ -178,27 +191,39 @@ SYM_FUNC_START(__tdx_hypercall)
178191
testq $TDX_HCALL_HAS_OUTPUT, %rbp
179192
jz .Lout
180193

194+
movq %r8, TDX_HYPERCALL_r8(%rax)
195+
movq %r9, TDX_HYPERCALL_r9(%rax)
181196
movq %r10, TDX_HYPERCALL_r10(%rax)
182197
movq %r11, TDX_HYPERCALL_r11(%rax)
183198
movq %r12, TDX_HYPERCALL_r12(%rax)
184199
movq %r13, TDX_HYPERCALL_r13(%rax)
185200
movq %r14, TDX_HYPERCALL_r14(%rax)
186201
movq %r15, TDX_HYPERCALL_r15(%rax)
202+
movq %rdi, TDX_HYPERCALL_rdi(%rax)
203+
movq %rsi, TDX_HYPERCALL_rsi(%rax)
204+
movq %rbx, TDX_HYPERCALL_rbx(%rax)
205+
movq %rdx, TDX_HYPERCALL_rdx(%rax)
187206
.Lout:
188207
/* TDVMCALL leaf return code is in R10 */
189208
movq %r10, %rax
190209

191210
/*
192211
* Zero out registers exposed to the VMM to avoid speculative execution
193212
* with VMM-controlled values. This needs to include all registers
194-
* present in TDVMCALL_EXPOSE_REGS_MASK (except R12-R15). R12-R15
195-
* context will be restored.
213+
* present in TDVMCALL_EXPOSE_REGS_MASK, except RBX, and R12-R15 which
214+
* will be restored.
196215
*/
216+
xor %r8d, %r8d
217+
xor %r9d, %r9d
197218
xor %r10d, %r10d
198219
xor %r11d, %r11d
220+
xor %rdi, %rdi
221+
xor %rsi, %rsi
222+
xor %rdx, %rdx
199223

200224
/* Restore callee-saved GPRs as mandated by the x86_64 ABI */
201225
pop %rbp
226+
pop %rbx
202227
pop %r12
203228
pop %r13
204229
pop %r14

0 commit comments

Comments
 (0)