On Tue, Jan 07, 2025 at 02:43:11PM +0800, Yan Zhao wrote: ... > +u64 tdh_phymem_page_wbinvd_hkid(struct page *page, u16 hkid) > +{ > + struct tdx_module_args args = {}; > + > + args.rcx = page_to_phys(page) | ((hpa_t)hkid << boot_cpu_data.x86_phys_bits); > + > + return seamcall(TDH_PHYMEM_PAGE_WBINVD, &args); > +} For type of hkid is changed from u64 to u16. Here's a fixup patch to further have tdh_phymem_page_wbinvd_tdr() in [1] and the tdh_phymem_page_wbinvd_hkid() in this patch to use the common helper set_hkid_to_hpa(). [1] https://lore.kernel.org/kvm/20250101074959.412696-11-pbonzini@xxxxxxxxxx/ commit 41f66e12a400516c6a851f0755f8abbe4dacb39b Author: Yan Zhao <yan.y.zhao@xxxxxxxxx> Date: Wed Dec 11 18:11:24 2024 +0800 x86/virt/tdx: Move set_hkid_to_hpa() to x86 common header and use it Move set_hkid_to_hpa() from KVM TDX to x86 common header and have tdh_phymem_page_wbinvd_tdr() and tdh_phymem_page_wbinvd_hkid() to use it. Signed-off-by: Yan Zhao <yan.y.zhao@xxxxxxxxx> diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 5420d07ee81c..5f3931e62c06 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -144,7 +144,13 @@ struct tdx_vp { struct page **tdcx_pages; }; +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); +} + /* SEAMCALL wrappers for creating/destroying/running TDX guests */ +u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page); u64 tdh_vp_enter(u64 tdvpr, struct tdx_module_args *args); u64 tdh_mng_addcx(struct tdx_td *td, struct page *tdcs_page); u64 tdh_mem_page_add(struct tdx_td *td, gfn_t gfn, struct page *private_page, diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index c3a84eb4694a..d86bfcbd6873 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -222,11 +222,6 @@ static inline int pg_level_to_tdx_sept_level(enum pg_level level) */ static DEFINE_PER_CPU(struct list_head, associated_tdvcpus); -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); -} - static __always_inline union vmx_exit_reason tdexit_exit_reason(struct kvm_vcpu *vcpu) { return (union vmx_exit_reason)(u32)(to_tdx(vcpu)->vp_enter_ret); diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 6f002e36e421..0d7a0a27bd3e 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1930,7 +1930,7 @@ 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); + args.rcx = set_hkid_to_hpa(tdx_tdr_pa(td), tdx_global_keyid); return seamcall(TDH_PHYMEM_PAGE_WBINVD, &args); } @@ -1940,7 +1940,7 @@ u64 tdh_phymem_page_wbinvd_hkid(struct page *page, u16 hkid) { struct tdx_module_args args = {}; - args.rcx = page_to_phys(page) | ((hpa_t)hkid << boot_cpu_data.x86_phys_bits); + args.rcx = set_hkid_to_hpa(page_to_phys(page), hkid); return seamcall(TDH_PHYMEM_PAGE_WBINVD, &args); }