[PATCH 02/10] x86/tdx: Use cmovc to save a label in TDX_MODULE_CALL asm

Kai Huang posted 10 patches 2 years, 5 months ago
There is a newer version of this series
[PATCH 02/10] x86/tdx: Use cmovc to save a label in TDX_MODULE_CALL asm
Posted by Kai Huang 2 years, 5 months ago
Change 'jnc .Lno_vmfailinvalid' to 'cmovc %rdi, %rax' to save the
.Lno_vmfailinvalid label in the TDX_MODULE_CALL asm macro.

Note %rdi, which is used as the first argument, has been saved to %rax
as TDCALL leaf ID thus is free to hold the error code for cmovc.

This is basically based on Peter's code.

Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Kai Huang <kai.huang@intel.com>
---
 arch/x86/virt/vmx/tdx/tdxcall.S | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/virt/vmx/tdx/tdxcall.S b/arch/x86/virt/vmx/tdx/tdxcall.S
index 49a54356ae99..3524915d8bd9 100644
--- a/arch/x86/virt/vmx/tdx/tdxcall.S
+++ b/arch/x86/virt/vmx/tdx/tdxcall.S
@@ -57,10 +57,8 @@
 	 * This value will never be used as actual SEAMCALL error code as
 	 * it is from the Reserved status code class.
 	 */
-	jnc .Lno_vmfailinvalid
-	mov $TDX_SEAMCALL_VMFAILINVALID, %rax
-.Lno_vmfailinvalid:
-
+	mov $TDX_SEAMCALL_VMFAILINVALID, %rdi
+	cmovc %rdi, %rax
 	.else
 	tdcall
 	.endif
-- 
2.41.0
Re: [PATCH 02/10] x86/tdx: Use cmovc to save a label in TDX_MODULE_CALL asm
Posted by Sathyanarayanan Kuppuswamy 2 years, 5 months ago

On 7/12/23 1:55 AM, Kai Huang wrote:
> Change 'jnc .Lno_vmfailinvalid' to 'cmovc %rdi, %rax' to save the
> .Lno_vmfailinvalid label in the TDX_MODULE_CALL asm macro.

You are removing the label, right? What use "save"?

> 
> Note %rdi, which is used as the first argument, has been saved to %rax
> as TDCALL leaf ID thus is free to hold the error code for cmovc.

> 
> This is basically based on Peter's code.
> 
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Kai Huang <kai.huang@intel.com>
> ---
>  arch/x86/virt/vmx/tdx/tdxcall.S | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/virt/vmx/tdx/tdxcall.S b/arch/x86/virt/vmx/tdx/tdxcall.S
> index 49a54356ae99..3524915d8bd9 100644
> --- a/arch/x86/virt/vmx/tdx/tdxcall.S
> +++ b/arch/x86/virt/vmx/tdx/tdxcall.S
> @@ -57,10 +57,8 @@
>  	 * This value will never be used as actual SEAMCALL error code as
>  	 * it is from the Reserved status code class.
>  	 */
> -	jnc .Lno_vmfailinvalid
> -	mov $TDX_SEAMCALL_VMFAILINVALID, %rax
> -.Lno_vmfailinvalid:
> -
> +	mov $TDX_SEAMCALL_VMFAILINVALID, %rdi
> +	cmovc %rdi, %rax
>  	.else
>  	tdcall
>  	.endif

-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
Re: [PATCH 02/10] x86/tdx: Use cmovc to save a label in TDX_MODULE_CALL asm
Posted by Huang, Kai 2 years, 5 months ago
On Wed, 2023-07-12 at 12:27 -0700, Sathyanarayanan Kuppuswamy wrote:
> 
> On 7/12/23 1:55 AM, Kai Huang wrote:
> > Change 'jnc .Lno_vmfailinvalid' to 'cmovc %rdi, %rax' to save the
> > .Lno_vmfailinvalid label in the TDX_MODULE_CALL asm macro.
> 
> You are removing the label, right? What use "save"?
 
Per comments to patch 10 I'll drop this patch, so doesn't matter anymore.