Message ID | 20241030190039.77971-7-rick.p.edgecombe@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | TDX vCPU/VM creation | expand |
On 10/30/24 12:00, Rick Edgecombe wrote: > +u64 tdh_mng_create(u64 tdr, u64 hkid) > +{ > + struct tdx_module_args args = { > + .rcx = tdr, > + .rdx = hkid, > + }; > + clflush_cache_range(__va(tdr), PAGE_SIZE); > + return seamcall(TDH_MNG_CREATE, &args); > +} > +EXPORT_SYMBOL_GPL(tdh_mng_create); I'd _prefer_ that this explain why the clflush is there. The other goofy thing here is why it's getting a physical address passed in. It's my old 32-bit paranoia kicking in, but everything that has a valid virtual address _also_ has a valid physical address. The inverse is not true, though. So I like to keep things as pointers as long as possible.
On Tue, 2024-11-12 at 12:17 -0800, Dave Hansen wrote: > On 10/30/24 12:00, Rick Edgecombe wrote: > > +u64 tdh_mng_create(u64 tdr, u64 hkid) > > +{ > > + struct tdx_module_args args = { > > + .rcx = tdr, > > + .rdx = hkid, > > + }; > > + clflush_cache_range(__va(tdr), PAGE_SIZE); > > + return seamcall(TDH_MNG_CREATE, &args); > > +} > > +EXPORT_SYMBOL_GPL(tdh_mng_create); > > I'd _prefer_ that this explain why the clflush is there. How about: /* * The TDX module exposes a CLFLUSH_BEFORE_ALLOC bit to specify whether * a CLFLUSH of pages is required before handing them to the TDX module. * Be conservative and make the code simpler by doing the CLFLUSH * unconditionally. */ > > The other goofy thing here is why it's getting a physical address passed > in. It's my old 32-bit paranoia kicking in, but everything that has a > valid virtual address _also_ has a valid physical address. The inverse > is not true, though. So I like to keep things as pointers as long as > possible. Ok, seems reasonable.
On 11/12/24 13:21, Edgecombe, Rick P wrote: > On Tue, 2024-11-12 at 12:17 -0800, Dave Hansen wrote: >> On 10/30/24 12:00, Rick Edgecombe wrote: >>> +u64 tdh_mng_create(u64 tdr, u64 hkid) >>> +{ >>> + struct tdx_module_args args = { >>> + .rcx = tdr, >>> + .rdx = hkid, >>> + }; >>> + clflush_cache_range(__va(tdr), PAGE_SIZE); >>> + return seamcall(TDH_MNG_CREATE, &args); >>> +} >>> +EXPORT_SYMBOL_GPL(tdh_mng_create); >> I'd _prefer_ that this explain why the clflush is there. > How about: > /* > * The TDX module exposes a CLFLUSH_BEFORE_ALLOC bit to specify whether > * a CLFLUSH of pages is required before handing them to the TDX module. > * Be conservative and make the code simpler by doing the CLFLUSH > * unconditionally. > */ Is there a chance we could put this in a helper so the "be conservative" policy is centralized in one location? The comment could also go there.
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 9897335a8e2f..9d19ca33e884 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -123,8 +123,11 @@ int tdx_guest_keyid_alloc(void); void tdx_guest_keyid_free(unsigned int keyid); /* SEAMCALL wrappers for creating/destroying/running TDX guests */ +u64 tdh_mng_addcx(u64 tdr, u64 tdcs); u64 tdh_mng_key_config(u64 tdr); +u64 tdh_mng_create(u64 tdr, u64 hkid); u64 tdh_mng_key_freeid(u64 tdr); +u64 tdh_mng_init(u64 tdr, u64 td_params, u64 *rcx); #else static inline void tdx_init(void) { } static inline int tdx_cpu_enable(void) { return -ENODEV; } diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index c42eab8cc069..16122fd552ff 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1563,6 +1563,18 @@ void tdx_guest_keyid_free(unsigned int keyid) } EXPORT_SYMBOL_GPL(tdx_guest_keyid_free); +u64 tdh_mng_addcx(u64 tdr, u64 tdcs) +{ + struct tdx_module_args args = { + .rcx = tdcs, + .rdx = tdr, + }; + + clflush_cache_range(__va(tdcs), PAGE_SIZE); + return seamcall(TDH_MNG_ADDCX, &args); +} +EXPORT_SYMBOL_GPL(tdh_mng_addcx); + u64 tdh_mng_key_config(u64 tdr) { struct tdx_module_args args = { @@ -1573,6 +1585,17 @@ u64 tdh_mng_key_config(u64 tdr) } EXPORT_SYMBOL_GPL(tdh_mng_key_config); +u64 tdh_mng_create(u64 tdr, u64 hkid) +{ + struct tdx_module_args args = { + .rcx = tdr, + .rdx = hkid, + }; + clflush_cache_range(__va(tdr), PAGE_SIZE); + return seamcall(TDH_MNG_CREATE, &args); +} +EXPORT_SYMBOL_GPL(tdh_mng_create); + u64 tdh_mng_key_freeid(u64 tdr) { struct tdx_module_args args = { @@ -1582,3 +1605,19 @@ u64 tdh_mng_key_freeid(u64 tdr) return seamcall(TDH_MNG_KEY_FREEID, &args); } EXPORT_SYMBOL_GPL(tdh_mng_key_freeid); + +u64 tdh_mng_init(u64 tdr, u64 td_params, u64 *rcx) +{ + struct tdx_module_args args = { + .rcx = tdr, + .rdx = td_params, + }; + u64 ret; + + ret = seamcall_ret(TDH_MNG_INIT, &args); + + *rcx = args.rcx; + + return ret; +} +EXPORT_SYMBOL_GPL(tdh_mng_init); diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 95002e7ff4c5..b9287304f372 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -17,8 +17,11 @@ /* * TDX module SEAMCALL leaf functions */ +#define TDH_MNG_ADDCX 1 #define TDH_MNG_KEY_CONFIG 8 +#define TDH_MNG_CREATE 9 #define TDH_MNG_KEY_FREEID 20 +#define TDH_MNG_INIT 21 #define TDH_PHYMEM_PAGE_RDMD 24 #define TDH_SYS_KEY_CONFIG 31 #define TDH_SYS_INIT 33