From 6513e9943895ec8b9432768dc5e0422bc70b82a4 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Fri, 9 May 2025 16:27:29 +0100 Subject: [PATCH] fix .sh typo on kernel module test that accept the module as first argument --- README.adoc | 14 +++++++++++--- kernel_modules/memfile.c | 2 +- rootfs_overlay/lkmc/fops.sh | 2 +- rootfs_overlay/lkmc/memfile.sh | 4 ++-- rootfs_overlay/lkmc/scull.sh | 2 +- rootfs_overlay/lkmc/seq_file.sh | 2 +- rootfs_overlay/lkmc/seq_file_single_open.sh | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README.adoc b/README.adoc index a9f42c2..bf36f36 100644 --- a/README.adoc +++ b/README.adoc @@ -364,15 +364,15 @@ The safe way is to fist <>, rebuild t ./run --eval-after 'insmod hello.ko' .... -or for a slightly faster turnaround just leave it on 9p and use it from there: +where `./build-buildroot` is required after `./build-modules` because it re-generates the root filesystem with the modules that we compiled at `./build-modules`. + +Alternatively, for a slightly faster turnaround just leave it on 9p and use it from there: .... ./build-modules ./run --eval-after 'insmod /mnt/9p/out_rootfs_overlay/lkmc/hello.ko' .... -`./build-buildroot` is required after `./build-modules` because it re-generates the root filesystem with the modules that we compiled at `./build-modules`. - You can see that `./build` does that as well, by running: .... @@ -7733,6 +7733,14 @@ This example behaves the same as <>, except that the in-memory virtual fil * link:kernel_modules/memfile.c[] * link:rootfs_overlay/lkmc/memfile.sh[] +TODO: this example builds but oopses with out of memory on our currently default kernel v5.9.2 when doing the big allocation at: + +.... +dd if=/dev/zero of="$f" bs=1k count=1M +.... + +It works however on kernel 6.8.12, we're not sure why. We do have a potential krealloc vs kvrealloc on version check which is a very likely reason for the issue, but it has not been investigated. + [[seq-file]] ==== seq_file diff --git a/kernel_modules/memfile.c b/kernel_modules/memfile.c index d39c317..82f4382 100644 --- a/kernel_modules/memfile.c +++ b/kernel_modules/memfile.c @@ -1,4 +1,4 @@ -/* https://cirosantilli.com/linux-kernel-module-cheat#fops */ +/* https://cirosantilli.com/linux-kernel-module-cheat#memfile */ #include #include /* EFAULT */ diff --git a/rootfs_overlay/lkmc/fops.sh b/rootfs_overlay/lkmc/fops.sh index f53c194..155aec1 100755 --- a/rootfs_overlay/lkmc/fops.sh +++ b/rootfs_overlay/lkmc/fops.sh @@ -4,7 +4,7 @@ set -e # Setup f=/sys/kernel/debug/lkmc_fops mod="${1:-fops.ko}" -[ $# -gt 1] && shift +[ $# -gt 1 ] && shift insmod "$mod" "$@" # read diff --git a/rootfs_overlay/lkmc/memfile.sh b/rootfs_overlay/lkmc/memfile.sh index 3fed942..fdf63a1 100755 --- a/rootfs_overlay/lkmc/memfile.sh +++ b/rootfs_overlay/lkmc/memfile.sh @@ -1,5 +1,5 @@ #!/bin/sh -set -e +set -eux # Helpers odraw() ( @@ -9,7 +9,7 @@ odraw() ( # Setup f=/sys/kernel/debug/lkmc_memfile mod="${1:-memfile.ko}" -[ $# -gt 1] && shift +[ $# -gt 1 ] && shift insmod "$mod" "$@" # Starts off empty diff --git a/rootfs_overlay/lkmc/scull.sh b/rootfs_overlay/lkmc/scull.sh index 9cd1263..7b3f2da 100755 --- a/rootfs_overlay/lkmc/scull.sh +++ b/rootfs_overlay/lkmc/scull.sh @@ -4,7 +4,7 @@ set -eux name=scull mod="${1:-$name.ko}" -[ $# -gt 1] && shift +[ $# -gt 1 ] && shift insmod "$mod" "$@" major="$(awk "\$2==\"$name\" {print \$1}" /proc/devices)" diff --git a/rootfs_overlay/lkmc/seq_file.sh b/rootfs_overlay/lkmc/seq_file.sh index 259852c..8121b3d 100755 --- a/rootfs_overlay/lkmc/seq_file.sh +++ b/rootfs_overlay/lkmc/seq_file.sh @@ -2,7 +2,7 @@ set -e f=/sys/kernel/debug/lkmc_seq_file mod="${1:-seq_file.ko}" -[ $# -gt 1] && shift +[ $# -gt 1 ] && shift insmod "$mod" "$@" [ "$(cat "$f")" = "$(printf '0\n1\n2\n')" ] [ "$(cat "$f")" = "$(printf '0\n1\n2\n')" ] diff --git a/rootfs_overlay/lkmc/seq_file_single_open.sh b/rootfs_overlay/lkmc/seq_file_single_open.sh index ee8c552..c6eaeb8 100755 --- a/rootfs_overlay/lkmc/seq_file_single_open.sh +++ b/rootfs_overlay/lkmc/seq_file_single_open.sh @@ -2,7 +2,7 @@ set -e f=/sys/kernel/debug/lkmc_seq_file_single_open mod="${1:-seq_file_single_open.ko}" -[ $# -gt 1] && shift +[ $# -gt 1 ] && shift insmod "$mod" "$@" [ "$(cat "$f")" = "$(printf 'ab\ncd\n')" ] [ "$(dd if="$f" bs=1 count=3 skip=1)" = "$(printf "b\nc\n")" ]