Skip to content

Commit 03a423d

Browse files
kaihuanghansendc
authored andcommitted
x86/tdx: Skip saving output regs when SEAMCALL fails with VMFailInvalid
If SEAMCALL fails with VMFailInvalid, the SEAM software (e.g., the TDX module) won't have chance to set any output register. Skip saving the output registers to the structure in this case. Also, as '.Lno_output_struct' is the very last symbol before RET, rename it to '.Lout' to make it short. Opportunistically make the asm directives unindented. Suggested-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Kai Huang <kai.huang@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/all/704088f5b4d72c7e24084f7f15bd1ac5005b7213.1692096753.git.kai.huang%40intel.com
1 parent 5d092b6 commit 03a423d

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

arch/x86/coco/tdx/tdcall.S

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@
7878
* Return status of TDCALL via RAX.
7979
*/
8080
SYM_FUNC_START(__tdx_module_call)
81-
FRAME_BEGIN
8281
TDX_MODULE_CALL host=0
83-
FRAME_END
84-
RET
8582
SYM_FUNC_END(__tdx_module_call)
8683

8784
/*

arch/x86/virt/vmx/tdx/tdxcall.S

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#include <asm/asm-offsets.h>
3+
#include <asm/frame.h>
34
#include <asm/tdx.h>
45

56
/*
@@ -18,6 +19,7 @@
1819
* TDX module.
1920
*/
2021
.macro TDX_MODULE_CALL host:req
22+
FRAME_BEGIN
2123
/*
2224
* R12 will be used as temporary storage for struct tdx_module_output
2325
* pointer. Since R12-R15 registers are not used by TDCALL/SEAMCALL
@@ -44,7 +46,7 @@
4446
mov %rsi, %rcx
4547
/* Leave input param 2 in RDX */
4648

47-
.if \host
49+
.if \host
4850
seamcall
4951
/*
5052
* SEAMCALL instruction is essentially a VMExit from VMX root
@@ -57,13 +59,10 @@
5759
* This value will never be used as actual SEAMCALL error code as
5860
* it is from the Reserved status code class.
5961
*/
60-
jnc .Lno_vmfailinvalid
61-
mov $TDX_SEAMCALL_VMFAILINVALID, %rax
62-
.Lno_vmfailinvalid:
63-
64-
.else
62+
jc .Lseamcall_vmfailinvalid
63+
.else
6564
tdcall
66-
.endif
65+
.endif
6766

6867
/*
6968
* Fetch output pointer from stack to R12 (It is used
@@ -80,7 +79,7 @@
8079
* Other registers may contain details of the failure.
8180
*/
8281
test %r12, %r12
83-
jz .Lno_output_struct
82+
jz .Lout
8483

8584
/* Copy result registers to output struct: */
8685
movq %rcx, TDX_MODULE_rcx(%r12)
@@ -90,7 +89,19 @@
9089
movq %r10, TDX_MODULE_r10(%r12)
9190
movq %r11, TDX_MODULE_r11(%r12)
9291

93-
.Lno_output_struct:
92+
.Lout:
9493
/* Restore the state of R12 register */
9594
pop %r12
95+
96+
FRAME_END
97+
RET
98+
99+
.if \host
100+
.Lseamcall_vmfailinvalid:
101+
mov $TDX_SEAMCALL_VMFAILINVALID, %rax
102+
/* pop the unused output pointer back to %r9 */
103+
pop %r9
104+
jmp .Lout
105+
.endif /* \host */
106+
96107
.endm

0 commit comments

Comments
 (0)