Message ID | 20250101074959.412696-8-pbonzini@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | x86/virt/tdx: Add SEAMCALL wrappers for KVM | expand |
On Wed, 2025-01-01 at 02:49 -0500, Paolo Bonzini wrote: > > +u64 tdh_mem_sept_add(struct tdx_td *td, u64 gpa, u64 level, u64 hpa, u64 *rcx, u64 *rdx) > +{ > + struct tdx_module_args args = { > + .rcx = gpa | level, The bit packing here is a bit magic. Yan had been looking at adding a union like below to use internally in tdh_mem_sept_add() to pack the rcx register. union tdx_sept_gpa_mapping_info { struct { u64 level : 3; u64 reserved1 : 9; u64 gfn : 40; u64 reserved2 : 12; }; u64 full; }; It might be a bit verbose, but I agree something should be done. > + .rdx = tdx_tdr_pa(td), > + .r8 = hpa, > + }; > + u64 ret; > + > + clflush_cache_range(__va(hpa), PAGE_SIZE); > + ret = seamcall_ret(TDH_MEM_SEPT_ADD, &args); > + > + *rcx = args.rcx; > + *rdx = args.rdx; This was changed to this: *extended_err1 = args.rcx; *extended_err2 = args.rdx; The reasoning is rcx and rdx are not very clear names. The caller only uses them for printing raw error codes, so don't bother creating a union or anything fancy. The print statements should print the raw error code to help in debugging situations where new bits are defined and returned by a future buggy TDX module. > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(tdh_mem_sept_add); > + > u64 tdh_vp_addcx(struct tdx_vp *vp, struct page *tdcx_page) > { > struct tdx_module_args args = { > diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h > index 62cb7832c42d..308d3aa565d7 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.h > +++ b/arch/x86/virt/vmx/tdx/tdx.h > @@ -16,6 +16,7 @@ > * TDX module SEAMCALL leaf functions > */ > #define TDH_MNG_ADDCX 1 > +#define TDH_MEM_SEPT_ADD 3 > #define TDH_VP_ADDCX 4 > #define TDH_MNG_KEY_CONFIG 8 > #define TDH_MNG_CREATE 9
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 8fc1836c5d09..9e0c60a41d5d 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -138,6 +138,7 @@ struct tdx_vp { }; u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page); +u64 tdh_mem_sept_add(struct tdx_td *td, u64 gpa, u64 level, u64 hpa, u64 *rcx, u64 *rdx); u64 tdh_vp_addcx(struct tdx_vp *vp, struct page *tdcx_page); u64 tdh_mng_key_config(struct tdx_td *td); u64 tdh_mng_create(struct tdx_td *td, u64 hkid); diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 986b58b63121..a97a470dda23 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1491,6 +1491,25 @@ u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page) } EXPORT_SYMBOL_GPL(tdh_mng_addcx); +u64 tdh_mem_sept_add(struct tdx_td *td, u64 gpa, u64 level, u64 hpa, u64 *rcx, u64 *rdx) +{ + struct tdx_module_args args = { + .rcx = gpa | level, + .rdx = tdx_tdr_pa(td), + .r8 = hpa, + }; + u64 ret; + + clflush_cache_range(__va(hpa), PAGE_SIZE); + ret = seamcall_ret(TDH_MEM_SEPT_ADD, &args); + + *rcx = args.rcx; + *rdx = args.rdx; + + return ret; +} +EXPORT_SYMBOL_GPL(tdh_mem_sept_add); + u64 tdh_vp_addcx(struct tdx_vp *vp, struct page *tdcx_page) { struct tdx_module_args args = { diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 62cb7832c42d..308d3aa565d7 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -16,6 +16,7 @@ * TDX module SEAMCALL leaf functions */ #define TDH_MNG_ADDCX 1 +#define TDH_MEM_SEPT_ADD 3 #define TDH_VP_ADDCX 4 #define TDH_MNG_KEY_CONFIG 8 #define TDH_MNG_CREATE 9