Why do kernel panics caused by init exiting peg the CPU?

From: Andrei E.
Date: Wed Jun 16 2021 - 06:22:37 EST


Good morning LKML,

I have noticed that using a very simple hello world program as init (very similar to the one from https://landley.net/writing/rootfs-howto.html, just with the sleep function removed) pegs the CPU on both linux (5.12.10.arch1-1) and linux-lts (5.10.43-1) kernels on Arch. Is this intended?

Steps to reproduce:
#!/bin/sh
cat << END > hello.c
#include <stdio.h>

int main(int argc, char *argv[])
{
  printf("Hello world\n");
}
END

gcc -static hello.c -o hello

mkdir sub
cp hello sub/init
cd sub
find . | cpio -o -H newc | gzip > ../initramfs_data.cpio.gz
cd ..
rm -rf sub

qemu-system-x86_64 -kernel /boot/vmlinuz-linux-lts -initrd initramfs_data.cpio.gz
# Spikes one thread to 100% usage. Causes the same issue with vmlinuz-linux.

Thank you for your time,
Andrei E.