Message ID | 20241203010317.827803-5-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: [...] > + > +/* > + * TDX ABI defines output operands as PT, OWNER and SIZE. These are TDX defined fomats. fomats -> formats > + * So despite the names, they must be interpted specially as described by the spec. Return interpted -> interpreted > + * them only for error reporting purposes. > + */ > +u64 tdh_phymem_page_reclaim(struct page *page, u64 *tdx_pt, u64 *tdx_owner, u64 *tdx_size) > +{ > + struct tdx_module_args args = { > + .rcx = page_to_pfn(page) << PAGE_SHIFT, > + }; > + u64 ret; > + > + ret = seamcall_ret(TDH_PHYMEM_PAGE_RECLAIM, &args); > + > + *tdx_pt = args.rcx; > + *tdx_owner = args.rdx; > + *tdx_size = args.r8; > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(tdh_phymem_page_reclaim); > + [...]
On Tue, 2024-12-03 at 10:33 +0800, Binbin Wu wrote: > > + * TDX ABI defines output operands as PT, OWNER and SIZE. These are TDX > > defined fomats. > fomats -> formats > > > + * So despite the names, they must be interpted specially as described by > > the spec. Return > interpted -> interpreted Oof, thanks.
On Mon, Dec 02, 2024 at 05:03:14PM -0800, Rick Edgecombe wrote: ... > +u64 tdh_phymem_page_wbinvd_tdr(struct tdx_td *td) > +{ > + struct tdx_module_args args = {}; > + > + args.rcx = tdx_tdr_pa(td) | ((u64)tdx_global_keyid << boot_cpu_data.x86_phys_bits); > + > + return seamcall(TDH_PHYMEM_PAGE_WBINVD, &args); > +} > +EXPORT_SYMBOL_GPL(tdh_phymem_page_wbinvd_tdr); The tdx_global_keyid is of type u16 in TDX spec and TDX module. As Reinette pointed out, u64 could cause overflow. Do we need to change all keyids to u16, including those in tdh.mng.create() in patch 2, the global_keyid, tdx_guest_keyid_start in arch/x86/virt/vmx/tdx/tdx.c and kvm_tdx->hkid in arch/x86/kvm/vmx/tdx.c ? BTW, is it a good idea to move set_hkid_to_hpa() from KVM TDX to x86 common header? static __always_inline hpa_t set_hkid_to_hpa(hpa_t pa, u16 hkid) { return pa | ((hpa_t)hkid << boot_cpu_data.x86_phys_bits); }
On Wed, 2024-12-11 at 09:23 +0800, Yan Zhao wrote: > On Mon, Dec 02, 2024 at 05:03:14PM -0800, Rick Edgecombe wrote: > ... > > +u64 tdh_phymem_page_wbinvd_tdr(struct tdx_td *td) > > +{ > > + struct tdx_module_args args = {}; > > + > > + args.rcx = tdx_tdr_pa(td) | ((u64)tdx_global_keyid << boot_cpu_data.x86_phys_bits); > > + > > + return seamcall(TDH_PHYMEM_PAGE_WBINVD, &args); > > +} > > +EXPORT_SYMBOL_GPL(tdh_phymem_page_wbinvd_tdr); > The tdx_global_keyid is of type u16 in TDX spec and TDX module. > As Reinette pointed out, u64 could cause overflow. > > Do we need to change all keyids to u16, including those in > tdh.mng.create() in patch 2, > the global_keyid, tdx_guest_keyid_start in arch/x86/virt/vmx/tdx/tdx.c > and kvm_tdx->hkid in arch/x86/kvm/vmx/tdx.c ? It seems like a good idea. > > BTW, is it a good idea to move set_hkid_to_hpa() from KVM TDX to x86 common > header? > > static __always_inline hpa_t set_hkid_to_hpa(hpa_t pa, u16 hkid) > { > return pa | ((hpa_t)hkid << boot_cpu_data.x86_phys_bits); > } Ah, yep.
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 018bbabf8639..f6ab8a9ea46b 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -151,6 +151,9 @@ u64 tdh_mng_key_freeid(struct tdx_td *td); u64 tdh_mng_init(struct tdx_td *td, u64 td_params, u64 *extended_err); u64 tdh_vp_init(struct tdx_vp *vp, u64 initial_rcx); u64 tdh_vp_init_apicid(struct tdx_vp *vp, u64 initial_rcx, u32 x2apicid); +u64 tdh_phymem_page_reclaim(struct page *page, u64 *tdx_pt, u64 *tdx_owner, u64 *tdx_size); +u64 tdh_phymem_cache_wb(bool resume); +u64 tdh_phymem_page_wbinvd_tdr(struct tdx_td *td); #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 d71656868fe4..b2a1ed13d0da 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1692,3 +1692,46 @@ u64 tdh_vp_init_apicid(struct tdx_vp *vp, u64 initial_rcx, u32 x2apicid) return seamcall(TDH_VP_INIT | (1ULL << TDX_VERSION_SHIFT), &args); } EXPORT_SYMBOL_GPL(tdh_vp_init_apicid); + +/* + * TDX ABI defines output operands as PT, OWNER and SIZE. These are TDX defined fomats. + * So despite the names, they must be interpted specially as described by the spec. Return + * them only for error reporting purposes. + */ +u64 tdh_phymem_page_reclaim(struct page *page, u64 *tdx_pt, u64 *tdx_owner, u64 *tdx_size) +{ + struct tdx_module_args args = { + .rcx = page_to_pfn(page) << PAGE_SHIFT, + }; + u64 ret; + + ret = seamcall_ret(TDH_PHYMEM_PAGE_RECLAIM, &args); + + *tdx_pt = args.rcx; + *tdx_owner = args.rdx; + *tdx_size = args.r8; + + return ret; +} +EXPORT_SYMBOL_GPL(tdh_phymem_page_reclaim); + +u64 tdh_phymem_cache_wb(bool resume) +{ + struct tdx_module_args args = { + .rcx = resume ? 1 : 0, + }; + + return seamcall(TDH_PHYMEM_CACHE_WB, &args); +} +EXPORT_SYMBOL_GPL(tdh_phymem_cache_wb); + +u64 tdh_phymem_page_wbinvd_tdr(struct tdx_td *td) +{ + struct tdx_module_args args = {}; + + args.rcx = tdx_tdr_pa(td) | ((u64)tdx_global_keyid << boot_cpu_data.x86_phys_bits); + + return seamcall(TDH_PHYMEM_PAGE_WBINVD, &args); +} +EXPORT_SYMBOL_GPL(tdh_phymem_page_wbinvd_tdr); + diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 3663971a3669..191bdd1e571d 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -26,11 +26,14 @@ #define TDH_MNG_INIT 21 #define TDH_VP_INIT 22 #define TDH_PHYMEM_PAGE_RDMD 24 +#define TDH_PHYMEM_PAGE_RECLAIM 28 #define TDH_SYS_KEY_CONFIG 31 #define TDH_SYS_INIT 33 #define TDH_SYS_RD 34 #define TDH_SYS_LP_INIT 35 #define TDH_SYS_TDMR_INIT 36 +#define TDH_PHYMEM_CACHE_WB 40 +#define TDH_PHYMEM_PAGE_WBINVD 41 #define TDH_SYS_CONFIG 45 /*