diff --git a/README.adoc b/README.adoc index 169cb39..3667944 100644 --- a/README.adoc +++ b/README.adoc @@ -3618,6 +3618,8 @@ Basically just calls `panic("BUG!")` for most archs. ===== Exit emulator on panic +====== Exit QEMU on panic + For testing purposes, it is very useful to quit the emulator automatically in case of kernel panic, instead of just hanging forever. In QEMU, we enable it by default with: @@ -3631,13 +3633,28 @@ TODO neither method exits with exit status different from 0, so for now we are j One possibility that gets close would be to use <> to break at the `panic` function, and then send a <> `quit` command if that happens, but I don't see a way to exit with non-zero status to indicate error. +====== Exit gem5 on panic + gem5 actually detects panics and outputs: .... warn: Kernel panic in simulated kernel .... -before hanging. gem5 ff52563a214c71fcd1e21e9f00ad839612032e3b `config.ini` has a `system.panic_on_panic` and `system.panic_on_oops` params which I bet will work, but it does not seem to be exposed to `fs.py`, so we don't enable it by default, although we want to. +before hanging forever. + +We can make gem5 ff52563a214c71fcd1e21e9f00ad839612032e3b `fs.py` quit instead of hang with: + +.... +patch -d gem5/gem5 -p1 < patches/manual/gem5-panic.patch +./run -aa -F 'echo c > /proc/sysrq-trigger' -g +.... + +Source: link:patches/manual/gem5-panic.patch[]. + +It does not seem to be exposed to `fs.py`. + +However TODO it still exits with status 0... so we are just parsing the logs for now, like QEMU does. Detection seems to be symbol based: it parses the kernel image, and triggers when the PC reaches the address of a symbol: https://github.com/gem5/gem5/blob/1da285dfcc31b904afc27e440544d006aae25b38/src/arch/arm/linux/system.cc#L73 @@ -8434,21 +8451,7 @@ The `-X-b` option enables the alternative `configs/example/arm/fs_bigLITTLE.py` First apply: .... -echo ' -diff --git a/configs/example/arm/fs_bigLITTLE.py b/configs/example/arm/fs_bigLITTLE.py -index 7d66c03a6..d71e714fe 100644 ---- a/configs/example/arm/fs_bigLITTLE.py -+++ b/configs/example/arm/fs_bigLITTLE.py -@@ -194,7 +194,7 @@ def build(options): - "norandmaps", - "loglevel=8", - "mem=%s" % default_mem_size, -- "root=/dev/vda1", -+ "root=/dev/vda", - "rw", - "init=%s" % options.kernel_init, - "vmalloc=768MB", -' | patch -d gem5/gem5 -p1 +patch -d gem5/gem5 -p1 < patches/manual/gem5-biglittle.patch .... then: @@ -9320,12 +9323,6 @@ The action seems to be happening at: `hw/arm/virt.c`. ***** `out/common/gem5//build/`: main build outputs, including the `gem5.opt` executable and object files ***** `out/common/gem5//system/`: `M5_PATH` directory, with DTBs and bootloaders -==== buildroot_patches - -Every `.patch` file in this directory gets applied to Buildroot before anything else is done. - -This directory has been made kind of useless when we decided to use our own Buildroot fork, but we've kept the functionality just in case we someday go back to upstream Buildroot. - ==== gem5 directory We Build the gem5 emulator through Buildroot basically just to reuse its timestamping system to avoid rebuilds. @@ -9334,7 +9331,19 @@ There is also the `m5` tool that we must build through Buildroot ans install on This directory has the following structure: -==== global_patch_dir +==== packages directory + +Any directory in that subdirectory is added to `BR2_EXTERNAL` and become available to the build. + +==== patches + +===== patches/buildroot + +Every `.patch` file in this directory gets applied to Buildroot before anything else is done. + +This directory has been made kind of useless when we decided to use our own Buildroot fork, but we've kept the functionality just in case we someday go back to upstream Buildroot. + +===== patches/global Has the following structure: @@ -9346,9 +9355,11 @@ The patches are then applied to the corresponding packages before build. Uses `BR2_GLOBAL_PATCH_DIR`. -==== packages directory +===== patches/manual -Any directory in that subdirectory is added to `BR2_EXTERNAL` and become available to the build. +Patches in this directory are never applied automatically: it is up to users to manually apply them before usage following the instructions in this documentation. + +These are typically patches that don't contain fundamental functionality, so we don't feel like forking the target repos. ==== rootfs_overlay diff --git a/br2/default b/br2/default index ebe786d..2df7a6f 100644 --- a/br2/default +++ b/br2/default @@ -21,7 +21,7 @@ BR2_CCACHE_USE_BASEDIR=n BR2_GCC_ENABLE_GRAPHITE=y BR2_GCC_ENABLE_LTO=y BR2_GCC_ENABLE_OPENMP=y -BR2_GLOBAL_PATCH_DIR="../global_patch_dir" +BR2_GLOBAL_PATCH_DIR="../patches/global" BR2_PACKAGE_BUSYBOX_CONFIG_FRAGMENT_FILES="../busybox_config_fragment" BR2_PACKAGE_DHRYSTONE=y BR2_PACKAGE_FILE=y diff --git a/build b/build index 95156d4..49c1bce 100755 --- a/build +++ b/build @@ -137,7 +137,7 @@ if "$configure"; then cp "${kernel_config_fragment_cli_file_tmp}" "${kernel_config_fragment_cli_file}" fi cd "${common_buildroot_dir}" - for p in $(find "${common_root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do + for p in $(find "${common_root_dir}/patches/buildroot/" -maxdepth 1 -name '*.patch' -print); do patch -N -r - -p 1 < "$p" || : done br2_external='../kernel_module:../gem5:../parsec-benchmark' diff --git a/buildroot_patches/README.adoc b/buildroot_patches/README.adoc deleted file mode 100644 index de7624c..0000000 --- a/buildroot_patches/README.adoc +++ /dev/null @@ -1 +0,0 @@ -https://github.com/cirosantilli/linux-kernel-module-cheat#buildroot_patches diff --git a/global_patch_dir/README.adoc b/global_patch_dir/README.adoc deleted file mode 100644 index a680752..0000000 --- a/global_patch_dir/README.adoc +++ /dev/null @@ -1 +0,0 @@ -https://github.com/cirosantilli/linux-kernel-module-cheat#global_patch_dir diff --git a/patches/buildroot/README.adoc b/patches/buildroot/README.adoc new file mode 100644 index 0000000..9d2226a --- /dev/null +++ b/patches/buildroot/README.adoc @@ -0,0 +1 @@ +https://github.com/cirosantilli/linux-kernel-module-cheat#patches-buildroot diff --git a/patches/global/README.adoc b/patches/global/README.adoc new file mode 100644 index 0000000..f58bf8b --- /dev/null +++ b/patches/global/README.adoc @@ -0,0 +1 @@ +https://github.com/cirosantilli/linux-kernel-module-cheat#patches-global diff --git a/patches/manual/README.adoc b/patches/manual/README.adoc new file mode 100644 index 0000000..dc2fab1 --- /dev/null +++ b/patches/manual/README.adoc @@ -0,0 +1 @@ +https://github.com/cirosantilli/linux-kernel-module-cheat#patches-manual diff --git a/patches/manual/gem5-biglittle.patch b/patches/manual/gem5-biglittle.patch new file mode 100644 index 0000000..0272b90 --- /dev/null +++ b/patches/manual/gem5-biglittle.patch @@ -0,0 +1,13 @@ +diff --git a/configs/example/arm/fs_bigLITTLE.py b/configs/example/arm/fs_bigLITTLE.py +index 7d66c03a6..d71e714fe 100644 +--- a/configs/example/arm/fs_bigLITTLE.py ++++ b/configs/example/arm/fs_bigLITTLE.py +@@ -194,7 +194,7 @@ def build(options): + "norandmaps", + "loglevel=8", + "mem=%s" % default_mem_size, +- "root=/dev/vda1", ++ "root=/dev/vda", + "rw", + "init=%s" % options.kernel_init, + "vmalloc=768MB", diff --git a/patches/manual/gem5-panic.patch b/patches/manual/gem5-panic.patch new file mode 100644 index 0000000..301f053 --- /dev/null +++ b/patches/manual/gem5-panic.patch @@ -0,0 +1,11 @@ +diff --git a/configs/example/fs.py b/configs/example/fs.py +index 4031fd05e..0f502a34a 100644 +--- a/configs/example/fs.py ++++ b/configs/example/fs.py +@@ -395,5 +395,6 @@ if buildEnv['TARGET_ISA'] == "arm" and options.generate_dtb: + sys = getattr(root, sysname) + sys.dtb_filename = create_dtb_for_system(sys, '%s.dtb' % sysname) + ++test_sys.panic_on_panic = True + Simulation.setWorkCountOptions(test_sys, options) + Simulation.run(options, root, test_sys, FutureClass) diff --git a/run b/run index 16e1ceb..0236c91 100755 --- a/run +++ b/run @@ -389,9 +389,7 @@ ${extra_flags}\ " fi "${common_root_dir}/eeval" "$cmd" "${common_run_dir}/run.sh" -if ! "$common_gem5"; then - if grep 'Kernel panic - not syncing' "$common_termout_file"; then - echo 'Kernel panic detected by parsing the terminal output. Exiting with status 1.' - exit 1 - fi +if grep 'Kernel panic - not syncing' "$common_termout_file"; then + echo 'Kernel panic detected by parsing the terminal output. Exiting with status 1.' + exit 1 fi