kexec_core-accept-unaccepted-kexec-segments-destination-addresses.patch removed from -mm tree
The quilt patch titled
Subject: kexec_core: accept unaccepted kexec segments' destination addresses
has been removed from the -mm tree. Its filename was
kexec_core-accept-unaccepted-kexec-segments-destination-addresses.patch
This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Yan Zhao <[email protected]>
Subject: kexec_core: accept unaccepted kexec segments' destination addresses
Date: Fri, 7 Mar 2025 10:44:11 +0200
The UEFI Specification version 2.9 introduces the concept of memory
acceptance: some Virtual Machine platforms, such as Intel TDX or AMD SEV-SNP, require memory to be accepted before it can be used by the guest.
Accepting memory is expensive. The memory must be allocated by the VMM and then brought to a known safe state: cache must be flushed, memory must be zeroed with the guest's encryption key, and associated metadata must be manipulated. These operations must be performed from a trusted environment (firmware or TDX module). Switching context to and from it also takes time.
This cost adds up. On large confidential VMs, memory acceptance alone can take minutes. It is better to delay memory acceptance until the memory is actually needed.
The kernel accepts memory when it is allocated from buddy allocator for the first time. This reduces boot time and decreases memory overhead as the VMM can allocate memory as needed.
It does not work when the guest attempts to kexec into a new kernel.
The kexec segments' destination addresses are not allocated by the buddy allocator. Instead, they are searched from normal system RAM (top-down or bottom-up) and exclude driver-managed memory, ACPI, persistent, and reserved memory. Unaccepted memory is normal system RAM from kernel point of view and kexec can place segments there.
Kexec bypasses the code path in buddy allocator where memory gets accepted and it leads to a crash when kexec accesses segments' memory.
Accept the destination addresses during the kexec load, immediately after they pass sanity checks. This ensures the code is located in a common place shared by both the kexec_load and kexec_file_load system calls.
This will not conflict with the accounting in try_to_accept_memory_one() since the accounting is set during kernel boot and decremented when pages are moved to the freelists. There is no harm in invoking accept_memory() on a page before making it available to the buddy allocator.
No need to worry about re-accepting memory since accept_memory() checks the unaccepted bitmap before accepting a memory page.
Although a user may perform kexec loading without ever triggering the jump, it doesn't impact much since kexec loading is not in a performance-critical path. Additionally, the destination addresses are always searched and found in the same location on a given system.
Changes to the destination address searching logic to locate only memory in either unaccepted or accepted status are unnecessary and complicated.
---
kernel/kexec_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/kexec_core.c renamed from kernel/kexec_core.c~kexec_core-accept-unaccepted-kexec-segments-destination-addresses +10 -0
@@ -210,6 +210,16 @@ int sanity_check_segment_list(struct kim }#endif +/* +* The destination addresses are searched from system RAM rather than +* being allocated from the buddy allocator, so they are not guaranteed +* to be accepted by the current kernel. Accept the destination +* addresses before kexec swaps their content with the segments' source +* pages to avoid accessing memory before it is accepted. +*/ +for (i =0 ; i < nr_segments; i++) +accept_memory (image->segment[i].mem, image->segment[i].memsz); +return 0 ; }
_
Patches currently in -mm which might be from [email protected] are
Quoted 8 lines · Andrew Morton
The quilt patch titled
Subject:kexec_core: accept unaccepted kexec segments' destination addresses
has been removed from the -mm tree. Its filename was
kexec_core-accept-unaccepted-kexec-segments-destination-addresses.patchThis patch was dropped because it was merged into the mm-nonmm-stable branch of
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
The patch is and was broken.
My last comments were completely ignored. Since this was posted after my comments I had assumed they would be addressed. Since this is not and never has been a bug fix I assumed that nothing would happen with this until the merge window and I had a little more time to compose cohesive response.
All of memory must be accepted before kexec happens because nothing is done to transfer the state of which pages are accepted and which pages are not accepted.
The kernel that is kexec'd can't know which pages to accept. If anything is left unaccepted "Boom" if it tries to accept the wrong thing then maybe "Boom"
Please revert this broken code.
Eric
Quoted 7 lines · Eric W. Biederman
Quoted 5 lines · Andrew Morton
The quilt patch titled
Subject:kexec_core: accept unaccepted kexec segments' destination addresses
has been removed from the -mm tree. Its filename was
kexec_core-accept-unaccepted-kexec-segments-destination-addresses.patch
Quoted 7 lines
Quoted 3 lines
This patch was dropped because it was merged into the mm-nonmm-stable branch of
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mmThe patch is and was broken.
My last comments were completely ignored.
No. There were not. I've replied to your comments:
https://lore.kernel.org/all/u3qnggs7ddbbmh2sjifi7s47tw3cahdjemzkz3nt5szk2i34mo@pqs4dlkd7mhe/
Quoted 9 lines
Since this was posted
after my comments I had assumed they would be addressed. Since this is not and never has been a bug fix I assumed that nothing would happen with this until the merge window and I had a little more time to compose cohesive response.All of memory must be accepted before kexec happens because nothing is done to transfer the state of which pages are accepted and which pages are not accepted.
Please, read my reply on your concern.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov