mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 11:41:35 +01:00
readme: double spaces!!!
This commit is contained in:
30
README.adoc
30
README.adoc
@@ -1,5 +1,5 @@
|
|||||||
= Linux Kernel Module Cheat
|
= Linux Kernel Module Cheat
|
||||||
:description: The perfect emulation setup to study and develop the <<linux-kernel>> v5.2.1, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>. "Tested" in an Ubuntu 18.04 host.
|
:description: The perfect emulation setup to study and develop the <<linux-kernel>> v5.2.1, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>. "Tested" in an Ubuntu 18.04 host.
|
||||||
:idprefix:
|
:idprefix:
|
||||||
:idseparator: -
|
:idseparator: -
|
||||||
:nofooter:
|
:nofooter:
|
||||||
@@ -1254,7 +1254,7 @@ For example, to run link:baremetal/arch/aarch64/dump_regs.c[] in QEMU do:
|
|||||||
|
|
||||||
And the terminal prints the values of certain system registers. This example prints registers that are only accessible from <<arm-exception-levels,EL1>> or higher, and thus could not be run in userland.
|
And the terminal prints the values of certain system registers. This example prints registers that are only accessible from <<arm-exception-levels,EL1>> or higher, and thus could not be run in userland.
|
||||||
|
|
||||||
In addition to the examples under link:baremetal/[], several of the <<userland-content,userland examples>> can also be run in baremetal! This is largely due to the <<about-the-baremetal-setup,awesomeness of Newlib>>.
|
In addition to the examples under link:baremetal/[], several of the <<userland-content,userland examples>> can also be run in baremetal! This is largely due to the <<about-the-baremetal-setup,awesomeness of Newlib>>.
|
||||||
|
|
||||||
The examples that work include most <<c,C examples>> that don't rely on complicated syscalls such as threads, and almost all the <<userland-assembly>> examples.
|
The examples that work include most <<c,C examples>> that don't rely on complicated syscalls such as threads, and almost all the <<userland-assembly>> examples.
|
||||||
|
|
||||||
@@ -3765,7 +3765,7 @@ or:
|
|||||||
....
|
....
|
||||||
./run \
|
./run \
|
||||||
--arch aarch64 \
|
--arch aarch64 \
|
||||||
--userland "$(./getvar --arch aarch64 buildroot_target_dir)/bin/sh" \
|
--userland "$(./getvar --arch aarch64 buildroot_target_dir)/bin/sh" \
|
||||||
--userland-args='-c "uname -a && pwd"' \
|
--userland-args='-c "uname -a && pwd"' \
|
||||||
;
|
;
|
||||||
....
|
....
|
||||||
@@ -4041,7 +4041,7 @@ Since gem5 has to implement syscalls itself in syscall emulation mode, it can of
|
|||||||
./run \
|
./run \
|
||||||
--emulator gem5 \
|
--emulator gem5 \
|
||||||
--static userland/arch/x86_64/freestanding/linux/hello.S \
|
--static userland/arch/x86_64/freestanding/linux/hello.S \
|
||||||
--userland \
|
--userland \
|
||||||
--trace-stdout \
|
--trace-stdout \
|
||||||
--trace ExecAll,SyscallBase,SyscallVerbose \
|
--trace ExecAll,SyscallBase,SyscallVerbose \
|
||||||
;
|
;
|
||||||
@@ -5996,7 +5996,7 @@ depends: dep
|
|||||||
We can double check with:
|
We can double check with:
|
||||||
|
|
||||||
....
|
....
|
||||||
strings 3 dep2.ko | grep -E 'depends'
|
strings 3 dep2.ko | grep -E 'depends'
|
||||||
....
|
....
|
||||||
|
|
||||||
The output contains:
|
The output contains:
|
||||||
@@ -6729,7 +6729,7 @@ Where the data comes from and how to modify it:
|
|||||||
In this repo, leaking host information, and to make builds more reproducible, we are setting:
|
In this repo, leaking host information, and to make builds more reproducible, we are setting:
|
||||||
|
|
||||||
- user and date to dummy values with `KBUILD_BUILD_USER` and `KBUILD_BUILD_TIMESTAMP`
|
- user and date to dummy values with `KBUILD_BUILD_USER` and `KBUILD_BUILD_TIMESTAMP`
|
||||||
- hostname to the kernel git commit with `KBUILD_BUILD_HOST` and `KBUILD_BUILD_VERSION`
|
- hostname to the kernel git commit with `KBUILD_BUILD_HOST` and `KBUILD_BUILD_VERSION`
|
||||||
|
|
||||||
A sample result is:
|
A sample result is:
|
||||||
|
|
||||||
@@ -9641,7 +9641,7 @@ Buildroot's Linux tools package provides some GPIO CLI tools: `lsgpio`, `gpio-ev
|
|||||||
|
|
||||||
==== LEDs
|
==== LEDs
|
||||||
|
|
||||||
TODO: broken when `arm` moved to `-M virt`, same as <<gpio>>.
|
TODO: broken when `arm` moved to `-M virt`, same as <<gpio>>.
|
||||||
|
|
||||||
Hack QEMU's `hw/misc/arm_sysctl.c` with a printf:
|
Hack QEMU's `hw/misc/arm_sysctl.c` with a printf:
|
||||||
|
|
||||||
@@ -10714,7 +10714,7 @@ ps Haux | grep qemu | wc
|
|||||||
|
|
||||||
Remember <<qemu-user-mode-does-not-show-stdout-immediately>> though.
|
Remember <<qemu-user-mode-does-not-show-stdout-immediately>> though.
|
||||||
|
|
||||||
At 369a47fc6e5c2f4a7f911c1c058b6088f8824463 + 1 QEMU appears to spawn 3 host threads plus one for every new guest thread created. Remember that link:userland/posix/pthread_count.c[] spawns N + 1 total threads if you count the `main` thread.
|
At 369a47fc6e5c2f4a7f911c1c058b6088f8824463 + 1 QEMU appears to spawn 3 host threads plus one for every new guest thread created. Remember that link:userland/posix/pthread_count.c[] spawns N + 1 total threads if you count the `main` thread.
|
||||||
|
|
||||||
====== gem5 syscall emulation multithreading
|
====== gem5 syscall emulation multithreading
|
||||||
|
|
||||||
@@ -11122,7 +11122,7 @@ gnuplot \
|
|||||||
xdg-open bst_vs_heap_vs_hashmap.tmp.png
|
xdg-open bst_vs_heap_vs_hashmap.tmp.png
|
||||||
....
|
....
|
||||||
|
|
||||||
The parameters `heap_zoom_max` and `hashmap_zoom_max` are chosen manually interactively to best showcase the regions of interest in those plots.
|
The parameters `heap_zoom_max` and `hashmap_zoom_max` are chosen manually interactively to best showcase the regions of interest in those plots.
|
||||||
|
|
||||||
To benchmark on gem5, we first build the benchmark with <<m5ops-instructions>> enabled, and then we run it and extract the stats:
|
To benchmark on gem5, we first build the benchmark with <<m5ops-instructions>> enabled, and then we run it and extract the stats:
|
||||||
|
|
||||||
@@ -12219,7 +12219,7 @@ The `--gem5-script biglittle` option enables the alternative `configs/example/ar
|
|||||||
|
|
||||||
Advantages over `fs.py`:
|
Advantages over `fs.py`:
|
||||||
|
|
||||||
* more representative of mobile ARM SoCs, which almost always have big little cluster
|
* more representative of mobile ARM SoCs, which almost always have big little cluster
|
||||||
* simpler than `fs.py`, and therefore easier to understand and modify
|
* simpler than `fs.py`, and therefore easier to understand and modify
|
||||||
|
|
||||||
Disadvantages over `fs.py`:
|
Disadvantages over `fs.py`:
|
||||||
@@ -15537,7 +15537,7 @@ It competes with <<x86-userland-assembly>> because its implementations are desig
|
|||||||
|
|
||||||
ARM is generally considered a RISC instruction set, although there are some more complex instructions which would not generally be classified as purely RISC.
|
ARM is generally considered a RISC instruction set, although there are some more complex instructions which would not generally be classified as purely RISC.
|
||||||
|
|
||||||
ARM is developed by the British funded company ARM Holdings: https://en.wikipedia.org/wiki/Arm_Holdings which originated as a joint venture between Acorn Computers, Apple and VLSI Technology in 1990.
|
ARM is developed by the British funded company ARM Holdings: https://en.wikipedia.org/wiki/Arm_Holdings which originated as a joint venture between Acorn Computers, Apple and VLSI Technology in 1990.
|
||||||
|
|
||||||
ARM Holdings was bought by the Japanese giant SoftBank in 2016.
|
ARM Holdings was bought by the Japanese giant SoftBank in 2016.
|
||||||
|
|
||||||
@@ -17335,8 +17335,6 @@ IN: main
|
|||||||
|
|
||||||
which does an `eret` and jumps back to 0x4000209c, which is 4 bytes and therefore one instruction after where SVC was taken at 0x40002098.
|
which does an `eret` and jumps back to 0x4000209c, which is 4 bytes and therefore one instruction after where SVC was taken at 0x40002098.
|
||||||
|
|
||||||
In QEMU, and then we just continue running from the exception handler address.
|
|
||||||
|
|
||||||
On the terminal output, we observe the initial values of:
|
On the terminal output, we observe the initial values of:
|
||||||
|
|
||||||
* DAIF: 0x3c0, i.e. 4 bits (6 to 9) set to 1, which means that exceptions are masked for each exception type: Synchronous, System error, IRQ and FIQ.
|
* DAIF: 0x3c0, i.e. 4 bits (6 to 9) set to 1, which means that exceptions are masked for each exception type: Synchronous, System error, IRQ and FIQ.
|
||||||
@@ -17607,7 +17605,7 @@ TODO: create and study a minimal examples in gem5 where the DMB instruction lead
|
|||||||
|
|
||||||
==== ARM timer
|
==== ARM timer
|
||||||
|
|
||||||
The ARM timer is the simplest way to generate hardware interrupts periodically, and therefore serves as the simples example of <<arm-gic>> usage.
|
The ARM timer is the simplest way to generate hardware interrupts periodically, and therefore serves as the simples example of <<arm-gic>> usage.
|
||||||
|
|
||||||
Working on QEMU: link:baremetal/arch/aarch64/timer.c[]
|
Working on QEMU: link:baremetal/arch/aarch64/timer.c[]
|
||||||
|
|
||||||
@@ -19448,7 +19446,7 @@ git clone https://my.private.repo.com/my-fork/gem5.git gem5-internal
|
|||||||
gem5_internal="$(pwd)/gem5-internal"
|
gem5_internal="$(pwd)/gem5-internal"
|
||||||
....
|
....
|
||||||
|
|
||||||
Next, when you want to build with the private repository, use the `--gem5-build-dir` and `--gem5-source-dir` argument to override our default gem5 source and build locations:
|
Next, when you want to build with the private repository, use the `--gem5-build-dir` and `--gem5-source-dir` argument to override our default gem5 source and build locations:
|
||||||
|
|
||||||
....
|
....
|
||||||
cd linux-kernel-module-cheat
|
cd linux-kernel-module-cheat
|
||||||
@@ -20094,7 +20092,7 @@ Go through all the other <<getting-started>> sections in order.
|
|||||||
Once everything looks fine, publish the release with:
|
Once everything looks fine, publish the release with:
|
||||||
|
|
||||||
....
|
....
|
||||||
git tag -a v3.0
|
git tag -a v3.0
|
||||||
# Describe the release int the tag message.
|
# Describe the release int the tag message.
|
||||||
git push --follow-tags
|
git push --follow-tags
|
||||||
./release-zip --all-archs
|
./release-zip --all-archs
|
||||||
|
|||||||
Reference in New Issue
Block a user