x86/tdx: Fix crash on kexec
Subsystems (2)
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().
--- arch/x86/coco/tdx/tdx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
arch/x86/coco/tdx/tdx.c +10 -2
@@ -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
Borislav Petkov
maintainerQuoted 10 lines · Kirill A. Shutemov
The function
tdx_enc_status_changed()was modified to handlevmalloc()mappings. It now utilizesslow_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 callingtdx_enc_status_changed(), causing aBUG_ON()error inslow_virt_to_phys().
Quoted 7 lines
To address this issue,
tdx_enc_status_change()should use__pa()to obtain physical addresses whenever possible. Thevirt_addr_valid()check will handle such cases, while any other scenarios, includingvmalloc()mappings, will resort toslow_virt_to_phys().Signed-off-by Kirill A. Shutemov <[email protected]>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-netiquetteQuoted 16 lines · Borislav Petkov
Quoted 15 lines · Kirill A. Shutemov
The function
tdx_enc_status_changed()was modified to handlevmalloc()mappings. It now utilizesslow_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 callingtdx_enc_status_changed(), causing aBUG_ON()error inslow_virt_to_phys().To address this issue,
tdx_enc_status_change()should use__pa()to obtain physical addresses whenever possible. Thevirt_addr_valid()check will handle such cases, while any other scenarios, includingvmalloc()mappings, will resort toslow_virt_to_phys().
Quoted 7 lines
Quoted 2 lines
Signed-off-by Kirill A. Shutemov <[email protected]>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
e1b8ac3aae58fixing and why is it urgent?
Daxuan, how urgent is this fix for you?
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 28 lines
From: Kirill A. Shutemov <[email protected]>
Sent: Saturday, June 29, 2024 7:04 AMQuoted 11 lines · Borislav Petkov
Quoted 10 lines · Kirill A. Shutemov
The function
tdx_enc_status_changed()was modified to handlevmalloc()mappings. It now utilizesslow_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 callingtdx_enc_status_changed(), causing aBUG_ON()error inslow_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. Thevirt_addr_valid()check will handle such cases, while any other scenarios, includingvmalloc()mappings, will resort toslow_virt_to_phys().Signed-off-by Kirill A. Shutemov <[email protected]>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
e1b8ac3aae58fixing 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
Borislav Petkov
maintainerQuoted 1 line · Dexuan Cui
It would be great to add
e1b8ac3aae58to 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-netiquetteQuoted 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
e1b8ac3aae58to 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
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 kexecQuoted 7 lines
Quoted 1 line · Dexuan Cui
It would be great to add
e1b8ac3aae58to 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 combinese1b8ac3aae58 ("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
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 combinese1b8ac3aae58 ("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
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 combinese1b8ac3aae58 ("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
Borislav Petkov
maintainerQuoted 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-netiquetteQuoted 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
Borislav Petkov
maintainerQuoted 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-netiquetteQuoted 4 lines
From: Kirill A. Shutemov <[email protected]>
Sent: Monday, July 8, 2024 5:35 AMQuoted 1 line
[...]
Go ahead, post the new version.
I just posted the new version.