diff --git a/index.html b/index.html index bf68eb3..6c099a4 100644 --- a/index.html +++ b/index.html @@ -556,8 +556,9 @@ pre{ white-space:pre }
  • 2.5. GDB step debug early boot
  • 2.6. GDB step debug userland processes @@ -853,184 +854,183 @@ pre{ white-space:pre }
  • -
  • 15.5. Linux kernel entry point
  • -
  • 15.6. Kernel module APIs +
  • 15.5. Kernel module APIs
  • -
  • 15.7. Kernel panic and oops +
  • 15.6. Kernel panic and oops
  • -
  • 15.8. Pseudo filesystems +
  • 15.7. Pseudo filesystems
  • -
  • 15.9. Pseudo files +
  • 15.8. Pseudo files
  • -
  • 15.10. kthread +
  • 15.9. kthread
  • -
  • 15.11. Timers
  • -
  • 15.12. IRQ +
  • 15.10. Timers
  • +
  • 15.11. IRQ
  • -
  • 15.13. Kernel utility functions +
  • 15.12. Kernel utility functions
  • -
  • 15.14. Linux kernel tracing +
  • 15.13. Linux kernel tracing
  • -
  • 15.15. Linux kernel hardening +
  • 15.14. Linux kernel hardening
  • -
  • 15.16. User mode Linux
  • -
  • 15.17. UIO
  • -
  • 15.18. Linux kernel interactive stuff +
  • 15.15. User mode Linux
  • +
  • 15.16. UIO
  • +
  • 15.17. Linux kernel interactive stuff
  • -
  • 15.19. DRM +
  • 15.18. DRM
  • -
  • 15.20. Linux kernel testing +
  • 15.19. Linux kernel testing
  • -
  • 15.21. Linux kernel build system +
  • 15.20. Linux kernel build system
  • -
  • 15.22. Virtio
  • -
  • 15.23. Kernel modules +
  • 15.21. Virtio
  • +
  • 15.22. Kernel modules
  • @@ -1224,7 +1224,7 @@ pre{ white-space:pre }
  • 19.16.5. gem5 sanitation build
  • 19.16.6. gem5 Ruby build
  • @@ -1453,149 +1453,150 @@ pre{ white-space:pre }
  • 22. Userland content
  • 23. Userland assembly @@ -1646,7 +1647,7 @@ pre{ white-space:pre }
  • 23.8. Linux calling conventions
  • @@ -2056,7 +2057,7 @@ pre{ white-space:pre }
  • 30.2.1. Benchmark Linux kernel boot
  • 30.2.2. Benchmark emulators on userland executables @@ -2232,7 +2233,7 @@ pre{ white-space:pre }
  • 34.15.1.1. Userland objects vs header-only
  • -
  • 34.15.2. buildroot_packages directory +
  • 34.15.2. buildroot_packages directory @@ -2243,15 +2244,15 @@ pre{ white-space:pre }
  • 34.15.3.2. patches/manual directory
  • -
  • 34.15.4. rootfs_overlay +
  • 34.15.4. rootfs_overlay
  • 34.15.5. lkmc.c
  • -
  • 34.15.6. lkmc_home
  • +
  • 34.15.6. lkmc_home
  • 34.15.7. path_properties.py
  • -
  • 34.15.8. rand_check.out
  • +
  • 34.15.8. rand_check.out
  • 34.16. Test this repo @@ -2449,7 +2450,7 @@ cd linux-kernel-module-cheat

    but you will soon find that they are simply not enough if you anywhere near serious about systems programming.

    -

    After ./run, QEMU opens up leaving you in the /lkmc/ directory, and you can start playing with the kernel modules inside the simulated system:

    +

    After ./run, QEMU opens up leaving you in the /lkmc/ directory, and you can start playing with the kernel modules inside the simulated system:

    @@ -3789,7 +3790,7 @@ dmesg

    userland/

  • -

    rootfs_overlay

    +

    rootfs_overlay

  • Add new Buildroot packages

    @@ -3980,7 +3981,7 @@ cd userland
    -

    build-userland-in-tre is in turn just a thin wrapper around build-userland:

    +

    build-userland-in-tree is in turn just a thin wrapper around build-userland:

    @@ -5200,7 +5201,31 @@ echo 'file kernel/module.c +p' > /sys/kernel/debug/dynamic_debug/control
    -

    TODO why can’t we break at early startup stuff such as:

    +

    Note however that early boot parts appear to be relocated in memory somehow, and therefore:

    +
    +
    + +
    +
    +

    Further discussion at: Linux kernel entry point.

    +
    +
    +

    2.5.1. Linux kernel entry point

    + +
    +

    As mentioned at: GDB step debug early boot, the very first kernel instructions executed appear to be placed into memory at a different location than that of the kernel ELF section.

    +
    +
    +

    As a result, we are unable to break on early symbols such as:

    @@ -5209,46 +5234,10 @@ echo 'file kernel/module.c +p' > /sys/kernel/debug/dynamic_debug/control
    -

    Maybe it is because they are being copied around at specific locations instead of being run directly from inside the main image, which is where the debug information points to?

    +

    gem5 ExecAll trace format>> however does show the right symbols however! This could be because gem5 uses vmlinux to boot, which QEMU uses the compressed version, and as mentioned on the Stack Overflow answer, the entry point is actually a tiny decompresser routine.

    -
    -

    gem5 tracing with --debug-flags=Exec does show the right symbols however! So in the worst case, we can just read their source. Amazing.

    -
    -
    -

    v4.19 also added a CONFIG_HAVE_KERNEL_UNCOMPRESSED=y option for having the kernel uncompressed which could make following the startup easier, but it is only available on s390. aarch64 however is already uncompressed by default, so might be the easiest one. See also: Section 15.21.1, “vmlinux vs bzImage vs zImage vs Image”.

    -
    -
    -

    2.5.1. GDB step debug early boot by address

    -
    -

    One possibility is to run:

    -
    -
    -
    -
    ./trace-boot --arch arm
    -
    -
    -
    -

    and then find the second address (the first one does not work, already too late maybe):

    -
    -
    -
    -
    less "$(./getvar --arch arm trace_txt_file)"
    -
    -
    -
    -

    and break there:

    -
    -
    -
    -
    ./run --arch arm --gdb-wait
    -./run-gdb --arch arm '*0x1000'
    -
    -
    -
    -

    but TODO: it does not show the source assembly under arch/arm: https://stackoverflow.com/questions/11423784/qemu-arm-linux-kernel-boot-debug-no-source-code

    +

    In gem5 aarch64 Linux v4.18, experimentally the entry point of secondary CPUs seems to be secondary_holding_pen as shown at https://gist.github.com/cirosantilli2/34a7bc450fcb6c1c1a910369be1fdd90

    I also tried to hack run-gdb with:

    @@ -5269,9 +5258,31 @@ echo 'file kernel/module.c +p' > /sys/kernel/debug/dynamic_debug/control

    and no I do have the symbols from arch/arm/boot/compressed/vmlinux', but the breaks still don’t work.

    +
    +

    v4.19 also added a CONFIG_HAVE_KERNEL_UNCOMPRESSED=y option for having the kernel uncompressed which could make following the startup easier, but it is only available on s390. aarch64 however is already uncompressed by default, so might be the easiest one. See also: Section 15.20.1, “vmlinux vs bzImage vs zImage vs Image”.

    +
    +
    +

    You then need the associated KERNEL_UNCOMPRESSED to enable it if available:

    +
    +
    +
    +
    config KERNEL_UNCOMPRESSED
    +    bool "None"
    +    depends on HAVE_KERNEL_UNCOMPRESSED
    +
    +
    +
    +

    2.5.3. Linux kernel early boot messages

    When booting Linux on a slow emulator like gem5, what you observe is that:

    @@ -7520,7 +7531,7 @@ cat f
    -

    We think that this might be because gem5 boots directly vmlinux, and not from the final compressed images that contain the attached rootfs such as bzImage, which is what QEMU does, see also: Section 15.21.1, “vmlinux vs bzImage vs zImage vs Image”.

    +

    We think that this might be because gem5 boots directly vmlinux, and not from the final compressed images that contain the attached rootfs such as bzImage, which is what QEMU does, see also: Section 15.20.1, “vmlinux vs bzImage vs zImage vs Image”.

    To do this failed test, we automatically pass a dummy disk image as of gem5 7fa4c946386e7207ad5859e8ade0bbfc14000d91 since the scripts don’t handle a missing --disk-image well, much like is currently done for Baremetal.

    @@ -8139,7 +8150,7 @@ qw er
    -

    Here is an interesting examples of this: Section 15.20.1, “Linux Test Project”

    +

    Here is an interesting examples of this: Section 15.19.1, “Linux Test Project”

    @@ -8953,7 +8964,7 @@ Program aborted at tick 0

    modules built with Buildroot, see: Section 34.15.2.1, “kernel_modules buildroot package”

  • -

    modules built from the kernel tree itself, see: Section 15.12.2, “dummy-irq”

    +

    modules built from the kernel tree itself, see: Section 15.11.2, “dummy-irq”

  • @@ -11005,7 +11016,7 @@ mount

    15.3.4. norandmaps

    -

    Disable userland address space randomization. Test it out by running rand_check.out twice:

    +

    Disable userland address space randomization. Test it out by running rand_check.out twice:

    @@ -11463,18 +11474,9 @@ insmod myprintk.ko
    -

    15.5. Linux kernel entry point

    - -
    -

    In gem5 aarc64 Linux v4.18, experimentally the entry point of secondary CPUs seems to be secondary_holding_pen as shown at https://gist.github.com/cirosantilli2/34a7bc450fcb6c1c1a910369be1fdd90

    -
    -
    -
    -

    15.6. Kernel module APIs

    +

    15.5. Kernel module APIs

    -

    15.6.1. Kernel module parameters

    +

    15.5.1. Kernel module parameters

    The Linux kernel allows passing module parameters at insertion time through the init_module and finit_module system calls.

    @@ -11547,7 +11549,7 @@ parm: i:my favorite int
    -
    15.6.1.1. modprobe.conf
    +
    15.5.1.1. modprobe.conf

    modprobe insertion can also set default parameters via the /etc/modprobe.conf file:

    @@ -11574,7 +11576,7 @@ cat /sys/kernel/debug/lkmc_params
    -

    15.6.2. Kernel module dependencies

    +

    15.5.2. Kernel module dependencies

    One module can depend on symbols of another module that are exported with EXPORT_SYMBOL:

    @@ -11687,7 +11689,7 @@ extra/dep.ko:

    TODO: what for, and at which point point does Buildroot / BusyBox generate that file?

    -
    15.6.2.1. Kernel module dependencies with modprobe
    +
    15.5.2.1. Kernel module dependencies with modprobe

    Unlike insmod, modprobe deals with kernel module dependencies for us.

    @@ -11773,7 +11775,7 @@ buildroot_dep 16384 1 buildroot_dep2
    -

    15.6.3. MODULE_INFO

    +

    15.5.3. MODULE_INFO

    Module metadata is stored on module files at compile time. Some of the fields can be retrieved through the THIS_MODULE struct module:

    @@ -11893,7 +11895,7 @@ vermagic: 4.17.0 SMP mod_unload modversions
    -

    15.6.4. vermagic

    +

    15.5.4. vermagic

    Vermagic is a magic string present in the kernel and on MODULE_INFO of kernel modules. It is used to verify that the kernel module was compiled against a compatible kernel version and relevant configuration:

    @@ -11972,7 +11974,7 @@ vermagic: 4.17.0 SMP mod_unload modversions
    -

    15.6.5. init_module

    +

    15.5.5. init_module

    init_module and cleanup_module are an older alternative to the module_init and module_exit macros:

    @@ -11999,7 +12001,7 @@ cleanup_module
    -

    15.6.6. Floating point in kernel modules

    +

    15.5.6. Floating point in kernel modules

    It is generally hard / impossible to use floating point operations in the kernel. TODO understand details.

    @@ -12070,7 +12072,7 @@ cleanup_module
    -

    15.7. Kernel panic and oops

    +

    15.6. Kernel panic and oops

    To test out kernel panics and oops in controlled circumstances, try out the modules:

    @@ -12134,7 +12136,7 @@ insmod oops.ko
    -

    15.7.1. Kernel panic

    +

    15.6.1. Kernel panic

    On panic, the kernel dies, and so does our terminal.

    @@ -12184,7 +12186,7 @@ Kernel Offset: disabled
    -
    15.7.1.1. Kernel module stack trace to source line
    +
    15.6.1.1. Kernel module stack trace to source line

    The log shows which module each symbol belongs to if any, e.g.:

    @@ -12250,25 +12252,25 @@ Kernel Offset: disabled
    -
    15.7.1.2. BUG_ON
    +
    15.6.1.2. BUG_ON

    Basically just calls panic("BUG!") for most archs.

    -
    15.7.1.3. Exit emulator on panic
    +
    15.6.1.3. Exit emulator on panic

    For testing purposes, it is very useful to quit the emulator automatically with exit status non zero in case of kernel panic, instead of just hanging forever.

    -
    15.7.1.3.1. Exit QEMU on panic
    +
    15.6.1.3.1. Exit QEMU on panic

    Enabled by default with:

    -
    15.7.1.3.2. Exit gem5 on panic
    +
    15.6.1.3.2. Exit gem5 on panic

    gem5 9048ef0ffbf21bedb803b785fb68f83e95c04db8 (January 2019) can detect panics automatically if the option system.panic_on_panic is on.

    @@ -12347,7 +12349,7 @@ Kernel Offset: disabled
    -
    15.7.1.4. Reboot on panic
    +
    15.6.1.4. Reboot on panic

    Make the kernel reboot after n seconds after panic:

    @@ -12377,7 +12379,7 @@ Kernel Offset: disabled
    -
    15.7.1.5. Panic trace show addresses instead of symbols
    +
    15.6.1.5. Panic trace show addresses instead of symbols

    If CONFIG_KALLSYMS=n, then addresses are shown on traces instead of symbol plus offset.

    @@ -12416,7 +12418,7 @@ Kernel Offset: disabled
    -

    15.7.2. Kernel oops

    +

    15.6.2. Kernel oops

    On oops, the shell still lives after.

    @@ -12533,7 +12535,7 @@ CR2: 0000000000000000
    -

    15.7.3. dump_stack

    +

    15.6.3. dump_stack

    The dump_stack function produces a stack trace much like panic and oops, but causes no problems and we return to the normal control flow, and can cleanly remove the module afterwards:

    @@ -12547,7 +12549,7 @@ CR2: 0000000000000000
    -

    15.7.4. WARN_ON

    +

    15.6.4. WARN_ON

    The WARN_ON macro basically just calls dump_stack.

    @@ -12568,7 +12570,7 @@ insmod warn_on.ko
    -

    15.7.5. not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

    +

    15.6.5. not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

    Let’s learn how to diagnose problems with the root filesystem not being found. TODO add a sample panic error message for each error type:

    @@ -12719,7 +12721,7 @@ CONFIG_VIRTIO_PCI=y
    -

    15.8. Pseudo filesystems

    +

    15.7. Pseudo filesystems

    Pseudo filesystems are filesystems that don’t represent actual files in a hard disk, but rather allow us to do special operations on filesystem-related system calls.

    @@ -12740,7 +12742,7 @@ CONFIG_VIRTIO_PCI=y
    -

    15.8.1. debugfs

    +

    15.7.1. debugfs

    Debugfs is the simplest pseudo filesystem to play around with:

    @@ -12804,7 +12806,7 @@ echo $?
    -

    15.8.2. procfs

    +

    15.7.2. procfs

    Procfs is just another fops entry point:

    @@ -12855,7 +12857,7 @@ echo $?
    -
    15.8.2.1. /proc/version
    +
    15.7.2.1. /proc/version

    Its data is shared with uname(), which is a POSIX C function and has a Linux syscall to back it up.

    @@ -12896,7 +12898,7 @@ echo $?
    -

    15.8.3. sysfs

    +

    15.7.3. sysfs

    Sysfs is more restricted than procfs, as it does not take an arbitrary file_operations:

    @@ -12976,7 +12978,7 @@ echo $?
    -

    15.8.4. Character devices

    +

    15.7.4. Character devices

    Character devices can have arbitrary File operations associated to them:

    @@ -13070,7 +13072,7 @@ echo $?

    Bibliography: https://unix.stackexchange.com/questions/37829/understanding-character-device-or-character-special-files/371758#371758

    -
    15.8.4.1. Automatically create character device file on insmod
    +
    15.7.4.1. Automatically create character device file on insmod

    And also destroy it on rmmod:

    @@ -13108,9 +13110,9 @@ echo $?
    -

    15.9. Pseudo files

    +

    15.8. Pseudo files

    -

    15.9.1. File operations

    +

    15.8.1. File operations

    File operations are the main method of userland driver communication.

    @@ -13163,7 +13165,7 @@ echo $?
    -

    15.9.2. seq_file

    +

    15.8.2. seq_file

    Writing trivial read File operations is repetitive and error prone. The seq_file API makes the process much easier for those trivial cases:

    @@ -13224,7 +13226,7 @@ echo $?
    -
    15.9.2.1. seq_file single_open
    +
    15.8.2.1. seq_file single_open

    If you have the entire read output upfront, single_open is an even more convenient version of seq_file:

    @@ -13267,7 +13269,7 @@ cd
    -

    15.9.3. poll

    +

    15.8.3. poll

    The poll system call allows an user process to do a non-busy wait on a kernel event.

    @@ -13372,7 +13374,7 @@ POLLIN n=10 buf=4294893839
    -

    15.9.4. ioctl

    +

    15.8.4. ioctl

    The ioctl system call is the best way to pass an arbitrary number of parameters to the kernel in a single go:

    @@ -13469,7 +13471,7 @@ echo $?
    -

    15.9.5. mmap

    +

    15.8.5. mmap

    The mmap system call allows us to share memory between user and kernel space without copying:

    @@ -13539,7 +13541,7 @@ echo $?
    -

    15.9.6. Anonymous inode

    +

    15.8.6. Anonymous inode

    Anonymous inodes allow getting multiple file descriptors from a single filesystem entry, which reduces namespace pollution compared to creating multiple device files:

    @@ -13587,7 +13589,7 @@ echo $?
    - +

    Netlink sockets offer a socket API for kernel / userland communication:

    @@ -13652,7 +13654,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.10. kthread

    +

    15.9. kthread

    Kernel threads are managed exactly like userland threads; they also have a backing task_struct, and are scheduled with the same mechanism:

    @@ -13690,7 +13692,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    The sleep is done with usleep_range, see: Section 15.10.2, “sleep”.

    +

    The sleep is done with usleep_range, see: Section 15.9.2, “sleep”.

    Bibliography:

    @@ -13706,7 +13708,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.10.1. kthreads

    +

    15.9.1. kthreads

    Let’s launch two threads and see if they actually run in parallel:

    @@ -13749,7 +13751,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.10.2. sleep

    +

    15.9.2. sleep

    Count to dmesg every one second from 0 up to n - 1:

    @@ -13779,7 +13781,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.10.3. Workqueues

    +

    15.9.3. Workqueues

    A more convenient front-end for kthread:

    @@ -13812,7 +13814,7 @@ for i in `seq 16`; do ./netlink.out & done

    Bibliography: https://github.com/torvalds/linux/blob/v4.17/Documentation/core-api/workqueue.rst

    -
    15.10.3.1. Workqueue from workqueue
    +
    15.9.3.1. Workqueue from workqueue

    Count from 0 to 9 every second infinitely many times by scheduling a new work item from a work item:

    @@ -13838,7 +13840,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.10.4. schedule

    +

    15.9.4. schedule

    Let’s block the entire kernel! Yay:

    @@ -13885,7 +13887,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.10.5. Wait queues

    +

    15.9.5. Wait queues

    Wait queues are a way to make a thread sleep until an event happens on the queue:

    @@ -13949,7 +13951,7 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.11. Timers

    +

    15.10. Timers

    Count from 0 to 9 infinitely many times in 1 second intervals using timers:

    @@ -13990,9 +13992,9 @@ for i in `seq 16`; do ./netlink.out & done
    -

    15.12. IRQ

    +

    15.11. IRQ

    -

    15.12.1. irq.ko

    +

    15.11.1. irq.ko

    Brute force monitor every shared interrupt that will accept us:

    @@ -14098,7 +14100,7 @@ request_irq irq = 1 ret = 0
    -

    15.12.2. dummy-irq

    +

    15.11.2. dummy-irq

    The Linux kernel v4.16 mainline also has a dummy-irq module at drivers/misc/dummy-irq.c for monitoring a single IRQ.

    @@ -14156,7 +14158,7 @@ request_irq irq = 1 ret = 0
    -

    15.12.3. /proc/interrupts

    +

    15.11.3. /proc/interrupts

    In the guest with QEMU graphic mode:

    @@ -14190,12 +14192,12 @@ request_irq irq = 1 ret = 0
    -

    15.13. Kernel utility functions

    +

    15.12. Kernel utility functions

    https://github.com/torvalds/linux/blob/v4.17/Documentation/core-api/kernel-api.rst

    -

    15.13.1. kstrto

    +

    15.12.1. kstrto

    Convert a string to an integer:

    @@ -14231,7 +14233,7 @@ echo $?
    -

    15.13.2. virt_to_phys

    +

    15.12.2. virt_to_phys

    Convert a virtual address to physical:

    @@ -14301,7 +14303,7 @@ virt_to_phys(&static_var) = 0x40002308
    -
    15.13.2.1. Userland physical address experiments
    +
    15.12.2.1. Userland physical address experiments

    Only tested in x86_64.

    @@ -14422,7 +14424,7 @@ pid 110
    -
    15.13.2.1.1. QEMU xp
    +
    15.12.2.1.1. QEMU xp

    The xp QEMU monitor command reads memory at a given physical address.

    @@ -14453,7 +14455,7 @@ pid 110
    -
    15.13.2.1.2. /dev/mem
    +
    15.12.2.1.2. /dev/mem

    /dev/mem exposes access to physical addresses, and we use it through the convenient devmem BusyBox utility.

    @@ -14529,7 +14531,7 @@ Value at address 0X7C7B800 (0x7ff7dbe01800): 0x12345678
    -
    15.13.2.1.3. pagemap_dump.out
    +
    15.12.2.1.3. pagemap_dump.out

    Dump the physical address of all pages mapped to a given process using /proc/<pid>/maps and /proc/<pid>/pagemap.

    @@ -14700,7 +14702,7 @@ pid 63
    -

    15.14. Linux kernel tracing

    +

    15.13. Linux kernel tracing

    Good overviews:

    @@ -14718,7 +14720,7 @@ pid 63

    I hope to have examples of all methods some day, since I’m obsessed with visibility.

    -

    15.14.1. CONFIG_PROC_EVENTS

    +

    15.13.1. CONFIG_PROC_EVENTS

    Logs proc events such as process creation to a netlink socket.

    @@ -14785,7 +14787,7 @@ a
    -
    15.14.1.1. CONFIG_PROC_EVENTS aarch64
    +
    15.13.1.1. CONFIG_PROC_EVENTS aarch64

    0111ca406bdfa6fd65a2605d353583b4c4051781 was failing with:

    @@ -14855,7 +14857,7 @@ make: *** [_all] Error 2
    -

    15.14.2. ftrace

    +

    15.13.2. ftrace

    Trace a single function:

    @@ -14963,13 +14965,13 @@ echo function_graph > current_tracer

    TODO: can you get function arguments? https://stackoverflow.com/questions/27608752/does-ftrace-allow-capture-of-system-call-arguments-to-the-linux-kernel-or-only

    -
    15.14.2.1. ftrace system calls
    +
    15.13.2.1. ftrace system calls

    https://stackoverflow.com/questions/29840213/how-do-i-trace-a-system-call-in-linux/51856306#51856306

    -
    15.14.2.2. trace-cmd
    +
    15.13.2.2. trace-cmd

    TODO example:

    @@ -14981,7 +14983,7 @@ echo function_graph > current_tracer
    -

    15.14.3. Kprobes

    +

    15.13.3. Kprobes

    kprobes is an instrumentation mechanism that injects arbitrary code at a given address in a trap instruction, much like GDB. Oh, the good old kernel. :-)

    @@ -15046,7 +15048,7 @@ sleep 4 & sleep 4 &
    -

    15.14.4. Count boot instructions

    +

    15.13.4. Count boot instructions

    TODO: didn’t port during refactor after 3b0a343647bed577586989fb702b760bd280844a. Reimplementing should not be hard.

    @@ -15238,12 +15240,12 @@ instructions_firmware 20708
    -

    15.15. Linux kernel hardening

    +

    15.14. Linux kernel hardening

    Make it harder to get hacked and easier to notice that you were, at the cost of some (small?) runtime overhead.

    -

    15.15.1. CONFIG_FORTIFY_SOURCE

    +

    15.14.1. CONFIG_FORTIFY_SOURCE

    Detects buffer overflows for us:

    @@ -15288,12 +15290,12 @@ detected buffer overflow in strlen
    -

    15.15.2. Linux security modules

    +

    15.14.2. Linux security modules

    https://en.wikipedia.org/wiki/Linux_Security_Modules

    -
    15.15.2.1. SELinux
    +
    15.14.2.1. SELinux

    TODO get a hello world permission control working:

    @@ -15390,7 +15392,7 @@ detected buffer overflow in strlen
    -

    15.16. User mode Linux

    +

    15.15. User mode Linux

    I once got UML running on a minimal Buildroot setup at: https://unix.stackexchange.com/questions/73203/how-to-create-rootfs-for-user-mode-linux-on-fedora-18/372207#372207

    @@ -15402,7 +15404,7 @@ detected buffer overflow in strlen
    -

    15.17. UIO

    +

    15.16. UIO

    UIO is a kernel subsystem that allows to do certain types of driver operations from userland.

    @@ -15510,9 +15512,9 @@ detected buffer overflow in strlen
    -

    15.18. Linux kernel interactive stuff

    +

    15.17. Linux kernel interactive stuff

    -

    15.18.1. Linux kernel console fun

    +

    15.17.1. Linux kernel console fun

    Requires Graphics.

    @@ -15556,7 +15558,7 @@ detected buffer overflow in strlen
    -

    15.18.2. Linux kernel magic keys

    +

    15.17.2. Linux kernel magic keys

    Requires Graphics.

    @@ -15593,7 +15595,7 @@ sendkey shift-pgdown
    -
    15.18.2.1. Ctrl Alt Del
    +
    15.17.2.1. Ctrl Alt Del

    If you run in QEMU graphic mode:

    @@ -15627,7 +15629,7 @@ sendkey shift-pgdown
    -

    This leads Linux to try to reboot, and QEMU shutdowns due to the -no-reboot option which we set by default for, see: Section 15.7.1.3, “Exit emulator on panic”.

    +

    This leads Linux to try to reboot, and QEMU shutdowns due to the -no-reboot option which we set by default for, see: Section 15.6.1.3, “Exit emulator on panic”.

    Here is a minimal example of Ctrl Alt Del:

    @@ -15811,7 +15813,7 @@ static void halt_reboot_pwoff(int sig)
    -
    15.18.2.2. SysRq
    +
    15.17.2.2. SysRq

    We cannot test these actual shortcuts on QEMU since the host captures them at a lower level, but from:

    @@ -15882,7 +15884,7 @@ static void halt_reboot_pwoff(int sig)
    -

    15.18.3. TTY

    +

    15.17.3. TTY

    In order to play with TTYs, do this:

    @@ -16121,7 +16123,7 @@ tty63::respawn:-/bin/sh
    -
    15.18.3.1. Start a getty from outside of init
    +
    15.17.3.1. Start a getty from outside of init

    TODO: https://unix.stackexchange.com/questions/196704/getty-start-from-command-line

    @@ -16178,7 +16180,7 @@ tty63::respawn:-/bin/sh
    -
    15.18.3.2. console kernel boot parameter
    +
    15.17.3.2. console kernel boot parameter

    Take the command described at TTY and try adding the following:

    @@ -16214,7 +16216,7 @@ tty63::respawn:-/bin/sh
    - +

    If you run in Graphics, then you get a Penguin image for every core above the console! https://askubuntu.com/questions/80938/is-it-possible-to-get-the-tux-logo-on-the-text-based-boot

    @@ -16258,7 +16260,7 @@ tty63::respawn:-/bin/sh
    -

    15.19. DRM

    +

    15.18. DRM

    DRM / DRI is the new interface that supersedes fbdev:

    @@ -16341,7 +16343,7 @@ crw------- 1 root root 226, 0 May 28 09:41 card0

    Tested on: 93e383902ebcc03d8a7ac0d65961c0e62af9612b

    -

    15.19.1. kmscube

    +

    15.18.1. kmscube

    ./build-buildroot --config-fragment buildroot_config/kmscube
    @@ -16403,7 +16405,7 @@ failed to initialize legacy DRM
    -

    15.19.2. kmscon

    +

    15.18.2. kmscon

    TODO get working.

    @@ -16424,7 +16426,7 @@ failed to initialize legacy DRM
    -

    15.19.3. libdri2

    +

    15.18.3. libdri2

    TODO get working.

    @@ -16450,12 +16452,12 @@ wget \
    -

    15.20. Linux kernel testing

    +

    15.19. Linux kernel testing

    Bibliography: https://stackoverflow.com/questions/3177338/how-is-the-linux-kernel-tested

    -

    15.20.1. Linux Test Project

    +

    15.19.1. Linux Test Project

    @@ -16502,7 +16504,7 @@ wget \
    -

    15.20.2. stress

    +

    15.19.2. stress

    POSIX userland stress. Two versions:

    @@ -16557,9 +16559,9 @@ ps
    -

    15.21. Linux kernel build system

    +

    15.20. Linux kernel build system

    -

    15.21.1. vmlinux vs bzImage vs zImage vs Image

    +

    15.20.1. vmlinux vs bzImage vs zImage vs Image

    Between all archs on QEMU and gem5 we touch all of those kernel built output files.

    @@ -16575,7 +16577,7 @@ ps
    -

    15.22. Virtio

    +

    15.21. Virtio

    https://www.linux-kvm.org/page/Virtio

    @@ -16593,9 +16595,9 @@ ps
    -

    15.23. Kernel modules

    +

    15.22. Kernel modules

    -

    15.23.1. dump_regs

    +

    15.22.1. dump_regs

    The following kernel modules and Baremetal executables dump and disassemble various registers which cannot be observed from userland (usually "system registers", "control registers"):

    @@ -18387,7 +18389,7 @@ less "$(./getvar --arch x86_64 run_dir)/trace-lines.txt"

    timestamps of dmesg output

  • -

    rand_check.out output

    +

    rand_check.out output

  • @@ -22491,7 +22493,7 @@ cat "$(./getvar --arch aarch64 --emulator gem5 trace_txt_file)"

    Tested in gem5 d7d9bc240615625141cd6feddbadd392457e49eb.

    -
    19.16.6.1. gem5 Ruby MI_example protocol
    +
    19.16.6.1. gem5 Ruby MI_example protocol

    This is the simplest of all protocols, and therefore the first one you should study to learn how Ruby works.

    @@ -29862,40 +29864,51 @@ make menuconfig

    21.5. Add new files to the Buildroot image

    -

    There are basically two choices:

    +

    These are your options:

    • create a Buildroot package: Add new Buildroot packages

      +
      +

      This is the most general option, but the most laborious. No big deal if you copy our template however as shown in that section.

      +
      +
      +

      Handles any type of cross compilation, including multiple input sources.

      +
    • -

      drop your files directly in rootfs_overlay and follow instructions from that section

      -
    • -
    +

    drop your files directly in rootfs_overlay and follow instructions from that section.

    +
    +

    Files in that directory are directly copied to the image, so this is the best option for files that don’t need to be compiled such as Interpreted languages.

    -

    If you need to cross compile input files such as C for the guest, then Buildroot packages are definitely the cleaner option as they make cross compilation easy.

    +

    You could also use this method to inject compiled binaries into the image for quick-and-dirty testing.

    -

    However, for a quick initial prototype, it should be fine to just manually compile your files and drop them in rootfs_overlay.

    +

    But it will be much more likely to work if you use our cross compiler with run-toolchain or getvar.

    -

    Ideally, you should still use the Buildroot cross compiler for this which ensures compatibility.

    +

    If you can’t do that, at the very least make it statically with -static compiled to remove the possibility of binary mismatch with our dynamic glibc.

    -

    The best way to do that is to use either run-toolchain or getvar.

    +

    But things can still break if your random glibc is configured to work with a newer Linux kernel than ours.

    -

    In case you can’t for some reason, e.g. if you need to use your own custom toolchain, you should:

    +

    It often just works even if they are not perfectly matched however, partly because the Linux kernel is highly backwards compatible

    -
    -
      -
    • -

      make sure that you have built your toolchain to match the our kernel version. It often just works even if they are not perfectly matched however, partly because the Linux kernel is highly backwards compatible

    • -

      build statically with -static to avoid binary compatibility issues with our own glibc

      +

      fork this repo and add new files to userland/ or kernel_modules/

      +
      +

      To add a simple executable that compiles from a single source file, like the dozens of examples that we have, you could just go this route.

      +
      +
      +

      This mechanisms bypasses having to create/modify Buildroot packages, and is very simple when you have a single input single output executable.

      +
      +
    • +
    • +

      9P. OK, this is not really adding to the image, but it is the most convenient way to quickly modify a binary on the host, cross compile, and test it out without rebooting.

    @@ -29931,7 +29944,7 @@ make menuconfig

    If none of those methods are flexible enough for you, you can just fork or hack up buildroot_packages/sample_package the sample package to do what you want.

    -

    For how to use that package, see: Section 34.15.2, “buildroot_packages directory”.

    +

    For how to use that package, see: Section 34.15.2, “buildroot_packages directory”.

    Then iterate trying to do what you want and reading the manual until it works: https://buildroot.org/downloads/manual/manual.html

    @@ -29950,7 +29963,7 @@ make menuconfig

    Also mentioned at: https://stackoverflow.com/questions/47320800/how-to-clean-only-target-in-buildroot

    -

    See this for a sample manual workaround: Section 22.8.1.4, “PARSEC uninstall”.

    +

    See this for a sample manual workaround: Section 22.9.1.4, “PARSEC uninstall”.

    @@ -30470,7 +30483,64 @@ cd ../..

    This section was originally moved in here from: https://github.com/cirosantilli/cpp-cheat

    -

    22.1. C

    +

    22.1. build-userland

    + + +
    +

    Build all with:

    +
    +
    +
    +
    ./build-userland
    +
    +
    +
    +

    or build only those under e.g. userland/c with:

    +
    +
    +
    +
    ./build-userland userland/c
    +
    +
    +
    +

    The executables are not automatically added to the Buildroot image, you must follow the command with a ./build-buildroot command as in:

    +
    +
    +
    +
    ./build-userland
    +./build-buildroot
    +
    +
    +
    +

    Remember that certain executables have specific requirements, e.g.:

    +
    +
    + +
    +
    +

    Default: build all examples that have their package dependencies met, e.g.:

    +
    +
    +
      +
    • +

      an OpenBLAS example can only be built if the target root filesystem has the OpenBLAS libraries and headers installed, which you must inform with --package

      +
    • +
    +
    +
    +
    +

    22.2. C

    Programs under userland/c/ are examples of ANSI C programming:

    @@ -30609,7 +30679,7 @@ cd ../..
    -

    22.1.1. malloc

    +

    22.2.1. malloc

    @@ -30623,7 +30693,7 @@ cd ../..

    malloc leads to the infinite joys of Memory leaks.

    -
    22.1.1.1. malloc implementation
    +
    22.2.1.1. malloc implementation

    TODO: the exact answer is going to be hard.

    @@ -30668,7 +30738,7 @@ printf '%x\n' 4198400
    -
    22.1.1.2. malloc maximum size
    +
    22.2.1.2. malloc maximum size

    General overview at: https://stackoverflow.com/questions/2798330/maximum-memory-which-malloc-can-allocate

    @@ -30734,7 +30804,7 @@ echo 1 > /proc/sys/vm/overcommit_memory

    If we start using the pages, the OOM killer would sooner or later step in and kill our process: Linux out-of-memory killer.

    -
    22.1.1.2.1. Linux out-of-memory killer
    +
    22.2.1.2.1. Linux out-of-memory killer

    We can observe the OOM in LKMC 1e969e832f66cb5a72d12d57c53fb09e9721d589 which defaults to 256MiB of memory with:

    @@ -30760,7 +30830,7 @@ echo 1 > /proc/sys/vm/overcommit_memory
    -

    22.1.2. C multithreading

    +

    22.2.2. C multithreading

    Added in C11!

    @@ -30778,7 +30848,7 @@ echo 1 > /proc/sys/vm/overcommit_memory
    -
    22.1.2.1. atomic.c
    +
    22.2.2.1. atomic.c
    -

    22.1.3. GCC C extensions

    +

    22.2.3. GCC C extensions

    -
    22.1.3.1. C empty struct
    +
    22.2.3.1. C empty struct
    @@ -30884,7 +30954,7 @@ echo 1 > /proc/sys/vm/overcommit_memory
    -
    22.1.3.2. OpenMP
    +
    22.2.3.2. OpenMP

    GCC implements the OpenMP threading implementation: https://stackoverflow.com/questions/3949901/pthreads-vs-openmp

    @@ -30907,7 +30977,7 @@ echo 1 > /proc/sys/vm/overcommit_memory

    strace shows that OpenMP makes clone() syscalls in Linux. TODO: does it actually call pthread_ functions, or does it make syscalls directly? Or in other words, can it work on Freestanding programs? A quick grep shows many references to pthreads.

    -
    22.1.3.2.1. OpenMP validation
    +
    22.2.3.2.1. OpenMP validation

    https://github.com/uhhpctools/omp-validation

    @@ -31005,7 +31075,7 @@ mkdir -p bin/c
    -

    22.2. C++

    +

    22.3. C++

    Programs under userland/cpp/ are examples of ISO C programming.

    @@ -31129,7 +31199,7 @@ mkdir -p bin/c
    -

    22.2.1. C++ initialization types

    +

    22.3.1. C++ initialization types

    OMG this is hell, understand when primitive variables are initialized or not:

    @@ -31177,7 +31247,7 @@ mkdir -p bin/c
    -

    22.2.2. C++ multithreading

    +

    22.3.2. C++ multithreading

    -
    22.2.2.1. atomic.cpp
    +
    22.3.2.1. atomic.cpp
    @@ -31411,7 +31481,7 @@ time ./mutex.out 4 100000000
    -
    22.2.2.1.1. Detailed gem5 analysis of how data races happen
    +
    22.3.2.1.1. Detailed gem5 analysis of how data races happen

    The smallest data race we managed to come up as of LKMC 7c01b29f1ee7da878c7cc9cb4565f3f3cf516a92 and gem5 872cb227fdc0b4d60acc7840889d567a6936b6e1 was with userland/c/atomic.c (see also C multithreading):

    @@ -31516,7 +31586,7 @@ non-atomic 19
    -
    22.2.2.2. C++ std::memory_order
    +
    22.3.2.2. C++ std::memory_order

    https://stackoverflow.com/questions/12346487/what-do-each-memory-order-mean

    @@ -31528,7 +31598,7 @@ non-atomic 19
    -
    22.2.2.3. C++ parallel algorithms
    +
    22.3.2.3. C++ parallel algorithms

    https://stackoverflow.com/questions/51031060/are-c17-parallel-algorithms-implemented-already/55989883#55989883

    @@ -31538,7 +31608,7 @@ non-atomic 19
    -

    22.2.3. C++ standards

    +

    22.3.3. C++ standards

    Like for C, you have to pay for the standards…​ insane. So we just use the closest free drafts instead.

    @@ -31546,14 +31616,14 @@ non-atomic 19

    https://stackoverflow.com/questions/81656/where-do-i-find-the-current-c-or-c-standard-documents

    -
    22.2.3.1. C++17 N4659 standards draft
    +
    22.3.3.1. C++17 N4659 standards draft

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf

    -

    22.2.4. C++ type casting

    +

    22.3.4. C++ type casting

    userland/cpp/static_dynamic_reinterpret_cast.cpp

    @@ -31563,7 +31633,7 @@ non-atomic 19
    -

    22.3. POSIX

    +

    22.4. POSIX

    Programs under userland/posix/ are examples of POSIX C programming.

    @@ -31581,13 +31651,13 @@ non-atomic 19
    -

    22.3.1. Environment variables

    +

    22.4.1. Environment variables

    POSIX C example that prints all environment variables: userland/posix/environ.c

    -

    22.3.2. unistd.h

    +

    22.4.2. unistd.h

    -

    22.3.3. fork

    +

    22.4.3. fork

    POSIX' multiprocess API. Contrast with pthreads which are for threads.

    @@ -31625,7 +31695,7 @@ fork() return = 13039

    Read the source comments and understand everything that is going on!

    -
    22.3.3.1. getpid
    +
    22.4.3.1. getpid

    The minimal interesting example is to use fork and observe different PIDs.

    @@ -31637,7 +31707,7 @@ fork() return = 13039
    -
    22.3.3.2. Fork bomb
    +
    22.4.3.2. Fork bomb

    https://en.wikipedia.org/wiki/Fork_bomb

    @@ -31672,7 +31742,7 @@ fork() return = 13039
    -

    22.3.4. pthreads

    +

    22.4.4. pthreads

    POSIX' multithreading API. Contrast with fork which is for processes.

    @@ -31696,7 +31766,7 @@ fork() return = 13039
    -
    22.3.4.1. pthread_mutex
    +
    22.4.4.1. pthread_mutex

    userland/posix/pthread_count.c exemplifies the functions:

    @@ -31733,7 +31803,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.3.5. sysconf

    +

    22.4.5. sysconf

    https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html

    @@ -31779,7 +31849,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.3.6. mmap

    +

    22.4.6. mmap

    The mmap system call allows advanced memory operations.

    @@ -31790,7 +31860,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -
    22.3.6.1. mmap MAP_ANONYMOUS
    +
    22.4.6.1. mmap MAP_ANONYMOUS

    Basic mmap example, do the same as userland/c/malloc.c, but with mmap.

    @@ -31808,7 +31878,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -
    22.3.6.2. mmap file
    +
    22.4.6.2. mmap file

    Memory mapped file example: userland/posix/mmap_file.c

    @@ -31820,7 +31890,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -
    22.3.6.3. brk
    +
    22.4.6.3. brk

    Previously POSIX, but was deprecated in favor of malloc

    @@ -31836,7 +31906,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.3.7. socket

    +

    22.4.7. socket

    A bit like read and write, but from / to the Internet!

    @@ -31850,7 +31920,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.4. Userland multithreading

    +

    22.5. Userland multithreading

    The following sections are related to multithreading in userland:

    @@ -31912,12 +31982,12 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.5. C debugging

    +

    22.6. C debugging

    Let’s group the hard-to-debug undefined-behaviour-like stuff found in C / C+ here and how to tackle those problems.

    -

    22.5.1. Stack smashing

    +

    22.6.1. Stack smashing

    @@ -31937,7 +32007,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.5.2. Memory leaks

    +

    22.6.2. Memory leaks

    @@ -31946,7 +32016,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.5.3. Profiling userland programs

    +

    22.6.3. Profiling userland programs

    @@ -31966,12 +32036,12 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.6. Interpreted languages

    +

    22.7. Interpreted languages

    Maybe some day someone will use this setup to study the performance of interpreters.

    -

    22.6.1. Python

    +

    22.7.1. Python

    Examples:

    @@ -31996,7 +32066,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -
    22.6.1.1. Build and install the interpreter
    +
    22.7.1.1. Build and install the interpreter

    Buildroot has a Python package that can be added to the guest image:

    @@ -32055,7 +32125,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -
    22.6.1.2. Python gem5 user mode simulation
    +
    22.7.1.2. Python gem5 user mode simulation

    At LKMC 50ac89b779363774325c81157ec8b9a6bdb50a2f gem5 390a74f59934b85d91489f8a563450d8321b602da:

    @@ -32105,7 +32175,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -
    22.6.1.3. Embedding Python in another application
    +
    22.7.1.3. Embedding Python in another application

    Here we will add some better examples and explanations for: https://docs.python.org/3/extending/embedding.html#very-high-level-embedding

    @@ -32156,7 +32226,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -
    22.6.1.4. pybind11
    +
    22.7.1.4. pybind11
    @@ -32179,7 +32249,7 @@ There are no non-locking atomic types or atomic primitives in POSIX: -

    22.6.2. Node.js

    +

    22.7.2. Node.js

    @@ -32279,7 +32349,7 @@ my type is MyClassToString and a is 1 and b is 2
    -
    22.6.2.1. NPM
    +
    22.7.2.1. NPM
    @@ -32298,7 +32368,7 @@ my type is MyClassToString and a is 1 and b is 2
    -
    22.6.2.1.1. NPM data-files
    +
    22.7.2.1.1. NPM data-files

    Illustrates how to add extra non-code data files to an NPM package, and then use those files at runtime.

    @@ -32309,7 +32379,7 @@ my type is MyClassToString and a is 1 and b is 2
    -

    22.6.3. Java

    +

    22.7.3. Java

    No OpenJDK package as of 2018.08: https://stackoverflow.com/questions/28874150/buildroot-with-jamvm-2-0-for-java-8/59290927#59290927 partly because their build system is shit like the rest of the project’s setup.

    @@ -32325,7 +32395,7 @@ my type is MyClassToString and a is 1 and b is 2
    -

    22.7. Algorithms

    +

    22.8. Algorithms

    userland/algorithm

    @@ -32485,7 +32555,7 @@ cmp tmp.o tmp.e

    These are good targets for performance analysis with gem5, and there is some overlap between this section and Benchmarks.

    -

    22.7.1. BST vs heap vs hashmap

    +

    22.8.1. BST vs heap vs hashmap

    TODO: move benchmark graph from userland/cpp/bst_vs_heap_vs_hashmap.cpp to userland/algorithm/set.

    @@ -32603,7 +32673,7 @@ xdg-open bst_vs_heap_vs_hashmap_gem5.tmp.png
    -

    22.7.2. BLAS

    +

    22.8.2. BLAS

    Buildroot supports it, which makes everything just trivial:

    @@ -32655,7 +32725,7 @@ cblas_dgemm( CblasColMajor, CblasNoTrans, CblasTrans,3,3,2 ,1, A,3, B,
    -

    22.7.3. Eigen

    +

    22.8.3. Eigen

    Header only linear algebra library with a mainline Buildroot package:

    @@ -32694,7 +32764,7 @@ cblas_dgemm( CblasColMajor, CblasNoTrans, CblasTrans,3,3,2 ,1, A,3, B,
    -

    22.8. Benchmarks

    +

    22.9. Benchmarks

    These are good targets for performance analysis with gem5.

    @@ -32712,7 +32782,7 @@ cblas_dgemm( CblasColMajor, CblasNoTrans, CblasTrans,3,3,2 ,1, A,3, B,
    -

    22.8.1. PARSEC benchmark

    +

    22.9.1. PARSEC benchmark

    We have ported parts of the PARSEC benchmark for cross compilation at: https://github.com/cirosantilli/parsec-benchmark See the documentation on that repo to find out which benchmarks have been ported. Some of the benchmarks were are segfaulting, they are documented in that repo.

    @@ -32730,7 +32800,7 @@ cblas_dgemm( CblasColMajor, CblasNoTrans, CblasTrans,3,3,2 ,1, A,3, B,
    -
    22.8.1.1. PARSEC benchmark without parsecmgmt
    +
    22.9.1.1. PARSEC benchmark without parsecmgmt
    ./build --arch arm --download-dependencies gem5-buildroot parsec-benchmark
    @@ -32764,7 +32834,7 @@ cblas_dgemm(      CblasColMajor, CblasNoTrans, CblasTrans,3,3,2  ,1,    A,3,  B,
     
    -
    22.8.1.2. PARSEC change the input size
    +
    22.9.1.2. PARSEC change the input size

    Running a benchmark of a size different than test, e.g. simsmall, requires a rebuild with:

    @@ -32828,7 +32898,7 @@ cblas_dgemm( CblasColMajor, CblasNoTrans, CblasTrans,3,3,2 ,1, A,3, B,
    -
    22.8.1.3. PARSEC benchmark with parsecmgmt
    +
    22.9.1.3. PARSEC benchmark with parsecmgmt

    Most users won’t want to use this method because:

    @@ -32891,7 +32961,7 @@ parsecmgmt -a run -p splash2x.fmm -i test
    -
    22.8.1.4. PARSEC uninstall
    +
    22.9.1.4. PARSEC uninstall

    If you want to remove PARSEC later, Buildroot doesn’t provide an automated package removal mechanism as mentioned at: Section 21.6, “Remove Buildroot packages”, but the following procedure should be satisfactory:

    @@ -32909,7 +32979,7 @@ parsecmgmt -a run -p splash2x.fmm -i test
    -
    22.8.1.5. PARSEC benchmark hacking
    +
    22.9.1.5. PARSEC benchmark hacking

    If you end up going inside submodules/parsec-benchmark to hack up the benchmark (you will!), these tips will be helpful.

    @@ -32961,7 +33031,7 @@ git clean -xdf .
    -
    22.8.1.6. Coremark
    +
    22.9.1.6. Coremark

    https://en.wikipedia.org/wiki/Coremark

    @@ -33174,7 +33244,7 @@ RUN_FLAGS =
    -

    22.8.2. Microbenchmarks

    +

    22.9.2. Microbenchmarks

    It eventually has to come to that, hasn’t it?

    @@ -33211,7 +33281,7 @@ RUN_FLAGS =
    -
    22.8.2.1. Dhrystone
    +
    22.9.2.1. Dhrystone

    https://en.wikipedia.org/wiki/Dhrystone

    @@ -33328,7 +33398,7 @@ Dhrystones per Second: 16152479.0
    -
    22.8.2.2. LMbench
    +
    22.9.2.2. LMbench

    http://www.bitmover.com/lmbench/

    @@ -33446,7 +33516,7 @@ make
    -
    22.8.2.3. STREAM benchmark
    +
    22.9.2.3. STREAM benchmark

    http://www.cs.virginia.edu/stream/ref.html

    @@ -33572,7 +33642,7 @@ Solution Validates: avg error less than 1.000000e-13 on all three arrays
    -

    22.9. userland/libs directory

    +

    22.10. userland/libs directory

    Tests under userland/libs require certain optional libraries to be installed on the target, and are not built or tested by default, you must enable them with either:

    @@ -33583,10 +33653,16 @@ Solution Validates: avg error less than 1.000000e-13 on all three arrays
    -

    See for example BLAS.

    +

    See for example BLAS. Since it is located under userland/libs/openblas, it will only build with either:

    +
    +
    +
    +
    ./build-userland --package openblas
    +./build-userland --package-all
    +
    -

    22.9.1. Boost

    +

    22.10.1. Boost

    https://en.wikipedia.org/wiki/Boost_(C%2B%2B_libraries)

    @@ -33602,7 +33678,7 @@ Solution Validates: avg error less than 1.000000e-13 on all three arrays
    -

    22.9.2. HDF5

    +

    22.10.2. HDF5

    https://en.wikipedia.org/wiki/Hierarchical_Data_Format

    @@ -33625,7 +33701,7 @@ Solution Validates: avg error less than 1.000000e-13 on all three arrays
    -

    22.10. Userland content filename conventions

    +

    22.11. Userland content filename conventions

    The following basenames should always refer to programs that do the same thing, but in different languages:

    @@ -33654,7 +33730,7 @@ Solution Validates: avg error less than 1.000000e-13 on all three arrays
    -

    22.11. Userland content bibliography

    +

    22.12. Userland content bibliography

    -
    30.2.1.2. gem5 x86_64 DerivO3CPU boot panics
    +
    30.2.1.2. gem5 x86_64 DerivO3CPU boot panics
    @@ -42253,7 +42329,7 @@ instructions 124346081

    First we build Dhrystone manually statically since dynamic linking is broken in gem5 as explained at: Section 10.7, “gem5 syscall emulation mode”.

    -

    TODO: move this section to our new custom dhrystone setup: Section 22.8.2.1, “Dhrystone”.

    +

    TODO: move this section to our new custom dhrystone setup: Section 22.9.2.1, “Dhrystone”.

    gem5 user mode:

    @@ -45206,7 +45282,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -
    -

    34.15.2. buildroot_packages directory

    +

    34.15.2. buildroot_packages directory

    Source: buildroot_packages/.

    @@ -45331,7 +45407,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -
    -

    34.15.4. rootfs_overlay

    +

    34.15.4. rootfs_overlay

    Source: rootfs_overlay.

    @@ -45378,7 +45454,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -

    This way you can just hack away the scripts and try them out immediately without any further operations.

    -
    34.15.4.1. out_rootfs_overlay_dir
    +
    34.15.4.1. out_rootfs_overlay_dir

    This path can be found with:

    @@ -45396,7 +45472,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -

    Userland content that needs to be compiled

  • -

    rootfs_overlay content that gets put inside the image as is

    +

    rootfs_overlay content that gets put inside the image as is

  • @@ -45407,7 +45483,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -

    In Buildroot, this is done by pointing BR2_ROOTFS_OVERLAY to that directory, which is documented at: https://buildroot.org/downloads/manual/manual.html#rootfs-custom

    -

    This does not include native image modification mechanisms such as Buildroot packages, which we let Buildroot itself manage.

    +

    This does not include native image modification mechanisms such as Buildroot packages, which we let Buildroot itself manage.

    @@ -45442,7 +45518,7 @@ git -C "$(./getvar buildroot_source_dir)" checkout -
    -

    34.15.6. lkmc_home

    +

    34.15.6. lkmc_home

    lkmc_home refers to the target base directory in which we put all our custom built stuff, such as userland executables and kernel modules.

    @@ -45538,7 +45614,7 @@ baremetal=True
    -

    34.15.8. rand_check.out

    +

    34.15.8. rand_check.out

    Print out several parameters that normally change randomly from boot to boot:

    @@ -45950,7 +46026,7 @@ echo $?

    When updating the Linux kernel, QEMU and gem5, things sometimes break.

    -

    However, for many types of crashes, it is trivial to bisect down to the offending commit, in particular because we can make QEMU and gem5 exit with status 1 on kernel panic as mentioned at: Section 15.7.1.3, “Exit emulator on panic”.

    +

    However, for many types of crashes, it is trivial to bisect down to the offending commit, in particular because we can make QEMU and gem5 exit with status 1 on kernel panic as mentioned at: Section 15.6.1.3, “Exit emulator on panic”.

    For example, when updating from QEMU v2.12.0 to v3.0.0-rc3, the Linux kernel boot started to panic for arm.