diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index e165bd5464741f3b614004af9630647a6f7dd6b8..03ffa90b0f70a6a1ba080085361ea16cc6916999 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -201,6 +201,12 @@ int tdx_mcall_extend_rtmr(u8 *data, u8 index) } EXPORT_SYMBOL_GPL(tdx_mcall_extend_rtmr); +bool cc_platform_has_tdx_guest(void) +{ + return cpu_feature_enabled(X86_FEATURE_TDX_GUEST); +} +EXPORT_SYMBOL_GPL(cc_platform_has_tdx_guest); + static void __noreturn tdx_panic(const char *msg) { struct tdx_hypercall_args args = { diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index 672c777956f7bbf45ad2c55250a230437e77fe1b..b622e25ac531f3133b615e9ed2282eb44d4ab9c7 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -112,4 +112,10 @@ bool cc_platform_has_csv3(void); static inline bool cc_platform_has_csv3(void) { return false; } #endif /* CONFIG_HYGON_CSV */ +#ifdef CONFIG_INTEL_TDX_GUEST +bool cc_platform_has_tdx_guest(void); +#else /* !CONFIG_INTEL_TDX_GUEST */ +static inline bool cc_platform_has_tdx_guest(void) { return false; } +#endif /* CONFIG_INTEL_TDX_GUEST */ + #endif /* _LINUX_CC_PLATFORM_H */ diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index aff8b59ce1097dee596bbafcbf0870ad3020163a..67d8805e3a125513d9b3ea7ae60693d2ea54d629 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -302,6 +302,14 @@ swiotlb_init(int verbose) align = SZ_16M; } + /* + * In TDX guest environment, use 2MB alignment for SWIOTLB buffer + * to optimize IOMMU page table and avoid EPT large page splitting. + */ + if (cc_platform_has_tdx_guest() && swiotlb_any && + bytes >= SZ_2M) + align = SZ_2M; + /* * For TDX, SEV or CSV without tee-io, all dma have to use * shared memory, that is, using the swiotlb mechanism.