mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-26 19:46:27 -08:00
kernel/linux/{scripts,src}: add a KASAN/lockdep debug kernel, and rename slab caches
gokrazy-debug-kernel.sh builds the gokrazy kernel package's kernel again with KASAN, lockdep, DEBUG_VM and DEBUG_NET, for tailscale.com's lean harness to boot (TSWG_DEBUG_KERNEL=1). build-for-gokrazy.sh builds against it when given TSWG_KDIR, since those options change kernel data structures. Its first find: our slab caches had upstream WireGuard's names (via KMEM_CACHE), which clash with wireguard.ko or a built-in WireGuard, as gokrazy has, and make slab_common warn at load. Give them tswg_ names. Updates #426 Signed-off-by: Brad Fitzpatrick <[email protected]> Change-Id: I2e7d5448bcf8b2fb68810486f7e5d4bf2af4558d
This commit is contained in:
1 parent
2c3ba4df08
commit
9dc696cc4d
5 files changed
+85
-4
No files matched your search
@@ -5,6 +5,9 @@
|
||||
# gokrazy-kdir.sh) in a private copy of src/ under OUTDIR, and prints the
|
||||
# path of the resulting tswg.ko to stdout. All build output goes to stderr.
|
||||
#
|
||||
# If TSWG_KDIR is set, it builds against that kernel build directory
|
||||
# instead (such as one from gokrazy-debug-kernel.sh).
|
||||
#
|
||||
# usage: build-for-gokrazy.sh GOKRAZY_KERNEL_PACKAGE_DIR OUTDIR
|
||||
|
||||
set -eu
|
||||
@@ -14,5 +17,5 @@ if [ $# -ne 2 ]; then
|
||||
exit 2
|
||||
fi
|
||||
scripts=$(dirname "$0")
|
||||
kdir=$("$scripts/gokrazy-kdir.sh" "$1")
|
||||
kdir=${TSWG_KDIR:-$("$scripts/gokrazy-kdir.sh" "$1")}
|
||||
exec "$scripts/build.sh" "$kdir" "$2"
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# gokrazy-debug-kernel.sh builds a debug variant of a gokrazy kernel package's
|
||||
# kernel (see gokrazy-kdir.sh): the same release, patches and config, plus
|
||||
# KASAN, lockdep, DEBUG_VM and DEBUG_NET, for catching memory and locking
|
||||
# bugs in tswg. It prints the build directory to stdout; the kernel is
|
||||
# arch/x86/boot/bzImage there, and tswg.ko must be built against that
|
||||
# directory (TSWG_KDIR=... build-for-gokrazy.sh), since the debug options
|
||||
# change kernel data structures.
|
||||
#
|
||||
# Results are cached in $TSLINUX_CACHE (default ~/.cache/tslinux).
|
||||
#
|
||||
# usage: gokrazy-debug-kernel.sh GOKRAZY_KERNEL_PACKAGE_DIR
|
||||
|
||||
set -eu
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "usage: $0 GOKRAZY_KERNEL_PACKAGE_DIR" >&2
|
||||
exit 2
|
||||
fi
|
||||
pkg=$1
|
||||
cache=${TSLINUX_CACHE:-$HOME/.cache/tslinux}
|
||||
|
||||
url=$(cat "$pkg/_build/upstream-url.txt")
|
||||
tarball=${url##*/}
|
||||
srcname=${tarball%.tar.*}
|
||||
|
||||
config=$(mktemp)
|
||||
trap 'rm -f "$config"' EXIT
|
||||
"$(dirname "$0")/extract-ikconfig" "$pkg/vmlinuz" > "$config"
|
||||
hash=$(sha256sum "$config" "$0" | sha256sum | cut -c1-12)
|
||||
|
||||
kdir=$cache/gokrazy/$srcname-$hash-debug
|
||||
if [ -f "$kdir/.tswg-built" ]; then
|
||||
echo "$kdir"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mkdir -p "$cache/tarballs"
|
||||
if [ ! -f "$cache/tarballs/$tarball" ]; then
|
||||
echo "downloading $url" >&2
|
||||
curl -sSfL -o "$cache/tarballs/$tarball.tmp" "$url"
|
||||
mv "$cache/tarballs/$tarball.tmp" "$cache/tarballs/$tarball"
|
||||
fi
|
||||
|
||||
rm -rf "$kdir"
|
||||
mkdir -p "$kdir"
|
||||
echo "unpacking $tarball" >&2
|
||||
tar -xf "$cache/tarballs/$tarball" -C "$kdir" --strip-components=1
|
||||
if [ -f "$pkg/_build/series" ]; then
|
||||
while read -r patch; do
|
||||
[ -n "$patch" ] || continue
|
||||
patch -s -d "$kdir" -p1 < "$pkg/_build/$patch"
|
||||
done < "$pkg/_build/series"
|
||||
fi
|
||||
cp "$config" "$kdir/.config"
|
||||
"$kdir/scripts/config" --file "$kdir/.config" \
|
||||
-e DEBUG_KERNEL \
|
||||
-e KASAN -e KASAN_GENERIC -e KASAN_INLINE \
|
||||
-e PROVE_LOCKING -e DEBUG_ATOMIC_SLEEP \
|
||||
-e DEBUG_VM -e DEBUG_NET \
|
||||
-d DEBUG_INFO_BTF -d RANDOMIZE_BASE
|
||||
echo "building debug $srcname" >&2
|
||||
make -s -C "$kdir" olddefconfig >&2
|
||||
make -s -C "$kdir" -j"$(nproc)" bzImage modules_prepare >&2
|
||||
touch "$kdir/.tswg-built"
|
||||
echo "$kdir"
|
||||
Reference in new issue
Block a user