[PATCH] x86/virt/tdx: Warn on !4K level in tdh_mem_page_aug()

Yan Zhao <[email protected]>
Newsgroups org.kernel.vger.kvm,dev.linux.lists.linux-coco,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Add a warning on a !4K level to loudly flag the unexpected condition when
callers pass in a level > 4K before tdh_mem_page_aug() supports huge pages.

The warning makes the unexpected condition more obvious since the SEAMCALL
TDH_MEM_PAGE_AUG does not necessarily fail when the level is above 4K,
while tdh_mem_page_aug() only flushes the cache for a 4K page before huge
page support is added.

Do not drop the "level" parameter instead, as it will be needed once huge
page support is added.

Do not use a stronger BUG_ON() because the cache flush is only needed when
the TDX module exposes a CLFLUSH_BEFORE_ALLOC bit, which has not yet been
observed in any TDX modules.

Reported-by: Kiryl Shutsemau <[email protected]>
Closes: https://lore.kernel.org/all/abvxiuJfK2eM_1UX@thinkstation
Suggested-by: Dave Hansen <[email protected]>
Suggested-by: Rick Edgecombe <[email protected]>
Signed-off-by: Yan Zhao <[email protected]>
---
 arch/x86/virt/vmx/tdx/tdx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 42df8ea464c4..5c0e91b4aa4f 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -1722,6 +1722,8 @@ u64 tdh_mem_page_aug(struct tdx_td *td, u64 gpa, enum pg_level level,
 	};
 	u64 ret;
 
+	/* TODO: handle large pages. */
+	WARN_ON_ONCE(level != PG_LEVEL_4K);
 	tdx_clflush_pfn(pfn);
 	ret = seamcall_ret(TDH_MEM_PAGE_AUG, &args);
 

base-commit: 1b731e5ded480bd1e5546aed35584238661ce72e
-- 
2.43.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.