Re: [PATCH v18 001/121] x86/virt/tdx: Export TDX KeyID information

From: Yuan Yao
Date: Wed Jan 31 2024 - 20:57:50 EST


On Mon, Jan 22, 2024 at 03:52:37PM -0800, isaku.yamahata@xxxxxxxxx wrote:
> From: Kai Huang <kai.huang@xxxxxxxxx>
>
> Each TDX guest must be protected by its own unique TDX KeyID. KVM will
> need to tell the TDX module the unique KeyID for a TDX guest when KVM
> creates it.
>
> Export the TDX KeyID range that can be used by TDX guests for KVM to
> use. KVM can then manage these KeyIDs and assign one for each TDX guest
> when it is created.
>
> Each TDX guest has a root control structure called "Trust Domain Root"
> (TDR). Unlike the rest of the TDX guest, the TDR is protected by the
> TDX global KeyID. When tearing down the TDR, KVM will need to pass the
> TDX global KeyID explicitly to the TDX module to flush cache associated
> to the TDR.
>
> Also export the TDX global KeyID for KVM to tear down the TDR.
>
> Signed-off-by: Kai Huang <kai.huang@xxxxxxxxx>

The variables exported by this patch are used first time in patch 18 IIUC...
So how about move this one just before the patch 18 ?

> ---
> arch/x86/include/asm/tdx.h | 5 +++++
> arch/x86/virt/vmx/tdx/tdx.c | 11 ++++++++---
> 2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
> index 4595fbe4639b..4e219fc2e8ee 100644
> --- a/arch/x86/include/asm/tdx.h
> +++ b/arch/x86/include/asm/tdx.h
> @@ -88,6 +88,11 @@ static inline long tdx_kvm_hypercall(unsigned int nr, unsigned long p1,
> #endif /* CONFIG_INTEL_TDX_GUEST && CONFIG_KVM_GUEST */
>
> #ifdef CONFIG_INTEL_TDX_HOST
> +
> +extern u32 tdx_global_keyid;
> +extern u32 tdx_guest_keyid_start;
> +extern u32 tdx_nr_guest_keyids;
> +
> u64 __seamcall(u64 fn, struct tdx_module_args *args);
> u64 __seamcall_ret(u64 fn, struct tdx_module_args *args);
> u64 __seamcall_saved_ret(u64 fn, struct tdx_module_args *args);
> diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> index 06fbd0b9ea29..14e068ee2640 100644
> --- a/arch/x86/virt/vmx/tdx/tdx.c
> +++ b/arch/x86/virt/vmx/tdx/tdx.c
> @@ -39,9 +39,14 @@
> #include <asm/mce.h>
> #include "tdx.h"
>
> -static u32 tdx_global_keyid __ro_after_init;
> -static u32 tdx_guest_keyid_start __ro_after_init;
> -static u32 tdx_nr_guest_keyids __ro_after_init;
> +u32 tdx_global_keyid __ro_after_init;
> +EXPORT_SYMBOL_GPL(tdx_global_keyid);
> +
> +u32 tdx_guest_keyid_start __ro_after_init;
> +EXPORT_SYMBOL_GPL(tdx_guest_keyid_start);
> +
> +u32 tdx_nr_guest_keyids __ro_after_init;
> +EXPORT_SYMBOL_GPL(tdx_nr_guest_keyids);
>
> static DEFINE_PER_CPU(bool, tdx_lp_initialized);
>
> --
> 2.25.1
>
>