Skip to content

Fix kexec to launch a new Linux kernel from the current one #92

Description

@frno7

kexec can launch a Linux kernel into a new version of itself, much faster than rebooting the hardware.

kexec -d -c --dtb=/etc/ps2.dtb /mnt/vmlinuz.elf doesn’t quite work, seemingly due to lack of memory:

# kexec -d -c --dtb=/etc/ps2.dtb /mnt/vmlinuz.elf
arch_process_options:137: command_line: (null)
arch_process_options:139: initrd: (null)
arch_process_options:141: dtb: /etc/ps2.dtb
kernel: 0x77a45020 kernel_size: 0x3f9420
kexec_load: entry = 0x800000 flags = 0x80000
nr_segments = 3
segment[0].buf   = 0x4500a0
segment[0].bufsz = 0x200
segment[0].mem   = 0
segment[0].memsz = 0x1000
segment[1].buf   = 0x77a55020
segment[1].bufsz = 0x3e9120
segment[1].mem   = 0x800000
segment[1].memsz = 0x8ed000
segment[2].buf   = 0x77a44420
segment[2].bufsz = 0x1cd
segment[2].mem   = 0x10ed000
segment[2].memsz = 0x1000
Killed

kexec invoked oom-killer: gfp_mask=0x100cc2(GFP_HIGHUSER), order=0, oom_score_adj=0
CPU: 0 PID: 297 Comm: kexec Not tainted 5.4.221+ #349
Stack : 00200000 8005becc 00000000 10058c01 00000000 00000000 804ec36c 80d05c54
        807832ac 804be4c8 80d10ee8 80527527 804be4c8 10058c00 80d05bf8 8052e3f0
        00000000 00000000 807a0000 00000007 00000000 00000000 00000089 00000000
        00000008 00000088 80790000 80285601 80000000 80d10c00 804c041c 805277b8
        80527650 ffffffff 7fff0000 80000000 00000000 8028061c 00000000 80780000
        ...
Call Trace:
[<8001b4a8>] show_stack+0x74/0x104
[<803dc86c>] dump_header+0x5c/0x230
[<800c7ef8>] oom_kill_process+0xb0/0x284
[<800c8824>] out_of_memory+0x360/0x374
[<800fa628>] __alloc_pages_nodemask+0x7fc/0x9c0
[<80084584>] kimage_alloc_pages+0x4c/0xa0
[<800848d8>] kimage_alloc_page+0x74/0x200
[<80084fc8>] kimage_load_segment+0x9c/0x2b4
[<8008592c>] sys_kexec_load+0x25c/0x360
[<8001f38c>] syscall_common+0x34/0x58
Mem-Info:
active_anon:3025 inactive_anon:7 isolated_anon:0
 active_file:4 inactive_file:3 isolated_file:0
 unevictable:0 dirty:0 writeback:0 unstable:0
 slab_reclaimable:124 slab_unreclaimable:783
 mapped:390 shmem:1855 pagetables:84 bounce:0
 free:144 free_pcp:0 free_cma:0
Node 0 active_anon:12100kB inactive_anon:28kB active_file:16kB inactive_file:12kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:1560kB dirty:0kB writeback:0kB shmem:7420kB writeback_tmp:0kB unstable:0kB all_unreclaimable? yes
Normal free:576kB min:576kB low:720kB high:864kB active_anon:12100kB inactive_anon:28kB active_file:16kB inactive_file:12kB unevictable:0kB writepending:0kB present:37888kB managed:23060kB mlocked:0kB kernel_stack:328kB pagetables:336kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
lowmem_reserve[]: 0 0
Normal: 6*4kB (UM) 3*8kB (M) 13*16kB (UM) 4*32kB (U) 3*64kB (UM) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 576kB
1862 total pagecache pages
0 pages in swap cache
Swap cache stats: add 0, delete 0, find 0/0
Free swap  = 0kB
Total swap = 0kB
9472 pages RAM
0 pages HighMem/MovableOnly
3707 pages reserved
oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),task=kexec,pid=297,uid=0
Out of memory: Killed process 297 (kexec) total-vm:4512kB, anon-rss:4104kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:24kB oom_score_adj:0

I’ve cross-compiled kexec with LDFLAGS=-static USE=-zlib ACCEPT_KEYWORDS='~*' emerge-mipsr5900el-unknown-linux-musl -av sys-apps/kexec-tools. As required by the kexec, I’ve also supplied a minimal DTB compiled from this DTS:

/dts-v1/;

/* dtc -I dts -O dtb -o ps2.dtb ps2.dts */

/ {
    model = "PlayStation 2 Linux";
    compatible = "vendor";
    #address-cells = <1>;
    #size-cells = <1>;

    memory@0 {
        device_type = "memory";
        reg = <0x0 0x2000000>; /* 32 MiB of RAM starting at 0x0 */
    };

    chosen {
        bootargs = "";
    };

    cpus {
        #address-cells = <1>;
        #size-cells = <0>;

        cpu@0 {
            device_type = "cpu";
            compatible = "mips";
            reg = <0>;
        };
    };
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions