mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	luto@kernel.org, peterz@infradead.org
Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com,
	ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com,
	hpa@zytor.com, jgross@suse.com, jmattson@google.com,
	joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org,
	pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com,
	tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com,
	thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCHv4 03/30] x86/tdx: Provide common base for SEAMCALL and TDCALL C wrappers
Date: Thu, 24 Feb 2022 08:35:32 -0800	[thread overview]
Message-ID: <faeb3c16-55a9-912d-1222-9dab364f56c7@intel.com> (raw)
In-Reply-To: <20220224155630.52734-4-kirill.shutemov@linux.intel.com>

...
>  arch/x86/include/asm/tdx.h    | 20 ++++++++
>  arch/x86/kernel/asm-offsets.c |  9 ++++
>  arch/x86/virt/tdxcall.S       | 91 +++++++++++++++++++++++++++++++++++
>  3 files changed, 120 insertions(+)
>  create mode 100644 arch/x86/virt/tdxcall.S
> 
> diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
> index ba8042ce61c2..2f8cb1e53e77 100644
> --- a/arch/x86/include/asm/tdx.h
> +++ b/arch/x86/include/asm/tdx.h
> @@ -8,6 +8,25 @@
>  #define TDX_CPUID_LEAF_ID	0x21
>  #define TDX_IDENT		"IntelTDX    "
>  
> +#define TDX_SEAMCALL_VMFAILINVALID     0x8000FF00FFFF0000ULL

This needs a comment.  It's a completely software-defined value, right?

> +#ifndef __ASSEMBLY__
> +
> +/*
> + * Used to gather the output registers values of the TDCALL and SEAMCALL
> + * instructions when requesting services from the TDX module.
> + *
> + * This is a software only structure and not part of the TDX module/VMM ABI.
> + */
> +struct tdx_module_output {
> +	u64 rcx;
> +	u64 rdx;
> +	u64 r8;
> +	u64 r9;
> +	u64 r10;
> +	u64 r11;
> +};
> +
>  #ifdef CONFIG_INTEL_TDX_GUEST
>  
>  void __init tdx_early_init(void);
> @@ -18,4 +37,5 @@ static inline void tdx_early_init(void) { };
>  
>  #endif /* CONFIG_INTEL_TDX_GUEST */
>  
> +#endif /* !__ASSEMBLY__ */
>  #endif /* _ASM_X86_TDX_H */
> diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
> index 9fb0a2f8b62a..7dca52f5cfc6 100644
> --- a/arch/x86/kernel/asm-offsets.c
> +++ b/arch/x86/kernel/asm-offsets.c
> @@ -18,6 +18,7 @@
>  #include <asm/bootparam.h>
>  #include <asm/suspend.h>
>  #include <asm/tlbflush.h>
> +#include <asm/tdx.h>
>  
>  #ifdef CONFIG_XEN
>  #include <xen/interface/xen.h>
> @@ -65,6 +66,14 @@ static void __used common(void)
>  	OFFSET(XEN_vcpu_info_arch_cr2, vcpu_info, arch.cr2);
>  #endif
>  
> +	BLANK();
> +	OFFSET(TDX_MODULE_rcx, tdx_module_output, rcx);
> +	OFFSET(TDX_MODULE_rdx, tdx_module_output, rdx);
> +	OFFSET(TDX_MODULE_r8,  tdx_module_output, r8);
> +	OFFSET(TDX_MODULE_r9,  tdx_module_output, r9);
> +	OFFSET(TDX_MODULE_r10, tdx_module_output, r10);
> +	OFFSET(TDX_MODULE_r11, tdx_module_output, r11);
> +
>  	BLANK();
>  	OFFSET(BP_scratch, boot_params, scratch);
>  	OFFSET(BP_secure_boot, boot_params, secure_boot);
> diff --git a/arch/x86/virt/tdxcall.S b/arch/x86/virt/tdxcall.S
> new file mode 100644
> index 000000000000..90569faedacc
> --- /dev/null
> +++ b/arch/x86/virt/tdxcall.S
> @@ -0,0 +1,91 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#include <asm/asm-offsets.h>
> +#include <asm/tdx.h>
> +
> +/*
> + * TDX guests use the TDCALL instruction to make requests to the
> + * TDX module and hypercalls to the VMM.
> + *
> + * TDX host user SEAMCALL instruction to make requests to TDX module.

		^ uses??


> + * They are supported in Binutils >= 2.36.
> + */

While you're in there, could we make this a little more structured, please?

/*
 * TDX_MODULE_CALL - common helper macro for both
 *		     TDCALL and SEAMCALL instructions.
 * 		
 * TDCALL   - used by TDX guests to make requests to the
 * 	      TDX module and hypercalls to the VMM.
 * SEAMCALL - used by TDX hosts to make requests to the
 *	      TDX module.
 *
 * Both instruction are supported in Binutils >= 2.36.
 */

> +#define tdcall		.byte 0x66,0x0f,0x01,0xcc
> +#define seamcall	.byte 0x66,0x0f,0x01,0xcf
> +
> +.macro TDX_MODULE_CALL host:req
> +	/*
> +	 * R12 will be used as temporary storage for struct tdx_module_output
> +	 * pointer. Since R12-R15 registers are not used by TDCALL/SEAMCALL
> +	 * services supported by this function, it can be reused.
> +	 */
> +
> +	/* Callee saved, so preserve it */
> +	push %r12
> +
> +	/*
> +	 * Push output pointer to stack.
> +	 * After the operation, it will be fetched into R12 register.
> +	 */
> +	push %r9
> +
> +	/* Mangle function call ABI into TDCALL/SEAMCALL ABI: */
> +	/* Move Leaf ID to RAX */
> +	mov %rdi, %rax
> +	/* Move input 4 to R9 */
> +	mov %r8,  %r9
> +	/* Move input 3 to R8 */
> +	mov %rcx, %r8
> +	/* Move input 1 to RCX */
> +	mov %rsi, %rcx
> +	/* Leave input param 2 in RDX */
> +
> +	.if \host
> +	seamcall
> +	/*
> +	 * SEAMCALL instruction is essentially a VMExit from VMX root
> +	 * mode to SEAM VMX root mode.  VMfailInvalid (CF=1) indicates
> +	 * that the targeted SEAM firmware is not loaded or disabled,
> +	 * or P-SEAMLDR is busy with another SEAMCALL.  %rax is not
> +	 * changed in this case.
> +	 *
> +	 * Set %rax to TDX_SEAMCALL_VMFAILINVALID for VMfailInvalid.
> +	 * This value will never be used as actual SEAMCALL error code.
> +	 */

Why can TDX_SEAMCALL_VMFAILINVALID never be used as an actual SEAMCALL
error code?  Would it be more accurate to say that today's P-SEAMLDR and
TDX module never use TDX_SEAMCALL_VMFAILINVALID as an actual SEAMCALL
error code?

There's an important distinction there.  It's possible that the SEAMCALL
instruction architecture says or implies that it can never have
TDX_SEAMCALL_VMFAILINVALID as a return value.  It's also possible that
this "never" comes from a guess about what P-SEAMLDRs or TDX modules can do.

> +	jnc .Lno_vmfailinvalid
> +	mov $TDX_SEAMCALL_VMFAILINVALID, %rax
> +.Lno_vmfailinvalid:
> +	.else
> +	tdcall
> +	.endif
> +
> +	/*
> +	 * Fetch output pointer from stack to R12 (It is used
> +	 * as temporary storage)
> +	 */
> +	pop %r12
> +
> +	/* Check for success: 0 - Successful, otherwise failed */
> +	test %rax, %rax
> +	jnz .Lno_output_struct
> +
> +	/*
> +	 * Since this function can be initiated without an output pointer,
> +	 * check if caller provided an output struct before storing
> +	 * output registers.
> +	 */
> +	test %r12, %r12
> +	jz .Lno_output_struct
> +
> +	/* Copy result registers to output struct: */
> +	movq %rcx, TDX_MODULE_rcx(%r12)
> +	movq %rdx, TDX_MODULE_rdx(%r12)
> +	movq %r8,  TDX_MODULE_r8(%r12)
> +	movq %r9,  TDX_MODULE_r9(%r12)
> +	movq %r10, TDX_MODULE_r10(%r12)
> +	movq %r11, TDX_MODULE_r11(%r12)
> +
> +.Lno_output_struct:
> +	/* Restore the state of R12 register */
> +	pop %r12
> +.endm

That doesn't look too bad.  Please just send an updated version with the
revised comments.

  reply	other threads:[~2022-02-24 16:36 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 15:56 [PATCHv4 00/30] TDX Guest: TDX core support Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 01/30] x86/mm: Fix warning on build with X86_MEM_ENCRYPT=y Kirill A. Shutemov
2022-02-24 16:06   ` Dave Hansen
2022-02-27 22:01   ` Josh Poimboeuf
2022-02-28 16:20     ` Kirill A. Shutemov
2022-02-28 16:40       ` Josh Poimboeuf
2022-02-28 16:51         ` Dave Hansen
2022-02-28 17:11           ` Josh Poimboeuf
2022-03-01  8:48             ` Borislav Petkov
2022-02-24 15:56 ` [PATCHv4 02/30] x86/tdx: Detect running as a TDX guest in early boot Kirill A. Shutemov
2022-02-24 16:16   ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 03/30] x86/tdx: Provide common base for SEAMCALL and TDCALL C wrappers Kirill A. Shutemov
2022-02-24 16:35   ` Dave Hansen [this message]
2022-02-24 23:10     ` Kirill A. Shutemov
2022-02-25  0:41       ` Dave Hansen
2022-02-25 10:39         ` Kai Huang
2022-02-25 15:46         ` Kirill A. Shutemov
2022-02-25 16:12           ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 04/30] x86/tdx: Add __tdx_module_call() and __tdx_hypercall() helper functions Kirill A. Shutemov
2022-02-24 17:01   ` Dave Hansen
2022-02-24 23:29     ` Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 05/30] x86/tdx: Extend the confidential computing API to support TDX guests Kirill A. Shutemov
2022-02-24 17:54   ` Dave Hansen
2022-02-24 23:54     ` Kirill A. Shutemov
2022-02-25  0:51       ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 06/30] x86/tdx: Exclude shared bit from __PHYSICAL_MASK Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 07/30] x86/traps: Add #VE support for TDX guest Kirill A. Shutemov
2022-02-24 18:36   ` Dave Hansen
2022-02-25 19:30     ` Kirill A. Shutemov
2022-02-25 19:46       ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 08/30] x86/tdx: Add HLT support for TDX guests Kirill A. Shutemov
2022-02-24 18:42   ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 09/30] x86/tdx: Add MSR " Kirill A. Shutemov
2022-02-24 18:52   ` Dave Hansen
2022-02-24 19:04     ` Sean Christopherson
2022-02-24 19:36       ` Dave Hansen
2022-02-26 21:35     ` Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 10/30] x86/tdx: Handle CPUID via #VE Kirill A. Shutemov
2022-02-24 19:04   ` Dave Hansen
2022-02-27  1:07     ` Kirill A. Shutemov
2022-02-28 16:41       ` Dave Hansen
2022-02-28 22:53         ` Kirill A. Shutemov
2022-02-28 23:05           ` Dave Hansen
2022-02-28 23:31             ` Kirill A. Shutemov
2022-02-28 23:37               ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 11/30] x86/tdx: Handle in-kernel MMIO Kirill A. Shutemov
2022-02-24 20:11   ` Dave Hansen
2022-02-25  2:23     ` David Laight
2022-02-25  3:10       ` David Laight
2022-03-02 13:42     ` Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 12/30] x86/tdx: Detect TDX at early kernel decompression time Kirill A. Shutemov
2022-02-24 20:44   ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 13/30] x86: Adjust types used in port I/O helpers Kirill A. Shutemov
2022-02-24 21:24   ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 14/30] x86: Consolidate " Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 15/30] x86/boot: Allow to hook up alternative " Kirill A. Shutemov
2022-02-24 22:14   ` Dave Hansen
2022-02-27 22:02   ` Josh Poimboeuf
2022-02-28 16:33     ` Kirill A. Shutemov
2022-02-28 16:44       ` Josh Poimboeuf
2022-02-24 15:56 ` [PATCHv4 16/30] x86/boot/compressed: Support TDX guest port I/O at decompression time Kirill A. Shutemov
2022-02-24 22:22   ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 17/30] x86/tdx: Add port I/O emulation Kirill A. Shutemov
2022-02-24 22:43   ` Dave Hansen
2022-02-25  3:59   ` Dave Hansen
2022-02-28  1:16     ` Kirill A. Shutemov
2022-02-28  4:32       ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 18/30] x86/tdx: Handle early boot port I/O Kirill A. Shutemov
2022-02-24 22:58   ` Dave Hansen
2022-02-24 15:56 ` [PATCHv4 19/30] x86/tdx: Wire up KVM hypercalls Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 20/30] x86/boot: Add a trampoline for booting APs via firmware handoff Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 21/30] x86/acpi, x86/boot: Add multiprocessor wake-up support Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 22/30] x86/boot: Set CR0.NE early and keep it set during the boot Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 23/30] x86/boot: Avoid #VE during boot for TDX platforms Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 24/30] x86/topology: Disable CPU online/offline control for TDX guests Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 25/30] x86/tdx: Make pages shared in ioremap() Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 26/30] x86/mm/cpa: Add support for TDX shared memory Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 27/30] x86/kvm: Use bounce buffers for TD guest Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 28/30] x86/tdx: ioapic: Add shared bit for IOAPIC base address Kirill A. Shutemov
2022-02-24 15:56 ` [PATCHv4 29/30] ACPICA: Avoid cache flush on TDX guest Kirill A. Shutemov
2022-02-27 22:05   ` Josh Poimboeuf
2022-02-28  1:34     ` Dan Williams
2022-02-28 16:37       ` Kirill A. Shutemov
2022-02-28 16:46         ` Dave Hansen
2022-02-28 17:02         ` Josh Poimboeuf
2022-02-24 15:56 ` [PATCHv4 30/30] Documentation/x86: Document TDX kernel architecture Kirill A. Shutemov
2022-02-25 17:42   ` Dave Hansen
2022-02-25 17:54   ` Dave Hansen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=faeb3c16-55a9-912d-1222-9dab364f56c7@intel.com \
    --to=dave.hansen@intel.com \
    --cc=aarcange@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=brijesh.singh@amd.com \
    --cc=dan.j.williams@intel.com \
    --cc=david@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=jpoimboe@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=knsathya@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=sdeep@vmware.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tony.luck@intel.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®