Commit 03a423d4 authored by Kai Huang's avatar Kai Huang Committed by Dave Hansen

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: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarKai Huang <kai.huang@intel.com>
Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/704088f5b4d72c7e24084f7f15bd1ac5005b7213.1692096753.git.kai.huang%40intel.com
parent 5d092b66
...@@ -78,10 +78,7 @@ ...@@ -78,10 +78,7 @@
* Return status of TDCALL via RAX. * Return status of TDCALL via RAX.
*/ */
SYM_FUNC_START(__tdx_module_call) SYM_FUNC_START(__tdx_module_call)
FRAME_BEGIN
TDX_MODULE_CALL host=0 TDX_MODULE_CALL host=0
FRAME_END
RET
SYM_FUNC_END(__tdx_module_call) SYM_FUNC_END(__tdx_module_call)
/* /*
......
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#include <asm/asm-offsets.h> #include <asm/asm-offsets.h>
#include <asm/frame.h>
#include <asm/tdx.h> #include <asm/tdx.h>
/* /*
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
* TDX module. * TDX module.
*/ */
.macro TDX_MODULE_CALL host:req .macro TDX_MODULE_CALL host:req
FRAME_BEGIN
/* /*
* R12 will be used as temporary storage for struct tdx_module_output * R12 will be used as temporary storage for struct tdx_module_output
* pointer. Since R12-R15 registers are not used by TDCALL/SEAMCALL * pointer. Since R12-R15 registers are not used by TDCALL/SEAMCALL
...@@ -44,7 +46,7 @@ ...@@ -44,7 +46,7 @@
mov %rsi, %rcx mov %rsi, %rcx
/* Leave input param 2 in RDX */ /* Leave input param 2 in RDX */
.if \host .if \host
seamcall seamcall
/* /*
* SEAMCALL instruction is essentially a VMExit from VMX root * SEAMCALL instruction is essentially a VMExit from VMX root
...@@ -57,13 +59,10 @@ ...@@ -57,13 +59,10 @@
* This value will never be used as actual SEAMCALL error code as * This value will never be used as actual SEAMCALL error code as
* it is from the Reserved status code class. * it is from the Reserved status code class.
*/ */
jnc .Lno_vmfailinvalid jc .Lseamcall_vmfailinvalid
mov $TDX_SEAMCALL_VMFAILINVALID, %rax .else
.Lno_vmfailinvalid:
.else
tdcall tdcall
.endif .endif
/* /*
* Fetch output pointer from stack to R12 (It is used * Fetch output pointer from stack to R12 (It is used
...@@ -80,7 +79,7 @@ ...@@ -80,7 +79,7 @@
* Other registers may contain details of the failure. * Other registers may contain details of the failure.
*/ */
test %r12, %r12 test %r12, %r12
jz .Lno_output_struct jz .Lout
/* Copy result registers to output struct: */ /* Copy result registers to output struct: */
movq %rcx, TDX_MODULE_rcx(%r12) movq %rcx, TDX_MODULE_rcx(%r12)
...@@ -90,7 +89,19 @@ ...@@ -90,7 +89,19 @@
movq %r10, TDX_MODULE_r10(%r12) movq %r10, TDX_MODULE_r10(%r12)
movq %r11, TDX_MODULE_r11(%r12) movq %r11, TDX_MODULE_r11(%r12)
.Lno_output_struct: .Lout:
/* Restore the state of R12 register */ /* Restore the state of R12 register */
pop %r12 pop %r12
FRAME_END
RET
.if \host
.Lseamcall_vmfailinvalid:
mov $TDX_SEAMCALL_VMFAILINVALID, %rax
/* pop the unused output pointer back to %r9 */
pop %r9
jmp .Lout
.endif /* \host */
.endm .endm
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment