Skip to content

Instantly share code, notes, and snippets.

@Swyter
Last active September 25, 2022 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swyter/8b67b96075de02b9111e834de0ce5f8a to your computer and use it in GitHub Desktop.
Save Swyter/8b67b96075de02b9111e834de0ce5f8a to your computer and use it in GitHub Desktop.
Bisect bugs in the Linux kernel -- Arch Linux
#!/bin/bash
# git bisect start
# git bisect good v5.19.8-arch1 # not working
# git bisect bad v5.19.9-arch1 # start working again
# git bisect run ../../_autobisecter.sh yourlocalhost.local
if [[ $1 == "" ]]; then
echo "[i] provide your host as the first argument"
exit 125
fi
remote_host=$1
bisect_line=`git bisect visualize --oneline|wc -l|perl -MPOSIX -lne 'print "Bisecting: ".floor(($_-1)/2)." revisions left to test after this (roughly ".(floor(log($_-1)/log(2))-1)." steps)" if $_'`
echo "[>] INIT: $bisect_line"
echo "[>] Building" && pushd ../../ && yes '' | makepkg -efs --noconfirm # swy: press enter to accept the default menu config, it will pick Y or M automatically
last_tar_file=`ls -c1 -t | grep linux.*\.tar | head -n1`
echo "[-] Built $last_tar_file. Copying and installing."
scp $last_tar_file $remote_host:~/linux-git
ssh $remote_host "sudo pacman -U linux-git/$last_tar_file --noconfirm"
echo "[-] Installed $last_tar_file; rebooting."
ssh $remote_host "sudo reboot"; sleep 1
until ssh $remote_host -o ConnectTimeout=1 "echo 1" > /dev/null && [[ $? == 0 ]]; do # 255 when it fails to connect, 0 when succeeding
sleep 1
done
popd
echo "[-] Rebooted; testing for card"
ssh $remote_host "pactl list cards" | grep 'Kaveri HDMI/DP Audio Controller'
status=$?; echo "[>] status: $status"
if [[ $status == 0 ]]; then
echo "[i] Kaveri HDMI/DP Audio is present"
ssh $remote_host "echo \"<body bgcolor=darkseagreen><h1 style=color:green;font-size:560%>Kaveri HDMI/DP Audio is present</h1><br><br>$last_tar_file<br>$bisect_line</body>\" > /tmp/pg.html"
ssh $remote_host "sh -c 'XAUTHORITY=/run/user/1000/gdm/Xauthority DISPLAY=:0 nohup chromium --kiosk /tmp/pg.html > /dev/null 2>&1 &'"
exit 1 # bad bisect revision - reversed
else
echo "[e] Kaveri HDMI/DP Audio missing"
ssh $remote_host "echo \"<body bgcolor=pink><h1 style=color:red;font-size:560%>Kaveri HDMI/DP Audio missing</h1><br><br>$last_tar_file<br>$bisect_line</body>\" > /tmp/pg.html"
ssh $remote_host "sh -c 'XAUTHORITY=/run/user/1000/gdm/Xauthority DISPLAY=:0 nohup chromium --kiosk /tmp/pg.html > /dev/null 2>&1 &'" # swy: https://stackoverflow.com/a/2831449/674685
exit 0 # good bisect revision - reversed
fi
# Note that the script (my_script in the above example) should exit with code 0 if the current source code is good/old,
# and exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad/new.
exit 125
yay -S modprobed-db
modprobed store
systemctl --user enable modprobed-db.service
makepkg # swy: let it download the git repo and prepare
pushd src/linux
make mrproper
zcat /proc/config.gz > .config
make LSMOD=$HOME/linux-git/modprobed.db localmodconfig
popd
makepkg -efsi --noconfirm # swy: or makepkg -efs to avoid installing it
git bisect start
# status: waiting for both good and bad commits
# good: [4b0986a3613c92f4ec1bdc7f60ec66fea135991f] Linux 5.18
git bisect good 4b0986a3613c92f4ec1bdc7f60ec66fea135991f
# status: waiting for bad commit, 1 good commit known
# bad: [3d7cb6b04c3f3115719235cc6866b10326de34cd] Linux 5.19
git bisect bad 3d7cb6b04c3f3115719235cc6866b10326de34cd
# good: [c011dd537ffe47462051930413fed07dbdc80313] Merge tag 'arm-soc-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
git bisect good c011dd537ffe47462051930413fed07dbdc80313
# skip: [5d4af9c1f04ab0411ba5818baad9a68e87f33099] Merge branch 'mv88e6xxx-fixes-for-reading-serdes-state'
git bisect skip 5d4af9c1f04ab0411ba5818baad9a68e87f33099
# good: [bf23729c7a5f44f0e863666b9364a64741fd3241] Merge tag 'amd-drm-next-5.19-2022-05-26-2' of https://gitlab.freedesktop.org/agd5f/linux into drm-next
git bisect good bf23729c7a5f44f0e863666b9364a64741fd3241
# skip: [0737e018a05e2aa352828c52bdeed3b02cff2930] net: dsa: lantiq_gswip: Fix refcount leak in gswip_gphy_fw_list
git bisect skip 0737e018a05e2aa352828c52bdeed3b02cff2930
# skip: [1e308c6fb7127371f48a0fb9770ea0b30a6b5698] ice: Fix max VLANs available for VF
git bisect skip 1e308c6fb7127371f48a0fb9770ea0b30a6b5698
# bad: [03c765b0e3b4cb5063276b086c76f7a612856a9a] Linux 5.19-rc4
git bisect bad 03c765b0e3b4cb5063276b086c76f7a612856a9a
# bad: [a111daf0c53ae91e71fd2bfe7497862d14132e3e] Linux 5.19-rc3
git bisect bad a111daf0c53ae91e71fd2bfe7497862d14132e3e
# Maintainer: Jonathan Wright <jon@than.io>
# Contributor: Boohbah <boohbah at gmail.com>
# Contributor: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
pkgbase=linux-git
pkgver=5.18.r12154.g5d4af9c1f04a
pkgrel=1
pkgdesc='Linux (Git)'
url="https://www.kernel.org"
arch=(x86_64)
license=(GPL2)
makedepends=(
bc kmod libelf git pahole
xmlto python-sphinx python-sphinx_rtd_theme graphviz imagemagick
)
options=('!strip')
_srcname=linux
source=(
'git+https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux'
config # the main kernel config file
)
sha256sums=('SKIP'
'a01c8ef3463c239f868fa679006bc591b1a088274dde8c9c162440dd0547ccad')
export KBUILD_BUILD_HOST=archlinux
export KBUILD_BUILD_USER=$pkgbase
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
pkgver() {
cd $_srcname
git describe --long | sed -E 's/^v//;s/([^-]*-g)/r\1/;s/-/./g;s/\.rc/rc/'
}
prepare() {
cd $_srcname
echo "Setting version..."
scripts/setlocalversion --save-scmversion
echo "-$pkgrel" > localversion.10-pkgrel
echo "${pkgbase#linux}" > localversion.20-pkgname
local src
for src in "${source[@]}"; do
src="${src%%::*}"
src="${src##*/}"
[[ $src = *.patch ]] || continue
echo "Applying patch $src..."
patch -Np1 < "../$src"
done
echo "Setting config..."
cp ../config .config
#make olddefconfig
# swy: added this here; make sure to install modprobe-db from the aur
# and run sudo systemctl --user enable modprobe-db
make LSMOD=$HOME/.config/modprobed.db localmodconfig
make -s kernelrelease > version
echo "Prepared $pkgbase version $(<version)"
}
build() {
cd $_srcname
make all
}
_package() {
pkgdesc="The $pkgdesc kernel and modules"
depends=(coreutils kmod initramfs)
optdepends=('crda: to set the correct wireless channels of your country'
'linux-firmware: firmware images needed for some devices')
provides=(WIREGUARD-MODULE)
replaces=(wireguard-arch)
cd $_srcname
# swy: duplicate the version file generation here to avoid rm failing at the end
make -s kernelrelease > version
echo "Prepared $pkgbase version $(<version)"
local kernver="$(<version)"
local modulesdir="$pkgdir/usr/lib/modules/$kernver"
echo "Installing boot image..."
# systemd expects to find the kernel here to allow hibernation
# https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"
# Used by mkinitcpio to name the kernel
echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"
echo "Installing modules..."
make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 modules_install
# remove build and source links
rm "$modulesdir"/{source,build}
}
pkgname=("$pkgbase")
for _p in "${pkgname[@]}"; do
eval "package_$_p() {
$(declare -f "_package${_p#$pkgbase}")
_package${_p#$pkgbase}
}"
done
# vim:set ts=8 sts=2 sw=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment