[PW_SID:1141250] Fix kexec_file segment placement on RISC-V - #2422
[PW_SID:1141250] Fix kexec_file segment placement on RISC-V#2422linux-riscv-bot wants to merge 4 commits into
Conversation
When an Sv48 or Sv57 kernel loads an Sv39 kernel, top-down allocation can place the initrd and other extra segments above the direct-map range supported by the next kernel. During early boot, setup_bootmem() limits usable memory to phys_ram_base + KERN_VIRT_SIZE. Any segment placed above the Sv39 limit is therefore unreachable by the next kernel. In particular, an initrd outside this range is disabled during boot. The max_low_pfn limit only reflects the direct map of the loading kernel and is insufficient when the next kernel uses a narrower address space. The paging mode of the next kernel is not known at load time, so apply the Sv39 limit unconditionally. On a machine with more than 128 GiB this also constrains a next kernel that would run in Sv48 or Sv57. Limit extra segment placement to the smaller of the loading kernel's direct-map limit and the end of the Sv39 direct map. The next kernel derives its direct map from the start of the memory it is given, which is the crash kernel region for a crash image, so use that region as the base in that case. A NOMMU kernel has no direct map and keeps the limit of the loading kernel. Fixes: b67a1ee ("riscv: kexec_file: Constrain segment placement to direct map") Co-developed-by: Yicong Yang <yang.yicong@picoheart.com> Signed-off-by: Yicong Yang <yang.yicong@picoheart.com> Signed-off-by: Yufan Dou <douyufan@picoheart.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
elf_find_pbase() searches for a memory hole to place the whole kernel image, and the segments are then added at fixed addresses derived from the base it returns. kexec_add_buffer() skips the memory hole check for a segment whose address is already known. The search is sized by the length of the ELF file, which does not reflect the extent the image occupies in memory: a PT_LOAD segment can have a memory size larger than its file size, so a stripped vmlinux can end up needing more memory than the file length accounts for. The tail of the image is then placed without any check that the memory is available. Size the search by the extent between the lowest and the highest physical address of the PT_LOAD segments instead, and drop the now unused kernel_len argument. Fixes: 6261586 ("RISC-V: Add kexec_file support") Cc: stable@vger.kernel.org Co-developed-by: Yicong Yang <yang.yicong@picoheart.com> Signed-off-by: Yicong Yang <yang.yicong@picoheart.com> Signed-off-by: Yufan Dou <douyufan@picoheart.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
When strict kernel permissions are enabled, the next kernel extends its image reservation from _start to the PMD-aligned address following _end. If kexec only reserves the exact image range, a later segment can be placed in this aligned tail and overlap the next kernel's reservation. For a flat Image, extend the decoded image size to the next PMD boundary. An ELF image contains multiple PT_LOAD segments. Extending every segment can make an intermediate segment overlap the following one. Find the PT_LOAD segment with the highest physical end address and extend only that segment to the next PMD boundary. Align the extent searched by elf_find_pbase() as well, so that the expanded tail stays within the range validated against the available memory. This reserves the range expected by the next kernel without changing the layout of intermediate ELF segments. Fixes: 6261586 ("RISC-V: Add kexec_file support") Fixes: 809a11e ("riscv: kexec_file: Support loading Image binary file") Cc: stable@vger.kernel.org Co-developed-by: Yicong Yang <yang.yicong@picoheart.com> Signed-off-by: Yicong Yang <yang.yicong@picoheart.com> Signed-off-by: Yufan Dou <douyufan@picoheart.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 1: "[1/3] riscv: kexec_file: constrain extra segments to the Sv39 direct map" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 2: "[2/3] riscv: kexec_file: size the ELF placement search by the load extent" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
|
Patch 3: "[3/3] riscv: kexec: reserve the PMD-aligned kernel image range" |
abf8962 to
9fa746d
Compare
PR for series 1141250 applied to workflow__riscv__fixes
Name: Fix kexec_file segment placement on RISC-V
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1141250
Version: 1