Skip to contentSkip to conversation

x86/tdx: Fix crash on kexec

PATCH In review Kirill A. Shutemov 3 participants 13 messages Jun 29, 2024 – Jul 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/tdx: Fix crash on kexec

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().

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(-)
arch/x86/coco/tdx/tdx.c +10 -2
index ef8ec2425998..8f471260924f 100644
@@ -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;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 10 lines · Kirill A. Shutemov

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().

Quoted 7 lines

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().

Fixes e1b8ac3aae58 ("x86/tdx: Support vmalloc() for tdx_enc_status_changed()")

I'm going to zap this one from x86/urgent and give you guys ample time to test thus stuff better and longer.

Also, what is this e1b8ac3aae58 fixing and why is it urgent?

AFAICT, it can go through the normal merge window...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#2 lore raw
Quoted 16 lines · Borislav Petkov
Quoted 15 lines · Kirill A. Shutemov

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().

Quoted 7 lines
Quoted 2 lines
Fixes e1b8ac3aae58 ("x86/tdx: Support vmalloc() for tdx_enc_status_changed()")

I'm going to zap this one from x86/urgent and give you guys ample time to test thus stuff better and longer.

Also, what is this e1b8ac3aae58 fixing and why is it urgent?

Daxuan, how urgent is this fix for you?

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#3 lore raw
Quoted 28 lines

From: Kirill A. Shutemov <[email protected]>
Sent: Saturday, June 29, 2024 7:04 AM

Quoted 11 lines · Borislav Petkov
Quoted 10 lines · Kirill A. Shutemov

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().

Quoted 7 lines
Quoted 7 lines

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().

Fixes e1b8ac3aae58 ("x86/tdx: Support vmalloc() for

tdx_enc_status_changed()")

Quoted 5 lines

I'm going to zap this one from x86/urgent and give you guys ample time to
test
thus stuff better and longer.

Quoted 6 lines
Quoted 1 line

Also, what is this e1b8ac3aae58 fixing and why is it urgent?

Daxuan, how urgent is this fix for you?

--
Kiryl Shutsemau / Kirill A. Shutemov

Hi Kirill, Boris,
IMO e1b8ac3aae58 is not urgent and can go through the normal merge window. It would be great to add e1b8ac3aae58 to the branch x86/tdx.

Thanks,
Dexuan

maintainer
#4 lore raw
Quoted 1 line · Dexuan Cui

It would be great to add e1b8ac3aae58 to the branch x86/tdx.

Sure we will, once it is properly tested. This very thread says otherwise.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#5 lore raw
Quoted 14 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Saturday, June 29, 2024 12:41 PM
To: Dexuan Cui <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>; Dave Hansen <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; [email protected]; H. Peter Anvin <[email protected]>; Michael Kelley <[email protected]>; Kuppuswamy Sathyanarayanan <[email protected]>; Kai Huang <[email protected]>; Rick Edgecombe <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] x86/tdx: Fix crash on kexec

Quoted 7 lines
Quoted 1 line · Dexuan Cui

It would be great to add e1b8ac3aae58 to the branch x86/tdx.

Sure we will, once it is properly tested. This very thread says otherwise. --
Regards/Gruss,
Boris.

Hi Kirill, Dave,
Do you think if it's a good idea if I post a new patch that combines

    e1b8ac3aae58 ("x86/tdx: Support vmalloc() for tdx_enc_status_changed()")

and
your patch "[PATCH] x86/tdx: Fix crash on kexec"?

Or, maybe Dave can help combine the two patches into one?

Just wanted to make sure e1b8ac3aae58 won't get lost.

Thanks,
Dexuan

#6 lore raw
Quoted 22 lines · Dexuan Cui
Quoted 14 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Saturday, June 29, 2024 12:41 PM
To: Dexuan Cui <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>; Dave Hansen <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; [email protected]; H. Peter Anvin <[email protected]>; Michael Kelley <[email protected]>; Kuppuswamy Sathyanarayanan <[email protected]>; Kai Huang <[email protected]>; Rick Edgecombe <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] x86/tdx: Fix crash on kexec

Quoted 7 lines
Quoted 1 line · Dexuan Cui

It would be great to add e1b8ac3aae58 to the branch x86/tdx.

Sure we will, once it is properly tested. This very thread says otherwise. --
Regards/Gruss,
Boris.

Quoted 5 lines

Hi Kirill, Dave,
Do you think if it's a good idea if I post a new patch that combines

    e1b8ac3aae58 ("x86/tdx: Support vmalloc() for tdx_enc_status_changed()")

and
your patch "[PATCH] x86/tdx: Fix crash on kexec"?

Yeah, IIUC, that's what Borislav wanted. After proper testing.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#7 lore raw
Quoted 9 lines

From: Kirill A. Shutemov <[email protected]>

Quoted 7 lines

[...]
Hi Kirill, Dave,
Do you think if it's a good idea if I post a new patch that combines

    e1b8ac3aae58 ("x86/tdx: Support vmalloc() for

tdx_enc_status_changed()")
and
your patch "[PATCH] x86/tdx: Fix crash on kexec"?

Quoted 4 lines

Yeah, IIUC, that's what Borislav wanted. After proper testing.

--
Kiryl Shutsemau / Kirill A. Shutemov

Hi Kirill,
I tested the 2 patches for a Linux VM on Hyper-V and all worked fine.

When you finish testing, please let me know so that I can post a combined patch; alternatively, it would be better if you can help post a combined patch.

Thanks,
Dexuan

#8 lore raw
Quoted 14 lines · Dexuan Cui
Quoted 9 lines

From: Kirill A. Shutemov <[email protected]>

Quoted 7 lines

[...]
Hi Kirill, Dave,
Do you think if it's a good idea if I post a new patch that combines

    e1b8ac3aae58 ("x86/tdx: Support vmalloc() for

tdx_enc_status_changed()")
and
your patch "[PATCH] x86/tdx: Fix crash on kexec"?

Quoted 4 lines

Yeah, IIUC, that's what Borislav wanted. After proper testing.

--
Kiryl Shutsemau / Kirill A. Shutemov

Quoted 6 lines

Hi Kirill,
I tested the 2 patches for a Linux VM on Hyper-V and all worked fine.

When you finish testing, please let me know so that I can post a combined patch; alternatively, it would be better if you can help post a combined patch.

Go ahead, post the new version.

Borislav, could you drop the original patch from tip tree?

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
maintainer
#9 lore raw
Quoted 1 line · Kirill A. Shutemov

Borislav, could you drop the original patch from tip tree?

Long gone already.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#10 lore raw
Quoted 4 lines · Borislav Petkov
Quoted 1 line · Kirill A. Shutemov

Borislav, could you drop the original patch from tip tree?

Long gone already.

Hm. I still see it in tip/x86/cc branch which is merged in tip/master.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
maintainer
#11 lore raw
Quoted 7 lines · Kirill A. Shutemov
Quoted 4 lines · Borislav Petkov
Quoted 1 line · Kirill A. Shutemov

Borislav, could you drop the original patch from tip tree?

Long gone already.

Hm. I still see it in tip/x86/cc branch which is merged in tip/master.

Yeah, it should be gone now.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette