Linux Confidential Computing Development
 help / color / mirror / Atom feed
* [PATCH] x86/tdx: Fix crash on kexec
@ 2024-06-29 13:06 Kirill A. Shutemov
  2024-06-29 13:59 ` Borislav Petkov
  0 siblings, 1 reply; 13+ messages in thread
From: Kirill A. Shutemov @ 2024-06-29 13:06 UTC (permalink / raw)
  To: Kirill A. Shutemov, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, x86, H. Peter Anvin, Michael Kelley,
	Kuppuswamy Sathyanarayanan, Kai Huang
  Cc: Rick Edgecombe, Dexuan Cui, linux-coco, linux-kernel

The function tdx_enc_status_changed() was modified to handle vmalloc()
mappings. It now utilizes slow_virt_to_phys() to determine the physical
address of the page by walking page tables and looking for the physical
address in the page table entry.

However, this adjustment conflicted with the enabling of kexec. The
function tdx_kexec_finish() clears the page table entry before calling
tdx_enc_status_changed(), causing a BUG_ON() error in
slow_virt_to_phys().

To address this issue, tdx_enc_status_change() should use __pa() to
obtain physical addresses whenever possible. The virt_addr_valid() check
will handle such cases, while any other scenarios, including vmalloc()
mappings, will resort to slow_virt_to_phys().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fixes: e1b8ac3aae58 ("x86/tdx: Support vmalloc() for tdx_enc_status_changed()")
---
 arch/x86/coco/tdx/tdx.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index ef8ec2425998..8f471260924f 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -813,8 +813,16 @@ static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc)
 		step = PAGE_SIZE;
 
 	for (addr = start; addr < end; addr += step) {
-		phys_addr_t start_pa = slow_virt_to_phys((void *)addr);
-		phys_addr_t end_pa   = start_pa + step;
+		phys_addr_t start_pa;
+		phys_addr_t end_pa;
+
+		/* The check fails on vmalloc() mappings */
+		if (virt_addr_valid(addr))
+			start_pa = __pa(addr);
+		else
+			start_pa = slow_virt_to_phys((void *)addr);
+
+		end_pa = start_pa + step;
 
 		if (!tdx_enc_status_changed_phys(start_pa, end_pa, enc))
 			return false;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-07-08 18:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-29 13:06 [PATCH] x86/tdx: Fix crash on kexec Kirill A. Shutemov
2024-06-29 13:59 ` Borislav Petkov
2024-06-29 14:04   ` Kirill A. Shutemov
2024-06-29 19:27     ` Dexuan Cui
2024-06-29 19:41       ` Borislav Petkov
2024-07-03 19:16         ` Dexuan Cui
2024-07-04 14:28           ` Kirill A. Shutemov
2024-07-04 14:48             ` Dexuan Cui
2024-07-08 12:34               ` Kirill A. Shutemov
2024-07-08 13:32                 ` Borislav Petkov
2024-07-08 13:51                   ` Kirill A. Shutemov
2024-07-08 15:57                     ` Borislav Petkov
2024-07-08 18:43                 ` Dexuan Cui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox