elf_kexec.c (9e6b3986759b5e6d625d6e9e33bdae59f5ed48c1) elf_kexec.c (e6265fe7775ec51241850abc854c9652d4709996)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Load ELF vmlinux file for the kexec_file_load syscall.
4 *
5 * Copyright (C) 2021 Huawei Technologies Co, Ltd.
6 *
7 * Author: Liao Chang (liaochang1@huawei.com)
8 *

--- 246 unchanged lines hidden (view full) ---

255 if (!modified_cmdline) {
256 pr_err("Setting up cmdline for kdump kernel failed\n");
257 ret = -EINVAL;
258 goto out;
259 }
260 cmdline = modified_cmdline;
261 }
262
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Load ELF vmlinux file for the kexec_file_load syscall.
4 *
5 * Copyright (C) 2021 Huawei Technologies Co, Ltd.
6 *
7 * Author: Liao Chang (liaochang1@huawei.com)
8 *

--- 246 unchanged lines hidden (view full) ---

255 if (!modified_cmdline) {
256 pr_err("Setting up cmdline for kdump kernel failed\n");
257 ret = -EINVAL;
258 goto out;
259 }
260 cmdline = modified_cmdline;
261 }
262
263#ifdef CONFIG_ARCH_HAS_KEXEC_PURGATORY
263#ifdef CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY
264 /* Add purgatory to the image */
265 kbuf.top_down = true;
266 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
267 ret = kexec_load_purgatory(image, &kbuf);
268 if (ret) {
269 pr_err("Error loading purgatory ret=%d\n", ret);
270 goto out;
271 }
272 ret = kexec_purgatory_get_set_symbol(image, "riscv_kernel_entry",
273 &kernel_start,
274 sizeof(kernel_start), 0);
275 if (ret)
276 pr_err("Error update purgatory ret=%d\n", ret);
264 /* Add purgatory to the image */
265 kbuf.top_down = true;
266 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
267 ret = kexec_load_purgatory(image, &kbuf);
268 if (ret) {
269 pr_err("Error loading purgatory ret=%d\n", ret);
270 goto out;
271 }
272 ret = kexec_purgatory_get_set_symbol(image, "riscv_kernel_entry",
273 &kernel_start,
274 sizeof(kernel_start), 0);
275 if (ret)
276 pr_err("Error update purgatory ret=%d\n", ret);
277#endif /* CONFIG_ARCH_HAS_KEXEC_PURGATORY */
277#endif /* CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY */
278
279 /* Add the initrd to the image */
280 if (initrd != NULL) {
281 kbuf.buffer = initrd;
282 kbuf.bufsz = kbuf.memsz = initrd_len;
283 kbuf.buf_align = PAGE_SIZE;
278
279 /* Add the initrd to the image */
280 if (initrd != NULL) {
281 kbuf.buffer = initrd;
282 kbuf.bufsz = kbuf.memsz = initrd_len;
283 kbuf.buf_align = PAGE_SIZE;
284 kbuf.top_down = true;
284 kbuf.top_down = false;
285 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
286 ret = kexec_add_buffer(&kbuf);
287 if (ret)
288 goto out;
289 initrd_pbase = kbuf.mem;
290 pr_notice("Loaded initrd at 0x%lx\n", initrd_pbase);
291 }
292

--- 127 unchanged lines hidden (view full) ---

420 break;
421 /*
422 * With no R_RISCV_PCREL_LO12_S, R_RISCV_PCREL_LO12_I
423 * sym is expected to be next to R_RISCV_PCREL_HI20
424 * in purgatory relsec. Handle it like R_RISCV_CALL
425 * sym, instead of searching the whole relsec.
426 */
427 case R_RISCV_PCREL_HI20:
285 kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
286 ret = kexec_add_buffer(&kbuf);
287 if (ret)
288 goto out;
289 initrd_pbase = kbuf.mem;
290 pr_notice("Loaded initrd at 0x%lx\n", initrd_pbase);
291 }
292

--- 127 unchanged lines hidden (view full) ---

420 break;
421 /*
422 * With no R_RISCV_PCREL_LO12_S, R_RISCV_PCREL_LO12_I
423 * sym is expected to be next to R_RISCV_PCREL_HI20
424 * in purgatory relsec. Handle it like R_RISCV_CALL
425 * sym, instead of searching the whole relsec.
426 */
427 case R_RISCV_PCREL_HI20:
428 case R_RISCV_CALL_PLT:
429 case R_RISCV_CALL:
430 *(u64 *)loc = CLEAN_IMM(UITYPE, *(u64 *)loc) |
431 ENCODE_UJTYPE_IMM(val - addr);
432 break;
433 case R_RISCV_RVC_BRANCH:
434 *(u32 *)loc = CLEAN_IMM(CBTYPE, *(u32 *)loc) |
435 ENCODE_CBTYPE_IMM(val - addr);
436 break;

--- 27 unchanged lines hidden ---
428 case R_RISCV_CALL:
429 *(u64 *)loc = CLEAN_IMM(UITYPE, *(u64 *)loc) |
430 ENCODE_UJTYPE_IMM(val - addr);
431 break;
432 case R_RISCV_RVC_BRANCH:
433 *(u32 *)loc = CLEAN_IMM(CBTYPE, *(u32 *)loc) |
434 ENCODE_CBTYPE_IMM(val - addr);
435 break;

--- 27 unchanged lines hidden ---