diff mbox series

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

Message ID fed47cd35b32ee66f7ec55bdda6ccab12c139e85.1705965634.git.isaku.yamahata@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM TDX basic feature support | expand

Commit Message

Isaku Yamahata Jan. 22, 2024, 11:52 p.m. UTC
From: Kai Huang <kai.huang@intel.com>

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@intel.com>
---
 arch/x86/include/asm/tdx.h  |  5 +++++
 arch/x86/virt/vmx/tdx/tdx.c | 11 ++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

Comments

Yuan Yao Feb. 1, 2024, 1:57 a.m. UTC | #1
On Mon, Jan 22, 2024 at 03:52:37PM -0800, isaku.yamahata@intel.com wrote:
> From: Kai Huang <kai.huang@intel.com>
>
> 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@intel.com>

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
>
>
Isaku Yamahata Feb. 26, 2024, 6:46 p.m. UTC | #2
On Thu, Feb 01, 2024 at 09:57:29AM +0800,
Yuan Yao <yuan.yao@linux.intel.com> wrote:

> On Mon, Jan 22, 2024 at 03:52:37PM -0800, isaku.yamahata@intel.com wrote:
> > From: Kai Huang <kai.huang@intel.com>
> >
> > 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@intel.com>
> 
> 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 ?

With v19, I put those tdx host patches in the first part.
diff mbox series

Patch

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);