Message ID | 20241203010317.827803-3-rick.p.edgecombe@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | SEAMCALL Wrappers | expand |
On 12/3/2024 9:03 AM, Rick Edgecombe wrote: [...] > > +/* > + * 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. > + */ > +static void tdx_clflush_page(struct page *tdr) The argument should have a generic name instead of tdr, because it's not limited to TDR. > +{ > + clflush_cache_range(page_to_virt(tdr), PAGE_SIZE); > +} > + > +u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page) > +{ > + struct tdx_module_args args = { > + .rcx = page_to_pfn(tdcs_page) << PAGE_SHIFT, > + .rdx = tdx_tdr_pa(td), > + }; > + > + tdx_clflush_page(tdcs_page); > + return seamcall(TDH_MNG_ADDCX, &args); > +} > +EXPORT_SYMBOL_GPL(tdh_mng_addcx); > + [...]
On Tue, 2024-12-03 at 10:20 +0800, Binbin Wu wrote: > > +/* > > + * 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. > > + */ > > +static void tdx_clflush_page(struct page *tdr) > The argument should have a generic name instead of tdr, because it's not > limited to TDR. Doh, yes. Thanks.
On 12/2/24 17:03, Rick Edgecombe wrote: > +u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page) > +{ > + struct tdx_module_args args = { > + .rcx = page_to_pfn(tdcs_page) << PAGE_SHIFT, This is a nit, but there is a page_to_phys().
On Wed, 2024-12-04 at 11:54 -0800, Dave Hansen wrote: > On 12/2/24 17:03, Rick Edgecombe wrote: > > +u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page) > > +{ > > + struct tdx_module_args args = { > > + .rcx = page_to_pfn(tdcs_page) << PAGE_SHIFT, > > This is a nit, but there is a page_to_phys(). I almost used that, but the macro casts to dma_addr_t which didn't quite fit these callers. Seems ok though.
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 139c003acd1b..a4360a71dbdd 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -131,8 +131,11 @@ struct tdx_td { struct page **tdcs_pages; }; +u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page); u64 tdh_mng_key_config(struct tdx_td *td); +u64 tdh_mng_create(struct tdx_td *td, u64 hkid); u64 tdh_mng_key_freeid(struct tdx_td *td); +u64 tdh_mng_init(struct tdx_td *td, u64 td_params, u64 *extended_err); #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 2d1cebce8c07..605eb9bd81d3 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1568,6 +1568,29 @@ static inline u64 tdx_tdr_pa(struct tdx_td *td) return page_to_pfn(td->tdr_page) << PAGE_SHIFT; } +/* + * 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. + */ +static void tdx_clflush_page(struct page *tdr) +{ + clflush_cache_range(page_to_virt(tdr), PAGE_SIZE); +} + +u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page) +{ + struct tdx_module_args args = { + .rcx = page_to_pfn(tdcs_page) << PAGE_SHIFT, + .rdx = tdx_tdr_pa(td), + }; + + tdx_clflush_page(tdcs_page); + return seamcall(TDH_MNG_ADDCX, &args); +} +EXPORT_SYMBOL_GPL(tdh_mng_addcx); + u64 tdh_mng_key_config(struct tdx_td *td) { struct tdx_module_args args = { @@ -1578,6 +1601,18 @@ u64 tdh_mng_key_config(struct tdx_td *td) } EXPORT_SYMBOL_GPL(tdh_mng_key_config); +u64 tdh_mng_create(struct tdx_td *td, u64 hkid) +{ + struct tdx_module_args args = { + .rcx = tdx_tdr_pa(td), + .rdx = hkid, + }; + + tdx_clflush_page(td->tdr_page); + return seamcall(TDH_MNG_CREATE, &args); +} +EXPORT_SYMBOL_GPL(tdh_mng_create); + u64 tdh_mng_key_freeid(struct tdx_td *td) { struct tdx_module_args args = { @@ -1588,3 +1623,19 @@ u64 tdh_mng_key_freeid(struct tdx_td *td) } EXPORT_SYMBOL_GPL(tdh_mng_key_freeid); +u64 tdh_mng_init(struct tdx_td *td, u64 td_params, u64 *extended_err) +{ + struct tdx_module_args args = { + .rcx = tdx_tdr_pa(td), + .rdx = td_params, + }; + u64 ret; + + ret = seamcall_ret(TDH_MNG_INIT, &args); + + *extended_err = 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